Ejemplo n.º 1
0
        public static void BuildParseCompareAudio(IAudioFormat audio, IAudioWriter writer, IAudioReader reader)
        {
            byte[]       builtFile   = writer.GetFile(audio);
            IAudioFormat parsedAudio = reader.ReadFormat(builtFile);

            Assert.Equal(audio, parsedAudio, new AudioFormatComparer());
        }
Ejemplo n.º 2
0
        public static IAudioFormat OpenFile(string path)
        {
            FileType     type   = AudioInfo.GetFileTypeFromName(path);
            IAudioReader reader = AudioInfo.Containers[type].GetReader();

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                return(reader.ReadFormat(stream));
            }
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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();
 }
Ejemplo n.º 5
0
        private void btnFile2_Click(object sender, EventArgs e)
        {
            if (ofdFile.ShowDialog(this) == DialogResult.OK)
            {
                tbFile2.Text = ofdFile.FileName;
                int    lenExt = 4;
                string ext    = ofdFile.FileName.Substring(ofdFile.FileName.Length - lenExt,
                                                           lenExt).ToLower();
                switch (ext)
                {
                case ".au":
                case ".snd":
                    ar = new AuReader(File.OpenRead(ofdFile.FileName));
                    break;

                case ".wav":
                    ar = new WaveReader(File.OpenRead(ofdFile.FileName));
                    break;

                case ".avi":
                    ar = new AviReader(File.OpenRead(ofdFile.FileName));
                    if (!((AviReader)ar).HasAudio)
                    {
                        MessageBox.Show("Avi stream has not audio track");
                        return;
                    }
                    break;

                case ".mp3":
                    ar = new Mp3Reader(File.OpenRead(ofdFile.FileName));
                    break;

                default:
                    ar = new DsReader(ofdFile.FileName);
                    if (!((DsReader)ar).HasAudio)
                    {
                        MessageBox.Show("DirectShow stream has not audio track");
                        return;
                    }
                    break;
                }
                oldFormat = ar.ReadFormat();
                FormatDetails fd = AudioCompressionManager.GetFormatDetails(oldFormat);
                lblFileFormat.Text = string.Format("{0} {1}", AudioCompressionManager.GetFormatTagDetails(fd.FormatTag).FormatTagName, fd.FormatName);
                GetFormatsConverted(oldFormat);
                gbConvert.Enabled  = true;
                btnMakeMp3.Enabled = false;
            }
        }
Ejemplo n.º 6
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;
                }
            }
        }
Ejemplo n.º 7
0
 private void btnFile2_Click(object sender, EventArgs e)
 {
     if (ofdFile.ShowDialog(this) == DialogResult.OK)
     {
         tbFile2.Text = ofdFile.FileName;
         int lenExt = 4;
         string ext = ofdFile.FileName.Substring(ofdFile.FileName.Length - lenExt,
             lenExt).ToLower();
         switch (ext)
         {
             case ".au":
             case ".snd":
                 ar = new AuReader(File.OpenRead(ofdFile.FileName));
                 break;
             case ".wav":
                 ar = new WaveReader(File.OpenRead(ofdFile.FileName));
                 break;
             case ".avi" :
                 ar = new AviReader(File.OpenRead(ofdFile.FileName));
                 if (!((AviReader)ar).HasAudio)
                 {
                     MessageBox.Show("Avi stream has not audio track");
                     return;
                 }
                 break;
             case ".mp3" :
                 ar = new Mp3Reader(File.OpenRead(ofdFile.FileName));
                 break;
             default:
                 ar = new DsReader(ofdFile.FileName);
                 if (!((DsReader)ar).HasAudio)
                 {
                     MessageBox.Show("DirectShow stream has not audio track");
                     return;
                 }
                 break;
         }
         oldFormat = ar.ReadFormat();
         FormatDetails fd = AudioCompressionManager.GetFormatDetails(oldFormat);
         lblFileFormat.Text = string.Format("{0} {1}", AudioCompressionManager.GetFormatTagDetails(fd.FormatTag).FormatTagName, fd.FormatName);
         GetFormatsConverted(oldFormat);
         gbConvert.Enabled = true;
         btnMakeMp3.Enabled = false;
     }
 }