Esempio n. 1
0
        private void Play()
        {
            IntPtr format = ar.ReadFormat();

            plex.OpenPlayer(format);
            byte[] data = ar.ReadData();
            plex.AddData(data);
            wfv.Assign(format, data);
            plex.StartPlay();
            state = DeviceState.InProgress;
        }
Esempio n. 2
0
 public void Play(IAudioReader wr, AudioEffect af)
 {
     //string fileName = @"c:\Wint\audio\NAudio-1-3\Source Code\MixDiff\bin\Debug\Windows XP Startup.wav";//1,16,8000.wav//G:\10\mp3\2,16,44100.wav
     //WaveReader wr = new WaveReader(File.OpenRead(fileName));
     IntPtr format = wr.ReadFormat();
     WaveFormat wf1 = AudioCompressionManager.GetWaveFormat(format);
     Console.WriteLine("{0},{1},{2}-{3}", wf1.nChannels, wf1.wBitsPerSample, wf1.nSamplesPerSec, wf1.wFormatTag);
     byte[] data = wr.ReadData();
     if (wf1.wFormatTag != 1)
     {
         IntPtr formatNew = IntPtr.Zero;
         byte[] dataNew = null;
         AudioCompressionManager.ToPcm(format, data, ref formatNew, ref dataNew);
         format = formatNew;
         data = dataNew;
         WaveFormat wf2 = AudioCompressionManager.GetWaveFormat(format);
         Console.WriteLine("{0},{1},{2}-{3}", wf2.nChannels, wf2.wBitsPerSample, wf2.nSamplesPerSec, wf2.wFormatTag);
     }
     else if (wf1.wBitsPerSample != 16)
     {
         WaveFormat wf = AudioCompressionManager.GetWaveFormat(format);
         IntPtr formatNew = AudioCompressionManager.GetPcmFormat(wf.nChannels, 16, wf.nSamplesPerSec);
         byte[] dataNew = AudioCompressionManager.Convert(format, formatNew, data, false);
         format = formatNew;
         data = dataNew;
         WaveFormat wf2 = AudioCompressionManager.GetWaveFormat(format);
         Console.WriteLine("{0},{1},{2}-{3}", wf2.nChannels, wf2.wBitsPerSample, wf2.nSamplesPerSec, wf2.wFormatTag);
     }
     //wr.Close();
     if (af != null)
     {
         bool hasProcessInPlace = af.HasProcessInPlace;
         //af.GetSupportedOutputFormats();
         GCHandle src = GCHandle.Alloc(data, GCHandleType.Pinned);
         IntPtr formatPtr = src.AddrOfPinnedObject();
         bool res = af.ProcessInPlace(format, data);
         src.Free();
         if (!res)
         {
             MessageBox.Show("Unable to convert the audio data");
             return;
         }
     }
     if (plex.State != DeviceState.Closed)
     {
         plex.ClosePlayer();
     }
     Console.WriteLine(plex.State);
     plex.OpenPlayer(format);
     plex.AddData(data);
     plex.StartPlay();
 }
Esempio n. 3
0
        public void Prepare(IAudioReader wr, AudioEffect af, ref IntPtr format, ref byte[] data)
        {
            format = wr.ReadFormat();
            WaveFormat wf1 = AudioCompressionManager.GetWaveFormat(format);

            Console.WriteLine("{0},{1},{2}-{3}", wf1.nChannels, wf1.wBitsPerSample, wf1.nSamplesPerSec, wf1.wFormatTag);
            data = wr.ReadData();
            if (wf1.wFormatTag != 1)
            {
                IntPtr formatNew = IntPtr.Zero;
                byte[] dataNew   = null;
                AudioCompressionManager.ToPcm(format, data, ref formatNew, ref dataNew);
                format = formatNew;
                data   = dataNew;
                WaveFormat wf2 = AudioCompressionManager.GetWaveFormat(format);
                Console.WriteLine("{0},{1},{2}-{3}", wf2.nChannels, wf2.wBitsPerSample, wf2.nSamplesPerSec, wf2.wFormatTag);
            }
            else if (wf1.wBitsPerSample != 16)
            {
                WaveFormat wf        = AudioCompressionManager.GetWaveFormat(format);
                IntPtr     formatNew = AudioCompressionManager.GetPcmFormat(wf.nChannels, 16, wf.nSamplesPerSec);
                byte[]     dataNew   = AudioCompressionManager.Convert(format, formatNew, data, false);
                format = formatNew;
                data   = dataNew;
                WaveFormat wf2 = AudioCompressionManager.GetWaveFormat(format);
                Console.WriteLine("{0},{1},{2}-{3}", wf2.nChannels, wf2.wBitsPerSample, wf2.nSamplesPerSec, wf2.wFormatTag);
            }
            //wr.Close();
            if (af != null)
            {
                bool hasProcessInPlace = af.HasProcessInPlace;
                //af.GetSupportedOutputFormats();
                GCHandle src       = GCHandle.Alloc(data, GCHandleType.Pinned);
                IntPtr   formatPtr = src.AddrOfPinnedObject();
                bool     res       = af.ProcessInPlace(format, data);
                src.Free();
                if (!res)
                {
                    MessageBox.Show("Unable to convert the audio data");
                    return;
                }
            }
        }