New! Alvas.Audio.Core

   Alvas.Audio

Stand with Ukraine!
Alvas.Net - .Net developers toolbox
  Overview    News    Articles    How to..    Samples    Videos    Order    Free Trial    Demo       PR    PAD  

Samples from Alvas.Audio.chm

1. This example shows how simple use WaveWriter.

2. This example shows how simple use WaveReader.

3. This example shows simple using of MakeMP3 method.

4. This example shows simple using of ReadInfoTag method.

5. This example shows simple using of Raw2Vox method.

6. This example shows simple using of Vox2Wav method.

7. This example shows simple using of Vox2Mp3 method.

8. This example shows simple using of Vox2Mp3 method.

9. This example shows simple using of Vox2Mp3 method.

10. This example shows simple using of CdReader class.

11. This example shows simple using of RawReader.

12. This example shows simple using of RecorderEx class.

13. This example shows simple using of GetRecorderName method.

14. This example shows simple using of DsReader class.

15. This example shows simple using of AviReader.

16. This example shows how translates an audio file in GSM 06.10 (full-rate) lossy speech compression to a WavPack lossless, lossy, and hybrid audio compression file

17. This example shows how translates an audio file in Creative Technology Sound Blaster format to a GSM 06.10 (full-rate) lossy speech compression file

18. This example shows how translates an audio file in Creative Technology Sound Blaster format to a Xiph.org's ogg-vorbis lossy compression file

19. This example shows how translates an audio file in Sun AU format to a Xiph.org's ogg-vorbis lossy compression file

20. This example shows how translates an audio file in Sun AU format to a Microsoft WAV file

21. This example shows simple using of WriteInfoTag method.

22. This example shows simple using of Mp3Reader.

23. This example shows simple using of MakeWave method.

24. This example shows simple using of ReadID3v1Tag method.

25. This example shows simple using of WriteID3v1Tag method.

26. This example shows simple using of RecordPlayer class.

27. This example shows simple using of VolumeData property.

28. This example shows how simple use AiffReader.

29. This example shows simple using of Mixer class.

30. This example shows simple using of GetMixerName method.

31. This example shows how simple use AiffWriter.

32. This example shows how simple use Player.

33. This example shows simple using of Play method.

34. This example shows simple using of GenerateTone method.

35. This example shows simple using of CheckSilent method.

36. This example shows simple using of MergeStereo method.

37. This example shows simple using of ChooseCompatibleFormat method.

38. This example shows simple using of ChooseCompatibleFormat method.

39. This example shows simple using of ToPcm method.

40. This example shows simple using of GetCompatibleFormat method.

41. This example shows simple using of ConvertMultistep method.

42. This example shows simple using of Convert method.

43. This example shows simple using of Convert method.

44. This example shows simple using of ChangeSpeed method.

45. This example shows simple using of ChangeSpeed method.

46. This example shows simple using of ChangeSpeed method.

47. This example shows simple using of WaveToMono method.

48. This example shows simple using of WaveToMono method.

49. This example shows simple using of Mp3ToMono method.

50. This example shows simple using of Mp3ToMono method.

51. This example shows simple using of ChangeVolume method.

52. This example shows simple using of Copy method.

53. This example shows simple using of Copy method.

54. This example shows simple using of Remove method.

55. This example shows simple using of Remove method.

56. This example shows simple using of CreateFormat method.

57. This example shows simple using of FormatBytes method.

58. This example shows simple using of GetFormatTagList method.

59. This example shows simple using of GetFormatList method.

60. This example shows simple using of GetFormatList method for specified driver.

61. This example shows simple using of GetFormatList method.

62. This example shows simple using of GetFormatList method for specified driver.

63. This example shows simple using of GetDriverList method.

64. This example shows simple using of GetFormatDetails method.

65. This example shows simple using of GetFormatDetails method.

66. This example shows simple using of GetFormatTagDetails method.

67. This example shows simple using of GetCompatibleFormatList method.

68. This example shows simple using of GetCompatibleFormatList method.

69. This example shows simple using of Wave2Mp3 method.

70. This example shows simple using of Wave2Mp3 method.

71. This example shows simple using of Mp3ToWav method.

72. This example shows simple using of Wave2Mp3 method.

73. This example shows simple using of Fade method.

74. This example shows simple using of ToPcm16Bit method.

75. This example shows simple using of Silence method.

76. This example shows simple using of Reverse method.

77. This example shows simple using of Reverse method.

78. This example shows simple using of Reverse method.

79. This example shows simple using of SplitStereo method.

80. This example shows simple using of SplitStereo method.

81. This example shows simple using of SplitStereo method.

82. This example shows simple using of SoundLevelMeter class.

83. This example shows simple using of Mp3Writer class.

84. This example shows how simple use CafWriter.

85. This example shows how simple use CafReader.

86. This example shows simple using of PlayerEx class.

87. This example shows simple using of GetPlayerName method.

88. This example shows how mixed audio data plays.

89. This example shows how simple use Recorder.

90. This example shows simple using of RawWriter class.


1. This example shows how simple use WaveWriter.


            string fileName = "123.wav";
            RecorderEx recEx = new RecorderEx();
            Stream stream = new FileStream(fileName, FileMode.Create);
            WaveWriter wr = new WaveWriter(stream, recEx.FormatBytes());
             
Up

2. This example shows how simple use WaveReader.


            WaveReader wr = new WaveReader(File.OpenRead("123.wav"));
            IntPtr format = wr.ReadFormat();
            byte[] data = wr.ReadData();
            wr.Close();
             
Up

3. This example shows simple using of MakeMP3 method.


            private void WavToMp3()
            {
                string wavFile = "in.wav";
                string mp3File = "out.mp3";
                using (WaveReader wr = new WaveReader(File.OpenRead(wavFile)))
                {
                    IntPtr pcmFormat = wr.ReadFormat();
                    byte[] pcmData = wr.ReadData();
                    WaveFormat wf = AudioCompressionManager.GetWaveFormat(pcmFormat);
                    if (wf.wFormatTag != AudioCompressionManager.PcmFormatTag)//Decode if not PCM data
                    {
                        Decode2Pcm(ref pcmFormat, ref pcmData, ref wf);
                    }
                    IntPtr webFormat = AudioCompressionManager.GetCompatibleFormat(pcmFormat,
                    AudioCompressionManager.MpegLayer3FormatTag);
                    byte[] webData = AudioCompressionManager.Convert(pcmFormat, webFormat,
                    pcmData, false);
                    MemoryStream ms = new MemoryStream();
                    using (WaveWriter ww = new WaveWriter(ms,
                    AudioCompressionManager.FormatBytes(webFormat)))
                    {
                        ww.WriteData(webData);
                        using (WaveReader wr2 = new WaveReader(ms))
                        {
                            using (FileStream fs = File.OpenWrite(mp3File))
                            {
                                wr2.MakeMP3(fs);
                            }
                        }
                    }
                }
            }        
            
            private static void Decode2Pcm(ref IntPtr format, ref byte[] data, ref WaveFormat wf)
            {
                IntPtr formatPcm16Bit = IntPtr.Zero;
                byte[] dataPcm16Bit = null;
                AudioCompressionManager.ToPcm16Bit(format, data, ref formatPcm16Bit, ref dataPcm16Bit);
                wf = AudioCompressionManager.GetWaveFormat(formatPcm16Bit);
                format = formatPcm16Bit;
                data = dataPcm16Bit;
            }        
             
Up

4. This example shows simple using of ReadInfoTag method.


            WaveReader br = new WaveReader(File.OpenRead(fileName));
            var dir = br.ReadInfoTag();
            br.Close();
            if (dir.Count > 0)
            {
                foreach (string val in dir.Values)
                {
                    Console.WriteLine(val);
                }
            }
             
Up

5. This example shows simple using of Raw2Vox method.


            private static void Decode2Pcm(ref IntPtr format, ref byte[] data, ref WaveFormat wf)
            {
                IntPtr newFormat = AudioCompressionManager.GetCompatibleFormat(format, AudioCompressionManager.PcmFormatTag);
                byte[] buffer = AudioCompressionManager.Convert(format, newFormat, data, false);
                wf = AudioCompressionManager.GetWaveFormat(newFormat);
                format = newFormat;
                data = buffer;
            }
            
            public static void Raw2VoxTest()
            {
                string inFile = "in.wav";
                string outFile = "out.vox";
                WaveReader wr = new WaveReader(File.OpenRead(inFile));
                IntPtr format = wr.ReadFormat();
                byte[] data = wr.ReadData();
                wr.Close();
                WaveFormat wf = AudioCompressionManager.GetWaveFormat(format);
                if (wf.wFormatTag != AudioCompressionManager.PcmFormatTag)//Decode if not PCM data 
                {
                    Decode2Pcm(ref format, ref data, ref wf);
                }
                BinaryWriter bw = new BinaryWriter(File.OpenWrite(outFile));
                BinaryReader br = new BinaryReader(new MemoryStream(data));
                Vox.Raw2Vox(br, bw, wf.wBitsPerSample);
                br.Close();
                bw.Close();
            }
             
Up

6. This example shows simple using of Vox2Wav method.


            string voxFile = "in.vox";
            int samplesPerSec = 8000;
            string wavFile = "out.wav";
            BinaryReader br = new BinaryReader(File.OpenRead(voxFile));
            IntPtr format = AudioCompressionManager.GetPcmFormat(1, 16, samplesPerSec);
            WaveWriter ww = new WaveWriter(File.Create(wavFile), AudioCompressionManager.FormatBytes(format));
            Vox.Vox2Wav(br, ww);
            br.Close();
            ww.Close();
             
Up

7. This example shows simple using of Vox2Mp3 method.


            string voxFile = "in.vox";
            string mp3File = "out.mp3";
            int samplesPerSec = 8000;
            Vox.Vox2Mp3(voxFile, mp3File, samplesPerSec);
             
Up

8. This example shows simple using of Vox2Mp3 method.


            string voxFile = "in.vox";
            string mp3File = "out.mp3";
            int samplesPerSec = 8000;
            Vox.Vox2Mp3(File.OpenRead(voxFile), File.Create(mp3File), samplesPerSec);
             
Up

9. This example shows simple using of Vox2Mp3 method.


            string voxFile = "in.vox";
            string mp3File = "out.mp3";
            int samplesPerSec = 8000;
            BinaryReader br = new BinaryReader(File.OpenRead(voxFile));
            Mp3Writer mw = new Mp3Writer(File.Create(mp3File));
            Vox.Vox2Mp3(br, mw, samplesPerSec);
            mw.Close();
            br.Close();
             
Up

10. This example shows simple using of CdReader class.


            CdDrive cda = new CdDrive();
            CdReader cr = cda.GetReader(0);
            if (cr.HasAudio)
            {
                IntPtr format = cr.ReadFormat();
                byte[] data = cr.ReadData();
            }
            cr.Close();
             
Up

11. This example shows simple using of RawReader.


            WaveFormat wfAlaw = new WaveFormat();
            wfAlaw.wFormatTag = AudioCompressionManager.ALawFormatTag;
            wfAlaw.nChannels = 1;
            wfAlaw.nSamplesPerSec = 8000;
            FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(wfAlaw);
            RawReader rr = new RawReader(File.OpenRead("123.alaw"), 
                fdArr[0].FormatHandle);
            IntPtr format = rr.ReadFormat();
            byte[] data = rr.ReadData();
            rr.Close();
             
Up

12. This example shows simple using of RecorderEx class.


            public static void TestRecorderEx()
            {
                RecorderEx rex = new RecorderEx();
                rex.Open += new EventHandler(rex_Open);
                rex.Data += new RecorderEx.DataEventHandler(rex_Data);
                rex.Close += new EventHandler(rex_Close);
                rex.Format = AudioCompressionManager.GetPcmFormat(1, 16, 44100);
                rex.StartRecord();
            }
            
            static WaveWriter ww;
            static int i = 0;
            
            static void rex_Close(object sender, EventArgs e)
            {
                ww.Close();
                ww = null;
            }
            
            static void rex_Data(object sender, DataEventArgs e)
            {
                ww.WriteData(e.Data);
                i += 1;
                if (i == 10)
                {
                    ((RecorderEx)sender).StopRecord();
                }
            }
            
            static void rex_Open(object sender, EventArgs e)
            {
                if (ww == null)
                {
                    ww = new WaveWriter(File.Create("rec.wav"), AudioCompressionManager.FormatBytes(((RecorderEx)sender).Format));
                }
            }
             
Up

13. This example shows simple using of GetRecorderName method.


            for (int i = 0; i < RecorderEx.RecorderCount; i++)
            {
                Console.WriteLine(RecorderEx.GetRecorderName(i));
            }
             
Up

14. This example shows simple using of DsReader class.


            DsReader dr = new DsReader("in.wma");
            if (dr.HasAudio)
            {
                IntPtr format = dr.ReadFormat();
                byte[] data = dr.ReadData();
            }
            dr.Close();
             
Up

15. This example shows simple using of AviReader.


            AviReader ar = new AviReader(File.OpenRead("123.avi"));
            if (ar.HasAudio)
            {
                IntPtr format = ar.ReadFormat();
                byte[] data = ar.ReadData();
            }
            ar.Close();
             
Up

16. This example shows how translates an audio file in GSM 06.10 (full-rate) lossy speech compression to a WavPack lossless, lossy, and hybrid audio compression file


            try
            {
            using (BinaryWriter to = new BinaryWriter(File.Create("Output.wv")))
            {
                Sox.Convert("sox.exe", "input.gsm", SoxAudioFileType.Gsm, to, SoxAudioFileType.Wv);
            }
            }
            catch (SoxException e)
            {
                Console.WriteLine("{0}: {1}", e.Code, e.Message);
            }
             
Up

17. This example shows how translates an audio file in Creative Technology Sound Blaster format to a GSM 06.10 (full-rate) lossy speech compression file


            try
            {
            using (BinaryWriter to = new BinaryWriter(File.Create("Output.gsm")))
            {
                Sox.Convert("sox.exe", "input.voc", to, SoxAudioFileType.Gsm);
            }
            }
            catch (SoxException e)
            {
                Console.WriteLine("{0}: {1}", e.Code, e.Message);
            }
             
Up

18. This example shows how translates an audio file in Creative Technology Sound Blaster format to a Xiph.org's ogg-vorbis lossy compression file


            try
            {
                Sox.Convert("sox.exe", "input.voc", SoxAudioFileType.Voc, "output.ogg", SoxAudioFileType.Ogg);
            }
            catch (SoxException e)
            {
                Console.WriteLine("{0}: {1}", e.Code, e.Message);
            }
             
Up

19. This example shows how translates an audio file in Sun AU format to a Xiph.org's ogg-vorbis lossy compression file


            try
            {
                Sox.Convert("sox.exe", "input.au", "output.ogg", SoxAudioFileType.Ogg);
            }
            catch (SoxException e)
            {
                Console.WriteLine("{0}: {1}", e.Code, e.Message);
            }
             
Up

20. This example shows how translates an audio file in Sun AU format to a Microsoft WAV file


            try
            {
                Sox.Convert("sox.exe", "input.au", "output.wav");
            }
            catch (SoxException e)
            {
                Console.WriteLine("{0}: {1}", e.Code, e.Message);
            }
             
Up

21. This example shows simple using of WriteInfoTag method.


             //removes INFO tags from audio stream 
            WaveReadWriter wrw1 = new WaveReadWriter(File.Open("in1.wav", FileMode.Open, FileAccess.ReadWrite));
            wrw1.WriteInfoTag(null);
            wrw1.Close();
            
             //writes INFO tags into audio stream 
            WaveReadWriter wrw2 = new WaveReadWriter(File.Open("in2.wav", FileMode.Open, FileAccess.ReadWrite));
            var tag = new Dictionary();
            tag[WaveInfo.Comments] = "Comments...";
            wrw2.WriteInfoTag(tag);
            wrw2.Close();
             
Up

22. This example shows simple using of Mp3Reader.


            Mp3Reader mr = new Mp3Reader(File.OpenRead("123.mp3"));
            IntPtr format = mr.ReadFormat();
            byte[] data = mr.ReadData();
            mr.Close();
             
Up

23. This example shows simple using of MakeWave method.


            string mp3File = "in.mp3";
            using (Mp3Reader mr = new Mp3Reader(File.OpenRead(mp3File)))
            {
                string wavFile = "out.wav";
                using (FileStream fs = File.Create(wavFile))
                {
                    mr.MakeWave(fs);
                }
            }
             
Up

24. This example shows simple using of ReadID3v1Tag method.


            Mp3Reader br = new Mp3Reader(File.OpenRead(fileName));
            ID3v1 id3v1 = br.ReadID3v1Tag();
            br.Close();
            if (id3v1 != null)
            {
                Console.WriteLine(id3v1.Title);
            }
             
Up

25. This example shows simple using of WriteID3v1Tag method.


             //removes ID3v1 tags from audio stream 
            Mp3ReadWriter mrw1 = new Mp3ReadWriter(File.Open("in1.mp3", FileMode.Open, FileAccess.ReadWrite));
            mrw1.WriteID3v1Tag(null);
            mrw1.Close();
            
             //writes ID3v1 tags into audio stream 
            Mp3ReadWriter mrw2 = new Mp3ReadWriter(File.Open("in2.mp3", FileMode.Open, FileAccess.ReadWrite));
            ID3v1 tag = new ID3v1();
            tag.Comment = "Comment...";
            mrw2.WriteID3v1Tag(tag);
            mrw2.Close();
             
Up

26. This example shows simple using of RecordPlayer class.


            public static void TestRecordPlayer()
            {
                RecordPlayer rp = new RecordPlayer();
                rp.PropertyChanged += new PropertyChangedEventHandler(rp_PropertyChanged);
                rp.Open(new Mp3Reader(File.OpenRead("in.mp3")));
                rp.Play();
            }
            
            static void rp_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                switch (e.PropertyName)
                {
                    case RecordPlayer.StateProperty:
                        RecordPlayer rp = ((RecordPlayer)sender);
                        if (rp.State == DeviceState.Stopped)
                        {
                            rp.Close();
                        }
                        break;
                }
            }
             
Up

27. This example shows simple using of VolumeData property.


            private void Init()
            {
                slm = new SoundLevelMeter();
                slm.Dock = DockStyle.Fill;
                this.Controls.Add(slm);
                IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(2, 16, 44100);
                rp.VolumeDataLength = slm.ClientSize.Width;
                rp.PropertyChanged += new PropertyChangedEventHandler(rp_PropertyChanged);
                rp.Open(new WaveReadWriter(new MemoryStream(), AudioCompressionManager.FormatBytes(pcmFormat)));
                rp.Record();
            }
            
            SoundLevelMeter slm;
            RecordPlayer rp = new RecordPlayer();
            
            void rp_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == RecordPlayer.VolumeLevelProperty)
                {
                    slm.Data = rp.VolumeData;
                };
            }
             
Up

28. This example shows how simple use AiffReader.


            AiffReader ar = new AiffReader(File.OpenRead("123.aif"));
            IntPtr format = ar.ReadFormat();
            byte[] data = ar.ReadData();
            ar.Close();
             
Up

29. This example shows simple using of Mixer class.


            public static void TestMixer()
            {
                PlayerEx plex = new PlayerEx();
                int playerMixerNo = plex.GetMixerNo();
                bool isMute = GetPlayerMute(playerMixerNo);
                SetPlayerMute(playerMixerNo, !isMute);
            
                RecorderEx rex = new RecorderEx();
                SetRecorderVolumeMax(rex.GetMixerNo());
            }
            
            private static void SetRecorderVolumeMax(int recorderMixerNo)
            {
                Mixer mx = new Mixer();
                mx.MixerNo = recorderMixerNo;
                DestinationLine dl = mx.GetDestination(Mixer.Recording);
                if (dl != null)
                {
                    foreach (MixerControl mc in dl.Controls)
                    {
                        if (mc is MixerIntControl)
                        {
                            MixerIntControl mic = mc as MixerIntControl;
                            mic.Value = mic.Maximum;
                            break;
                        }
                        else if (mc is MixerListControl)
                        {
                            MixerListControl mlc = dl.Controls[0] as MixerListControl;
                            MixerLine ml = mlc.Lines[mlc.Value];
                            foreach (MixerControl ctrl in ml.Controls)
                            {
                                if (ctrl is MixerIntControl)
                                {
                                    MixerIntControl mic = ctrl as MixerIntControl;
                                    mic.Value = mic.Maximum;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            
            private static bool GetPlayerMute(int playerMixerNo)
            {
                Mixer mx = new Mixer();
                mx.MixerNo = playerMixerNo;
                DestinationLine dl = mx.GetDestination(Mixer.Playback);
                if (dl != null)
                {
                    foreach (MixerControl ctrl in dl.Controls)
                    {
                        if (ctrl is MixerMuteControl)
                        {
                            return ((MixerMuteControl)ctrl).Value != 0;
                        }
                    }
                }
                return false;
            }
            
            private static void SetPlayerMute(int playerMixerNo, bool value)
            {
                Mixer mx = new Mixer();
                mx.MixerNo = playerMixerNo;
                DestinationLine dl = mx.GetDestination(Mixer.Playback);
                if (dl != null)
                {
                    foreach (MixerControl ctrl in dl.Controls)
                    {
                        if (ctrl is MixerMuteControl)
                        {
                            ((MixerMuteControl)ctrl).Value = (value) ? 1 : 0;
                            break;
                        }
                    }
                }
            }
             
Up

30. This example shows simple using of GetMixerName method.


            for (int i = 0; i < Mixer.MixerCount; i++)
            {
               Console.WriteLine(Mixer.GetMixerName(i));
            }
            
Up

31. This example shows how simple use AiffWriter.


            string fileName = "123.aif";
            RecorderEx recEx = new RecorderEx();
            Stream stream = new FileStream(fileName, FileMode.Create);
            AiffWriter aw = new AiffWriter(stream, recEx.Format);
             
Up

32. This example shows how simple use Player.


            player.FileName = "123.mp3";
            player.Play();
             
Up

33. This example shows simple using of Play method.


            Player pl = new Player();
            byte[] arr = File.ReadAllBytes(@"in.wav");
            pl.Play(arr);
             
Up

34. This example shows simple using of GenerateTone method.


            IntPtr format = AudioCompressionManager.GetPcmFormat(1, 16, 44100);
            byte[] data = GenerateTone(format, ToneType.Sine, 200, 0.5f, 1000);
             
Up

35. This example shows simple using of CheckSilent method.


            private static void SkipSilent(string fileName, short silentLevel)
            {
                WaveReader wr = new WaveReader(File.OpenRead(fileName));
                IntPtr format = wr.ReadFormat();
                WaveWriter ww = new WaveWriter(File.Create(fileName + ".wav"), AudioCompressionManager.FormatBytes(format));
                int i = 0;
                while (true)
                {
                    byte[] data = wr.ReadData(i, 1);
                    if (data.Length == 0)
                    {
                        break;
                    }
                    if (!AudioCompressionManager.CheckSilent(format, data, silentLevel))
                    {
                        ww.WriteData(data);
                    }
                }
                ww.Close();
                wr.Close();
            }
             
Up

36. This example shows simple using of MergeStereo method.


            AudioCompressionManager.MergeStereo(@"Left.wav", @"Right.wav", @"res.wav");
            
Up

37. This example shows simple using of ChooseCompatibleFormat method.


            IntPtr formatOld = AudioCompressionManager.GetPcmFormat(1, 16, 44100);
            FormatChooseResult fcr = AudioCompressionManager.ChooseCompatibleFormat(IntPtr.Zero, formatOld);
            if (fcr.Result == 0)
            {
                Console.WriteLine("{0} {1}", fcr.FormatTagName, fcr.FormatName);
                IntPtr format = fcr.Format;
            }
             
Up

38. This example shows simple using of ChooseCompatibleFormat method.


            IntPtr formatOld = AudioCompressionManager.GetPcmFormat(1, 16, 44100);
            FormatChooseResult fcr = AudioCompressionManager.ChooseCompatibleFormat(IntPtr.Zero, formatOld, "Select Audio Format");
            if (fcr.Result == 0)
            {
                Console.WriteLine("{0} {1}", fcr.FormatTagName, fcr.FormatName);
                IntPtr format = fcr.Format;
            }
             
Up

39. This example shows simple using of ToPcm method.


            string fileName = @"in.wav";
            WaveReader wr = new WaveReader(File.OpenRead(fileName));
            IntPtr formatWav = wr.ReadFormat();
            byte[] data = wr.ReadData();
            wr.Close();
            IntPtr formatPcm = IntPtr.Zero;
            byte[] dataPcm = null;
            AudioCompressionManager.ToPcm(formatWav, data, ref formatPcm, ref dataPcm);
            WaveWriter ww = new WaveWriter(File.Create(fileName + ".wav"), AudioCompressionManager.FormatBytes(formatPcm));
            ww.WriteData(dataPcm);
            ww.Close();
             
Up

40. This example shows simple using of GetCompatibleFormat method.


            IntPtr formaGsm = AudioCompressionManager.GetCompatibleFormat(AudioCompressionManager.GetPcmFormat(1, 16, 16000),
                            AudioCompressionManager.Gsm610FormatTag);
            FormatDetails fd = AudioCompressionManager.GetFormatDetails(formaGsm, true);
            Console.WriteLine(fd.ToString());
             
Up

41. This example shows simple using of ConvertMultistep method.


            string fileName = @"in.mp3";
            using (Mp3Reader mr = new Mp3Reader(File.OpenRead(fileName)))
            {
                IntPtr oldFormat = mr.ReadFormat();
                WaveFormat wf = AudioCompressionManager.GetWaveFormat(oldFormat);
                wf.nChannels = 2;
                byte[] oldData = mr.ReadData();
                IntPtr newFormat = IntPtr.Zero;
                byte[] newData = null;
                if (AudioCompressionManager.ConvertMultistep(oldFormat, wf, oldData, false, ref newFormat, ref newData))
                {
                    using (Mp3Writer mw = new Mp3Writer(File.Create(fileName + ".mp3")))
                    {
                        mw.WriteData(newData);
                    }
                }
            }
             
Up

42. This example shows simple using of Convert method.


            Mp3Reader mr = new Mp3Reader(File.OpenRead("in.mp3"));
            IntPtr formatMp3 = mr.ReadFormat();
            IntPtr formatPcm = AudioCompressionManager.GetCompatibleFormat(formatMp3, 
                AudioCompressionManager.PcmFormatTag);
            WaveWriter ww = new WaveWriter(File.Create("out.wav"), 
                AudioCompressionManager.FormatBytes(formatPcm));
            AudioCompressionManager.Convert(mr, ww, false);
            mr.Close();
            ww.Close();
             
Up

43. This example shows simple using of Convert method.


            Mp3Reader mr = new Mp3Reader(File.OpenRead("in.mp3"));
            IntPtr formatMp3 = mr.ReadFormat();
            byte[] dataMp3 = mr.ReadData();
            mr.Close();
            IntPtr formatPcm = AudioCompressionManager.GetCompatibleFormat(formatMp3,
                AudioCompressionManager.PcmFormatTag);
            byte[] dataPcm = AudioCompressionManager.Convert(formatMp3, formatPcm, dataMp3, false);
            WaveWriter ww = new WaveWriter(File.Create("out.wav"),
                AudioCompressionManager.FormatBytes(formatPcm));
            ww.WriteData(dataPcm);
            ww.Close();
             
Up

44. This example shows simple using of ChangeSpeed method.


            string inFile = @"in.wav";
            string outFile = @"out.wav";
            int persent = 50;
            AudioCompressionManager.ChangeSpeed(inFile, outFile, persent);
             
Up

45. This example shows simple using of ChangeSpeed method.


            string inFile = @"in.wav";
            string outFile = @"out.wav";
            int persent = 50;
            AudioCompressionManager.ChangeSpeed(File.OpenRead(inFile), File.Create(outFile), persent);
             
Up

46. This example shows simple using of ChangeSpeed method.


            string inFile = @"in.mp3";
            string outFile = @"out.mp3";
            int persent = 50;
            Mp3Reader mr = new Mp3Reader(File.OpenRead(inFile));
            IntPtr format = mr.ReadFormat();
            byte[] data = mr.ReadData();
            mr.Close();
            byte[] outData = AudioCompressionManager.ChangeSpeed(format, data, persent);
            Mp3Writer mw = new Mp3Writer(File.Create(outFile));
            mw.WriteData(outData);
            mw.Close();
             
Up

47. This example shows simple using of WaveToMono method.


            string wav = @"d:\down\stereo.wav";
            byte[] dataPcmMono;
            IntPtr formatPcmMono = AudioCompressionManager.WaveToMono(wav, out dataPcmMono);
            using (WaveWriter ww = new WaveWriter(File.Create(wav + ".mono.wav"), 
                AudioCompressionManager.FormatBytes(formatPcmMono)))
            {
                ww.WriteData(dataPcmMono);
            }
             
Up

48. This example shows simple using of WaveToMono method.


            string wav = @"d:\down\stereo.wav";
            AudioCompressionManager.WaveToMono(wav, wav + ".mono.wav");
             
Up

49. This example shows simple using of Mp3ToMono method.


            string mp3 = @"d:\down\stereo.mp3";
            AudioCompressionManager.Mp3ToMono(mp3, mp3 + ".mono.mp3");
             
Up

50. This example shows simple using of Mp3ToMono method.


            string mp3 = @"d:\down\stereo.mp3";
            byte[] dataMp3Mono;
            IntPtr formatMp3Mono = AudioCompressionManager.Mp3ToMono(mp3, out dataMp3Mono);
            using (Mp3Writer mw = new Mp3Writer(File.Create(mp3 + ".mono.mp3")))
            {
                mw.WriteData(dataMp3Mono);
            }
             
Up

51. This example shows simple using of ChangeVolume method.


            string inFile = @"in.mp3";
            string outFile = @"out.mp3";
            int persent = 50;
            Mp3Reader mr = new Mp3Reader(File.OpenRead(inFile));
            IntPtr format = mr.ReadFormat();
            byte[] data = mr.ReadData();
            mr.Close();
            byte[] outData = AudioCompressionManager.ChangeVolume(format, data, persent);
            Mp3Writer mw = new Mp3Writer(File.Create(outFile));
            mw.WriteData(outData);
            mw.Close();
             
Up

52. This example shows simple using of Copy method.


            string inFile = "in.wav";
            string outFile = "out.wav";
            int skipSeconds = 1;
            int readSeconds = 2;
            AudioCompressionManager.Copy(inFile, outFile, skipSeconds, readSeconds);
             
Up

53. This example shows simple using of Copy method.


            string inFile = "in.wav";
            string outFile = "out.wav";
            int skipSeconds = 1;
            int readSeconds = 2;
            AudioCompressionManager.Copy(File.OpenRead(inFile), File.Create(outFile), skipSeconds, readSeconds);
             
Up

54. This example shows simple using of Remove method.


            string inFile = "in.wav"; 
            string outFile = "out.wav"; 
            int fromSeconds = 0;
            int duration = 1;
            AudioCompressionManager.Remove(File.OpenRead(inFile), File.Create(outFile), fromSeconds, duration);
             
Up

55. This example shows simple using of Remove method.


            string inFile = "in.wav"; 
            string outFile = "out.wav"; 
            int fromSeconds = 0;
            int duration = 1;
            AudioCompressionManager.Remove(inFile, outFile, fromSeconds, duration);
             
Up

56. This example shows simple using of CreateFormat method.


            IntPtr format = AudioCompressionManager.CreateFormat(AudioCompressionManager.FormatBytes(AudioCompressionManager.GetPcmFormat(2, 16, 8000)));
            FormatDetails fd = AudioCompressionManager.GetFormatDetails(format, true);
            Console.WriteLine(fd.ToString());
             
Up

57. This example shows simple using of FormatBytes method.


            WaveWriter ww = new WaveWriter(File.Create("out.wav"), 
                AudioCompressionManager.FormatBytes(AudioCompressionManager.GetPcmFormat(2, 16, 8000)));
            ww.Close();
             
Up

58. This example shows simple using of GetFormatTagList method.


            FormatTagDetails ftd = AudioCompressionManager.GetFormatTagDetails(AudioCompressionManager.PcmFormatTag);
            Console.WriteLine(ftd.FormatTagName);
             
Up

59. This example shows simple using of GetFormatList method.


            FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(AudioCompressionManager.ImaAdpcmFormatTag);
            foreach (FormatDetails fd in fdArr)
            {
                Console.WriteLine(fd.ToString());
            }
             
Up

60. This example shows simple using of GetFormatList method for specified driver.


            private void GetDriver()
            {
                foreach (DriverDetails dd in AudioCompressionManager.GetDriverList())
                {
                    if (dd.LongName.Contains("{insert text here}"))
                    {
                        int driverId = dd.Driver;
                        FormatDetails[] fd = AudioCompressionManager.GetFormatList(AudioCompressionManager.MpegLayer3FormatTag, driverId);
                        break;
                    }
                };
            }
             
Up

61. This example shows simple using of GetFormatList method.


            FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(AudioCompressionManager.AdpcmFormatTag, true);
            foreach (FormatDetails fd in fdArr)
            {
                Console.WriteLine(fd.ToString());
            }
             
Up

62. This example shows simple using of GetFormatList method for specified driver.


            private void GetDriver()
            {
                foreach (DriverDetails dd in AudioCompressionManager.GetDriverList())
                {
                    if (dd.LongName.Contains("{insert text here}"))
                    {
                        int driverId = dd.Driver;
                        FormatDetails[] fd = AudioCompressionManager.GetFormatList(AudioCompressionManager.MpegLayer3FormatTag, driverId, true);
                        break;
                    }
                };
            }
             
Up

63. This example shows simple using of GetDriverList method.


            DriverDetails[] driverList = AudioCompressionManager.GetDriverList();
            
            foreach (DriverDetails driverDetails in driverList)
            {
                Console.WriteLine("Driver: {0}, Version: {1}, LongName: {2}", driverDetails.Driver, driverDetails.DriverVersion, driverDetails.LongName);
            }
             
Up

64. This example shows simple using of GetFormatDetails method.


            IntPtr format = AudioCompressionManager.GetPcmFormat(2, 16, 24000);
            FormatDetails fd = AudioCompressionManager.GetFormatDetails(format);
            Console.WriteLine(fd.ToString());
             
Up

65. This example shows simple using of GetFormatDetails method.


            IntPtr format = AudioCompressionManager.GetPcmFormat(2, 16, 24000);
            FormatDetails fd = AudioCompressionManager.GetFormatDetails(format, true);
            Console.WriteLine(fd.ToString());
             
Up

66. This example shows simple using of GetFormatTagDetails method.


            FormatTagDetails ftd = AudioCompressionManager.GetFormatTagDetails(AudioCompressionManager.PcmFormatTag);
            Console.WriteLine(ftd.FormatTagName);
             
Up

67. This example shows simple using of GetCompatibleFormatList method.


            IntPtr formaGsm = AudioCompressionManager.GetCompatibleFormat(AudioCompressionManager.GetPcmFormat(1, 16, 16000),
                            AudioCompressionManager.Gsm610FormatTag);
            FormatDetails fd = AudioCompressionManager.GetFormatDetails(formaGsm);
            Console.WriteLine(fd.ToString());
             
Up

68. This example shows simple using of GetCompatibleFormatList method.


            IntPtr formaGsm = AudioCompressionManager.GetCompatibleFormat(AudioCompressionManager.GetPcmFormat(1, 16, 16000),
                            AudioCompressionManager.Gsm610FormatTag);
            FormatDetails fd = AudioCompressionManager.GetFormatDetails(formaGsm, true);
            Console.WriteLine(fd.ToString());
             
Up

69. This example shows simple using of Wave2Mp3 method.


            string inFile = "test2.wav";
            string outFile = @"test2.mp3";
            
            AudioCompressionManager.Wave2Mp3(inFile, outFile);
             
Up

70. This example shows simple using of Wave2Mp3 method.


            string inFile = "test2.wav";
            string outFile = @"test2.mp3";
            
            AudioCompressionManager.Wave2Mp3(File.OpenRead(inFile), File.Create(outFile));
             
Up

71. This example shows simple using of Mp3ToWav method.


            AudioCompressionManager.Mp3ToWav("in.mp3", "out.wav");
             
Up

72. This example shows simple using of Wave2Mp3 method.


            string inFile = "test2.wav";
            string outFile = @"test2.mp3";
            
            WaveReader wr = new WaveReader(File.OpenRead(inFile));
            IntPtr format = wr.ReadFormat();
            byte[] data = wr.ReadData();
            wr.Close();
            byte[] dataMp3 = AudioCompressionManager.Wave2Mp3(format, data);
            Mp3Writer mw = new Mp3Writer(File.Create(outFile));
            mw.WriteData(dataMp3);
            mw.Close();
             
Up

73. This example shows simple using of Fade method.


            WaveReader wr = new WaveReader(File.OpenRead("in.wav"));
            IntPtr format = wr.ReadFormat();
            byte[] data1 = wr.ReadData(0, 1);
            byte[] data2 = wr.ReadData(1, 1);
            byte[] data3 = wr.ReadData(2, 1);
            wr.Close();
            byte[] data11 = AudioCompressionManager.Fade(format, data1, true);
            byte[] data33 = AudioCompressionManager.Fade(format, data3, false);
            WaveWriter ww = new WaveWriter(File.Create("out.wav"), AudioCompressionManager.FormatBytes(format));
            ww.WriteData(data11);
            ww.WriteData(data2);
            ww.WriteData(data33);
            ww.Close();
             
Up

74. This example shows simple using of ToPcm16Bit method.


            string fileName = @"in.wav";
            WaveReader wr = new WaveReader(File.OpenRead(fileName));
            IntPtr formatWav = wr.ReadFormat();
            byte[] data = wr.ReadData();
            wr.Close();
            IntPtr formatPcm = IntPtr.Zero;
            byte[] dataPcm = null;
            AudioCompressionManager.ToPcm(formatWav, data, ref formatPcm, ref dataPcm);
            WaveWriter ww = new WaveWriter(File.Create(fileName + ".wav"), AudioCompressionManager.FormatBytes(formatPcm));
            ww.WriteData(dataPcm);
            ww.Close();
             
Up

75. This example shows simple using of Silence method.


            FormatDetails[] formatList = AudioCompressionManager.GetFormatList(AudioCompressionManager.Gsm610FormatTag);
            IntPtr format = formatList[formatList.Length - 1].FormatHandle;
            WaveWriter ww = new WaveWriter(File.Create("file.wav"), AudioCompressionManager.FormatBytes(format));
            byte[] data = AudioCompressionManager.Silence(format, 10000);
            ww.WriteData(data);
            ww.Close();
             
Up

76. This example shows simple using of Reverse method.


            string inFile = "test2.wav";
            string outFile = "ReverseTest3.wav";
            
            AudioCompressionManager.Reverse(inFile, outFile);
             
Up

77. This example shows simple using of Reverse method.


            string inFile = "test2.wav";
            string outFile = "ReverseTest3.wav";
            
            AudioCompressionManager.Reverse(File.OpenRead(inFile), File.Create(outFile));
             
Up

78. This example shows simple using of Reverse method.


            string inFile = "test2.wav";
            string outFile = "ReverseTest3.wav";
            
            WaveReader wr = new WaveReader(File.OpenRead(inFile));
            IntPtr format = wr.ReadFormat();
            byte[] data = wr.ReadData();
            wr.Close();
            WaveWriter ww = new WaveWriter(File.Create(outFile), AudioCompressionManager.FormatBytes(format));
            ww.WriteData(AudioCompressionManager.Reverse(format, data));
            ww.Close();
             
Up

79. This example shows simple using of SplitStereo method.


            string inFile = "stereo.wav";
            string leftFile = "left.wav";
            string rightFile = "right.wav";
            AudioCompressionManager.SplitStereo(inFile, leftFile, rightFile);
             
Up

80. This example shows simple using of SplitStereo method.


            string inFile = "stereo.wav";
            string leftFile = "left.wav";
            string rightFile = "right.wav";
            AudioCompressionManager.SplitStereo(File.OpenRead(inFile), 
                File.Create(leftFile), File.Create(rightFile));
             
Up

81. This example shows simple using of SplitStereo method.


            string inFile = "stereo.wav";
            string leftFile = "left.wav";
            string rightFile = "right.wav";
            WaveReader wr = new WaveReader(File.OpenRead(inFile));
            IntPtr formatStereo = wr.ReadFormat();
            byte[] dataStereo = wr.ReadData();
            wr.Close();
            IntPtr formatMono = IntPtr.Zero;
            byte[] leftData = null;
            byte[] rightData = null;
            AudioCompressionManager.SplitStereo(formatStereo, dataStereo, ref formatMono, ref leftData, ref rightData);
            byte[] headerMono = AudioCompressionManager.FormatBytes(formatMono);
            WaveWriter wwLeft = new WaveWriter(File.Create(leftFile), headerMono);
            wwLeft.WriteData(leftData);
            wwLeft.Close();
            WaveWriter wwRight = new WaveWriter(File.Create(rightFile), headerMono);
            wwRight.WriteData(rightData);
            wwRight.Close();
             
Up

82. This example shows simple using of SoundLevelMeter class.


            SoundLevelMeter vum = new SoundLevelMeter();
            WaveReader wr = new WaveReader(File.OpenRead("in.wav"));
            IntPtr format = wr.ReadFormat();
            byte[] data = wr.ReadData();
            wr.Close();
            short[] buffer = AudioCompressionManager.RecalculateData(format, data, vum.ClientRectangle.Width);
            vum.Data = buffer;
             
Up

83. This example shows simple using of Mp3Writer class.


            Mp3Writer mw = new Mp3Writer(File.Create("new.mp3"));
            mw.WriteData(dataMp3);
            mw.Close();
             
Up

84. This example shows how simple use CafWriter.


            string fileName = "123.caf";
            RecorderEx recEx = new RecorderEx();
            Stream stream = new FileStream(fileName, FileMode.Create);
            CafWriter cw = new CafWriter(stream, recEx.Format);
             
Up

85. This example shows how simple use CafReader.


            CafReader cr = new CafReader(File.OpenRead("123.caf"));
            IntPtr format = cr.ReadFormat();
            byte[] data = cr.ReadData();
            cr.Close();
             
Up

86. This example shows simple using of PlayerEx class.


            public static void TestPlayerEx()
            {
                PlayerEx plex = new PlayerEx();
                plex.Done += new PlayerEx.DoneEventHandler(plex_Done);
                Mp3Reader mr = new Mp3Reader(File.OpenRead("in.mp3"));
                IntPtr format = mr.ReadFormat();
                byte[] data = mr.ReadData();
                mr.Close();
                plex.OpenPlayer(format);
                plex.AddData(data);
                plex.StartPlay();
            }
            
            static void plex_Done(object sender, DoneEventArgs e)
            {
                if (e.IsEndPlaying)
                {
                    ((PlayerEx)sender).ClosePlayer();
                }
            }
             
Up

87. This example shows simple using of GetPlayerName method.


            for (int i = 0; i < PlayerEx.PlayerCount; i++)
            {
                Console.WriteLine(PlayerEx.GetPlayerName(i));
            }
             
Up

88. This example shows how mixed audio data plays.


            public void PlayMix()
            {
            		string dir = Path.GetDirectoryName(Application.ExecutablePath);
            		string path1 = dir + @"\1.wav";
            		WaveReader wr1 = new WaveReader(File.OpenRead(path1));
            		IntPtr format = wr1.ReadFormat();
            		WaveFormat wf = AudioCompressionManager.GetWaveFormat(format);
            		playEx.OpenPlayer(format);//validFormat
            		byte[] data1 = wr1.ReadData();
            		wr1.Close();
            		//----------
            		string path2 = dir + @"\2.wav";
            		WaveReader wr2 = new WaveReader(File.OpenRead(path2));
            		byte[] data2 = wr2.ReadData();
            		wr2.Close();
            		playEx.AddMixData(data1, data2);
            		playEx.StartPlay();
            }
             
Up

89. This example shows how simple use Recorder.


            rec.Open();
            Recorder.Channel rc = Recorder.Channel.Stereo;
            Recorder.BitsPerSample rbps = Recorder.BitsPerSample.Bps16;
            Recorder.SamplesPerSec rsps = Recorder.SamplesPerSec.Sps8000;
            rec.Configure(rc, rbps, rsps);
            rec.Record();
             
Up

90. This example shows simple using of RawWriter class.


            RawWriter rw = new RawWriter(File.Create("out.pcm"));
            rw.WriteData(new byte[16000]);
            rw.Close();
             
Up
Blog :: Contact Us :: Copyright © 1998-2023 Alvas.Net. All rights reserved