Beispiel #1
0
        static void Test()
        {
            SF2 sf2 = new SF2("g:\\test.sf2");

            List <short> samples = sf2.SoundChunk.SMPLSubChunk.samples;

            PCMProcesser pcmProcesser = new PCMProcesser();

            short[] newSamples = pcmProcesser.PitchPcmNote(samples.ToArray(), 24);

            // pitch.Seq(samples.ToArray());


            pcm_buffer = new byte[newSamples.Length * 2];
            int idx = 0;

            for (int i = 0; i < newSamples.Length; i++)
            {
                pcm_buffer[idx++] = (byte)(newSamples[i] & 0xff);
                pcm_buffer[idx++] = (byte)((newSamples[i] >> 8) & 0xff);
            }


            float newTime = pcmProcesser.GetPcmTime(newSamples, 44100);


            SDL_AudioSpec OutputAudioSpec = new SDL_AudioSpec();

            OutputAudioSpec.freq     = 44100;
            OutputAudioSpec.format   = AUDIO_S16;
            OutputAudioSpec.channels = 1;
            OutputAudioSpec.samples  = 1024;
            OutputAudioSpec.callback = SDL_AudioCallback;


            if (SDL_AudioInit(null) < 0)
            {
                return;
            }

            IntPtr n = IntPtr.Zero;

            if (SDL_OpenAudio(ref OutputAudioSpec, n) < 0)
            {
                return;
            }


            audio_len = pcm_buffer.Length; //长度为读出数据长度,在read_audio_data中做减法
            audio_pos = pcm_buffer;
            audio_idx = 0;

            SDL_PauseAudio(0);
            SDL_Delay((uint)(Math.Round(newTime) * 1000));
        }
Beispiel #2
0
        public ChartApp(ScMgr scMgr)
        {
            SF2          sf2     = new SF2("g:\\test.sf2");
            List <short> samples = sf2.SoundChunk.SMPLSubChunk.samples;

            pcmProcesser = new PCMProcesser();
            short[] newSamples = pcmProcesser.PitchPcmNote(samples.ToArray(), -24, true, 10);

            pcm_buffer = new byte[newSamples.Length * 2];
            int idx = 0;

            for (int i = 0; i < newSamples.Length; i++)
            {
                pcm_buffer[idx++] = (byte)(newSamples[i] & 0xff);
                pcm_buffer[idx++] = (byte)((newSamples[i] >> 8) & 0xff);
            }


            List <short> shortBufs = new List <short>();
            short        val;

            for (int i = 0; i < pcm_buffer.Length; i += 2)
            {
                val = (short)((pcm_buffer[i + 1] << 8) | pcm_buffer[i]);
                shortBufs.Add(val);
            }

            List <float> floatBufs = new List <float>();

            for (int i = 0; i < pcm_buffer.Length; i += 2)
            {
                val = (short)((pcm_buffer[i + 1] << 8) | pcm_buffer[i]);
                floatBufs.Add(val);
            }

            pcm = shortBufs.ToArray();
            float[] seqDatas = pcmProcesser.CreatePcmFreqNormAmpSpectrum(pcm, 44100);

            List <float> samplesFloat = new List <float>();

            for (int i = 0; i < shortBufs.Count; i++)
            {
                samplesFloat.Add(shortBufs[i]);
            }


            this.scMgr = scMgr;
            root       = scMgr.GetRootLayer();

            ScChart chart = new ScChart(scMgr);

            chart.GetAxisXSeq = GetAxisXSeq;
            chart.Datas       = samplesFloat.ToArray();
            // chart.DataLineColor = Color.Blue;
            //  chart.XAxisColor = Color.White;
            // chart.DataRange = new DrawDataRange(0, 5000);
            chart.xAxisSeqCount = 10;
            chart.Dock          = ScDockStyle.Fill;
            // chart.BackgroundColor = Color.Black;
            root.Add(chart);
        }