Take the latest version at http://alvas.net/alvas.audio,tips.aspx ::

Questions about Alvas.Audio [Download Alvas.Audio tips in PDF]

1. Is it possible to merge several audio (wave) files that I have on disk and produce a single audio wave file?
2. I want to read an existing wav file, change the format then write it back out.
3. If I buy Single License for Alvas.Audio, will there be no 'about window' deployed on the customers apllication whenever the application is started?
4. Does your .net component require any dependency files?
5. Is the runtime license free?
6. Do you provide some c# code with the classes?
7. I would like to know under what .Net language is the Audio application written?
8. Can you please confirm that if I buy a single user license for Alvas Suite, that it also includes Alvas.Audio?
9. Can we use Alvas.Audio for Pocket PC applications?
10. It appears to be necessary to select input and output devices. I would like to simply use the default devices that the user has selected on the control panel. Is this possible?
11. I need to be able to convert Dialogic files to MP3
12. Can you send me the complete list of all audio formats that can be converted FROM and converted TO using Alvas.Audio?
13. I want to decode a GSM-stream, but after a quick glance in the example-code and at Alvas.Audio.chm I can't really see how to do that.
14. I'm using the Alvas.Audio.dll, and i'm trying to play 2 wav's at the same time (I don't want the first one to stop when the second one begins). How can I make this happen?
15. Is this control suitable for use in MC++ Windows forms projects?
16. Would your audio compenent be suitable for Voip, would it decode and encode fast enough to keep latency at a minimum. Has it been used in this type of environment.
17. Can I use your audio toolkit to extract portions of a wav file to a new wav file?
18. Have you tested the audio on Vista?
19. Is it possible to insert new recordings into existing WAV files?
20. What does a single license entitle us to do, and how does it affect sales of software produced that include Alvas.Audio.
21. How do I stop (not pause) audio that's allready playing in command?
22. I would like to use your audio control for VoIP. Record to memory (Speex) and send the data by UDP the receive from UDP and playback raw data. Would your control be suitable for this purpose?
23. Using either the WaveReader or Player(Ex) classes, is there anyway for me to tell how long (in seconds) a WAV file is?
24. I'm looking for a way via a web page to convert a saved Wav file to MP3. Will your code allow me to do so?
25. I just need to get the duration in MS for a file. This code will be on an ASP.NET website, so I want to instance your class, assign a file name (NOT PLAY THE FILE) and then just get the duration. Is this possible with your Alvas.Audio classes - if so, which class does it?
26. I am developing an application in VB.net 2.0, and i am looking for a library to transform u-law audio files into mp3. Could I get some sample code to help me get this to work?
27. Is it possible to default to a particular format on any machine (e.g. 'MP3, 20kbps, 11,025Hz, mono') without the user having to specify it? I need to default to a low quality mp3 format for speech recording and I don't want the user to have to select anything. I want to make it as simple as possible for them. Is it reliable to just iterate through the FormatTags and select the right one based on matching a string? Or will different client machines have different values/indexes for these tags?
28. I need to be able to convert from ADPCM 6khz 4-bit mono, ADPCM 8khz 4-bit mono, PCM8 8khz 8-but uLaw mono formats and standard formats such as WAV.
29. Must I pay a license for every deploy on my customer or only one for developer?
30. Reading / Writing of our VOX Files is not possibile.
31. Can you convert WAV files to the headerless formats like Dialogic VOX and PCM 8khz?
32. It can play from an array of doubles?
33. I was evaluating your product to use in an application for Asterisk(VOIP) solution, but I found there is no output support for SLINEAR. Do you plan to support this format? This would be a great option since there is no Windows application to make the conversion for Asterisk.
34. How to convert a wave file into an raw alaw 8Khz mono file?
35. We need to be able to essentially convert a wav file while adjusting its speed by a factor.
36. Does the Alvas.Audio library work with Terminal Services?
37. How to send audio stream in the browser?
38. How to Play big audio files?
39. Simple RecorderEx example
40. Simple PlayerEx example
41. Can you tell me whether the player will support playing Dialogic .vox (adpcm) format?
42. I expected that the RecorderEx.Data event would be raised whenever a buffer (size determined by BufferSize) was filled, but it's only raised on the half-second. Is there any way to reduce this?
43. How do I Boost the volume of an existing WAVE file - How can I make it louder?
44. Do you have any examples or sample applications that record directly to mp3?
45. Can Alvas.NET perform mp3 playing in C# with selected sound card. I have multiple sound card on my PC.
46. I would like to know if it is possible to record both line-in and line-out from a soundcard (full duplex).
47. Does Alvas.Audio support 64bit operating systems?
48. How can I check frequency (sample rate) of MP3 file? The only way I could find is to use FormatDetails struct and parse frequency out of it's FormatName property. However, I'm sure there are nicer way to achieve this :)
49. I am a newbie trying to recode MP3 file to a different bit rate/sample rate/mode. Like changing the Bit rate, Sample rate or changing from stereo to mono or their combination. I would really appreciate any help, with code if possible.
50. Can you give an example to convert a mp3 file from 320kbps bit rate, stereo, 44khz sample rate to 48kbps bit rate, mono, 22khz.
51. Our company needs audio control, which can record separately and independently right and left channel from stereo input. Has Alvas.Audio got such functionality?
52. How can I get higher quality when converting from .vox to .mp3.
53. Could you be more specific about adding the control to the toolbox.
54. After the file has been played I want to delete it, but I get an “access denied” error, because the file is in use. Is there a way to release the file from the DSReader (or PlayerEx) so that I can delete it?
55. I'm looking for .net a component like yours that can convert .wma to .mp3 - can it easily to that.
56. Does Alvas.Audio work with Windows 7 RTM?
57. Is it possible to increase/amplify the volume of mp3 file using Alvas.Audio library?
58. Is it possible to work directly on free licence file formats like Ogg Vorbis?
59. Can I convert an MP3 file to .VOX format?
60. I have a byte array of PCM audio. I would like to convert that to a byte array of GSM audio (and back). Would your Alvas.Audio library be able to do that?
61. Is there a way to use a specific codec? For example, say I install the lame.acm as part of my application installation. Then the user decides to installs other codecs for some reason. Can I specifically ensure that I use my specific codec?
62. We're having some troubles with big audio files when we attempt to convert them from mp3 to wav: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
63. Can Alvas.Audio can detect silence detection?
64. I would like to be able to select the input device like Microphone or CD Audio when recording sound.
65. Does your audio control allow real time monitoring of the lenght of the recording? Basically while its recording, can I see position with the scroll bar?
66. Can your audio library playback Shoutcast or Icecast radio streams? I also need to extract metadata from stream.
67. First, can you jump to a specific spot in a wav file and start recording from there? Meaning could I record for say five seconds, then replay the sound, then jump to the middle of the recording and start recording again from there?
68. I'm listening to an internet radio station over my speakers, and I'd like to record what I hear, and directly to an mp3 file. Can your alvas.audio contol record 'what you hear'? If so, how?
69. I try to convert a file on my web page but the process get stuck. The web page seems like it tries to load something but won't go on. What can I do?
70. I'm trying to trial your software, building it into our web application but the trial version I have downloaded won't work in my web app as it keeps trying to pop up a 'nag screen' which causes the app to throw an error. Is there any way to turn this off?
71. We are evaluating your Alvas.Audio product for a .net server side mixer and aren't able to evaluate it completely since we keep getting this error: 'Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.' The error seems to come from the Alvas.Audio.AboutBox.ShowNagScreen, which I would guess has to do that we are running a demo. Is there any way of testing server side things without getting that error just to make sure that it works for our project?
72. When converting audio from Wav to Mp3 and NOT using the Wave2Mp3 function, do you always need to convert the wave data into PCM data before converting it to MP3? Is there a reason for doing that?
73. I have to connect to a SHOUTcast stream, take 5 seconds of the sound then detect if there is silence (no sound above -14db). Would you be so kind to provide us with some sample?
74. I have multiple audio tracks with nothing but music. I have multiple recorded voice tracks no longer than 2-3 seconds each. What I would like to do is 'overlay' a voice track onto an audio track at a specified time and output the results to a single file. E.g. Audio track is 2 minutes long, and I would like to insert the voice track at 23 seconds as well 1m 05 seconds and at 1m 40 seconds. Can Alvas.Audio accomplish this sort of task for me??
75. Effectively, I have a block of memory which contains A-law data and I want to play the data using vb.net. Can you provide some sample code on how I can achieve this with PlayerEx?
76. Can I use Alvas.Audio to play(stream) MP3 from the buffer of byte array. Please explain it with sample code in c#.

Answers

1. Is it possible to merge several audio (wave) files that I have on disk and produce a single audio wave file?

Yes, of course. If You want to join 2 files their formats should be identical. For Example You can join "CCITT u-Law 8 bit mono" with "CCITT u-Law 8 bit mono". Thus if You have "CCITT u-Law 16 bit mono" You have to convert it to "CCITT u-Law 8 bit mono" (use AudioCompressionManager.Convert method). Please see example below.

        private void Join()

        {

            string path = Application.StartupPath;

            WaveReader wr1 = new WaveReader(File.OpenRead(path + @"\one.wav"));

            IntPtr format = wr1.ReadFormat();

            byte[] data1 = wr1.ReadData();

            wr1.Close();

            WaveReader wr2 = new WaveReader(File.OpenRead(path + @"\two.wav"));

            byte[] data2 = wr2.ReadData();

            wr2.Close();

            WaveWriter ww = new WaveWriter(File.Create(path + @"\join.wav"), AudioCompressionManager.FormatBytes(format));

            ww.WriteData(data1);

            ww.WriteData(data2);

            ww.Close();

        }


Up

2. I want to read an existing wav file, change the format then write it back out.

        private void Convert()

        {

            WaveReader read = new WaveReader(File.OpenRead(@"g:\~data\123.wav"));

            IntPtr oldFormat = read.ReadFormat();

            WaveFormat wf = AudioCompressionManager.GetWaveFormat(oldFormat);

            byte[] oldData = read.ReadData();

            FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(wf);

            IntPtr newFormat = fdArr[fdArr.Length - 1].FormatHandle;

            byte[] data = AudioCompressionManager.Convert(oldFormat, newFormat, oldData, true);

            WaveWriter write = new WaveWriter(File.OpenWrite(@"g:\~data\123_new.wav"),

            AudioCompressionManager.FormatBytes(newFormat));

            write.WriteData(data);

            write.Close();

            read.Close();

        }


Up

3. If I buy Single License for Alvas.Audio, will there be no 'about window' deployed on the customers apllication whenever the application is started?

Yes, of course. The 'about window' doesn't appear when You buy the product.

Up

4. Does your .net component require any dependency files?

No, our components don't require any dependency file.

Up

5. Is the runtime license free?

Yes, the runtime license is free.

Up

6. Do you provide some c# code with the classes?

Yes, the source code is available in Team edition of the product.

Up

7. I would like to know under what .Net language is the Audio application written?

Controls are 100% native CLR compliant written in C# and can be used in C#, VB.Net and other .Net languages.

Up

8. Can you please confirm that if I buy a single user license for Alvas Suite, that it also includes Alvas.Audio?

Yes, of course. If You buy Alvas Suite it will include Alvas.Audio.

Up

9. Can we use Alvas.Audio for Pocket PC applications?

No, Alvas.Audio can't be used for Pocket PC applications.

Up

10. It appears to be necessary to select input and output devices. I would like to simply use the default devices that the user has selected on the control panel. Is this possible?

Yes, it is possible. You need to assign -1 to RecorderID. Example, recEx.RecorderID = -1;

Up

11. I need to be able to convert Dialogic files to MP3

     string voxFile = @"C:\AlvasAudio\8000.vox";

     string mp3File = @"C:\AlvasAudio\8000.mp3";

     Vox2Mp3(voxFile, 1, 16, 8000, mp3File);

     //-------

     private static void Vox2Mp3(string voxFile, short channels, short bitsPerSample, int samplesPerSec, string mp3File)

        {

           BinaryReader br = new BinaryReader(File.OpenRead(voxFile));

           MemoryStream pcmStream = new MemoryStream();

           IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(channels, bitsPerSample, samplesPerSec);

           WaveWriter ww = new WaveWriter(pcmStream, AudioCompressionManager.FormatBytes(pcmFormat));

           Vox.Vox2Wav(br, ww);

           br.Close();

           IntPtr mp3Format = AudioCompressionManager.GetCompatibleFormat(pcmFormat, AudioCompressionManager.MpegLayer3FormatTag);

           WaveReader wr = new WaveReader(pcmStream);

           byte[] pcmData = wr.ReadData();

           wr.Close();

           byte[] data = AudioCompressionManager.Convert(pcmFormat, mp3Format, pcmData, false);

           BinaryWriter bw = new BinaryWriter(File.Create(mp3File));

           bw.Write(data, 0, data.Length);

           ww.Close();

           bw.Close();

        }


Up

12. Can you send me the complete list of all audio formats that can be converted FROM and converted TO using Alvas.Audio?

Alvas.Audio uses Windows Audio Compression Manager to convert audio data. You can install additional ACM-drivers. For example, "Ogg Vorbis for MSACM" http://www.free-codecs.com/Ogg_Vorbis_CODEC_for_MSACM_download.htm

Up

13. I want to decode a GSM-stream, but after a quick glance in the example-code and at Alvas.Audio.chm I can't really see how to do that.

To encode a GSM-stream You need to run AudioExCS.exe demo and select "audio format tag" GSM 6.10. To decode a GSM-stream You need to use the Conversion tab and select the file with GSM data...

Up

14. I'm using the Alvas.Audio.dll, and i'm trying to play 2 wav's at the same time (I don't want the first one to stop when the second one begins). How can I make this happen?

Instead of PlayerEx.AddData use PlayerEx.AddMixData.

Up

15. Is this control suitable for use in MC++ Windows forms projects?

Yes, Alvas.Audio is suitable for use in MC++ (with managed extension) .Net Windows forms projects. Requirements: .Net Framework v1.1 or later (also .NET v3.5)

Up

16. Would your audio compenent be suitable for Voip, would it decode and encode fast enough to keep latency at a minimum. Has it been used in this type of environment.

Yes, of course.

Up

17. Can I use your audio toolkit to extract portions of a wav file to a new wav file?

wr.ReadData(2, 1);

Up

18. Have you tested the audio on Vista?

Yes, of course.

Up

19. Is it possible to insert new recordings into existing WAV files?

Yes, you can insert audio data into existing WAV file.

Up

20. What does a single license entitle us to do, and how does it affect sales of software produced that include Alvas.Audio.

Single license allows one developer to use Alvas.Audio. If You have more developers in the project You need to purchase additional licenses. For example Team license is for 4 developers. Any kind of license gives You Royalty-Free redistribution rights with your applications.

Up

21. How do I stop (not pause) audio that's allready playing in command?

Please use playerEx.ClosePlayer() method.

Up

22. I would like to use your audio control for VoIP. Record to memory (Speex) and send the data by UDP the receive from UDP and playback raw data. Would your control be suitable for this purpose?

Yes, of course. You need:
1. Download Speex Voice ACM Codec
(http://www.free-codecs.com/download/Speex_Voice_ACM_Codec.htm) to enable Speex voice compression in Your apps.
2. Develop Your UDP application.

Up

23. Using either the WaveReader or Player(Ex) classes, is there anyway for me to tell how long (in seconds) a WAV file is?

Look at WaveReader.GetDurationInMS.

Up

24. I'm looking for a way via a web page to convert a saved Wav file to MP3. Will your code allow me to do so?

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using Alvas.Audio;

using System.IO;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        ConvertAudio();

    }

 

    private void ConvertAudio()

    {

        string webFile = @"D:\AudioCS\bin\Debug\_web.mp3";

        string pcmFile = @"D:\AudioCS\bin\Debug\_AudioCS.wav";

        using (WaveReader wr = new WaveReader(File.OpenRead(pcmFile)))

        {

            IntPtr pcmFormat = wr.ReadFormat();

            byte[] pcmData = wr.ReadData();

            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(webFile))

                    {

                        wr2.MakeMP3(fs);

                    }

                }

            }

        }

    }

}


Up

25. I just need to get the duration in MS for a file. This code will be on an ASP.NET website, so I want to instance your class, assign a file name (NOT PLAY THE FILE) and then just get the duration. Is this possible with your Alvas.Audio classes - if so, which class does it?

Yes. Please use

            string path = @"c:\test.wav";

            WaveReader wr = new WaveReader(File.OpenRead(path));

            int durationInMS = wr.GetDurationInMS();

            wr.Close();


Up

26. I am developing an application in VB.net 2.0, and i am looking for a library to transform u-law audio files into mp3. Could I get some sample code to help me get this to work?

        Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click

            Dim inFile As String = "path_to_your_file.wav"

            Dim outFile As String = "path_to_output_file.mp3"

            Convert(inFile, outFile)

        End Sub

 

        Public Sub Convert(ByVal inFile As String, ByVal outFile As String)

            Dim inFs As FileStream = File.OpenRead(inFile)

            Dim wr As WaveReader = New WaveReader(inFs)

            Dim inFormat As IntPtr = wr.ReadFormat()

            Dim inData As Byte() = wr.ReadData

            Dim pcmFormat As IntPtr = AudioCompressionManager.GetCompatibleFormat(inFormat, AudioCompressionManager.PcmFormatTag)

            Dim pcmData As Byte() = AudioCompressionManager.Convert(inFormat, pcmFormat, inData, False)

            Dim mp3Format As IntPtr = AudioCompressionManager.GetCompatibleFormat(pcmFormat, AudioCompressionManager.MpegLayer3FormatTag)

            Dim mp3Data As Byte() = AudioCompressionManager.Convert(pcmFormat, mp3Format, pcmData, False)

            Dim outFs As MemoryStream = New MemoryStream()

            Dim ww As WaveWriter = New WaveWriter(outFs, AudioCompressionManager.FormatBytes(mp3Format))

            ww.WriteData(mp3Data)

            Dim outWr As WaveReader = New WaveReader(outFs)

            outWr.MakeMP3(File.Create(outFile))

            ww.Close()

        End Sub


Up

27. Is it possible to default to a particular format on any machine (e.g. 'MP3, 20kbps, 11,025Hz, mono') without the user having to specify it? I need to default to a low quality mp3 format for speech recording and I don't want the user to have to select anything. I want to make it as simple as possible for them. Is it reliable to just iterate through the FormatTags and select the right one based on matching a string? Or will different client machines have different values/indexes for these tags?

        //---

        private static IntPtr GetFormat()

        {

            WaveFormat wf = new WaveFormat();

            wf.wFormatTag = AudioCompressionManager.MpegLayer3FormatTag;

            wf.nChannels = 1;

            wf.nSamplesPerSec = 11025;

            FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(wf);

            foreach (FormatDetails fd in fdArr)

            {

                WaveFormat fdWf = AudioCompressionManager.GetWaveFormat(fd.FormatHandle);

                if (fdWf.nAvgBytesPerSec * 8 == 20000)

                {

                    return fd.FormatHandle;

                }

            }

            return IntPtr.Zero;

        }


Up

28. I need to be able to convert from ADPCM 6khz 4-bit mono, ADPCM 8khz 4-bit mono, PCM8 8khz 8-but uLaw mono formats and standard formats such as WAV.

Please see the code below for converting Your three sample audio files.

            Vox2Pcm(@"C:\AlvasAudio\8000.vox", @"C:\AlvasAudio\8000.wav", 8000);

            Vox2Pcm(@"C:\AlvasAudio\6000.vox", @"C:\AlvasAudio\6000.wav", 6000);

            uLaw(@"C:\AlvasAudio\8000.pcm", @"C:\AlvasAudio\8000.pcm.wav");

 

        //-------

        private static void uLaw(string inFile, string outFile)

        {

            WaveFormat wf = new WaveFormat();

            wf.nChannels = 1;

            wf.nSamplesPerSec = 8000;

            wf.wFormatTag = AudioCompressionManager.MuLawFormatTag;

            FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(wf);

            IntPtr format = fdArr[0].FormatHandle;

            RawReader br = new RawReader(File.OpenRead(inFile), format);

            byte[] data = br.ReadData();

            br.Close();

            WaveWriter ww = new WaveWriter(File.Create(outFile),

            AudioCompressionManager.FormatBytes(format));

            ww.WriteData(data);

            ww.Close();

        }

 

        private static void Vox2Pcm(string inFile, string outFile, int samplesPerSec)

        {

            BinaryReader br = new BinaryReader(File.OpenRead(inFile));

            IntPtr format = AudioCompressionManager.GetPcmFormat(1, 16, samplesPerSec);

            WaveWriter ww = new WaveWriter(File.Create(outFile),

            AudioCompressionManager.FormatBytes(format));

            Vox.Vox2Wav(br, ww);

            br.Close();

            ww.Close();

        }


Up

29. Must I pay a license for every deploy on my customer or only one for developer?

You must pay a license for every developer in your team.

Up

30. Reading / Writing of our VOX Files is not possibile.

Alvas.Audio now supports Dialogic Vox files. Please download new version http://www.alvas.net/Download/Alvas.Audio.zip and see AudioExCS sample.

Up

31. Can you convert WAV files to the headerless formats like Dialogic VOX and PCM 8khz?

Please see code for Wav2Vox with resample

            Wav2Vox(@"C:\AlvasAudio\6000.wav", @"C:\AlvasAudio\6000.wav.vox", 8000);

 

 

        private static void Wav2Vox(string inFile, string outFile, int samplesPerSec)

        {

            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);

            }

            if (wf.nSamplesPerSec != samplesPerSec)

            {

                Resample(ref format, ref data, ref wf, samplesPerSec);

            }

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(outFile));

            BinaryReader br = new BinaryReader(new MemoryStream(data));

            Vox.Raw2Vox(br, bw, wf.wBitsPerSample);

            br.Close();

            bw.Close();

        }

 

        private static void Resample(ref IntPtr format, ref byte[] data, ref WaveFormat wf,

        int samplesPerSec)

        {

            foreach (FormatDetails fd in

            AudioCompressionManager.GetCompatibleFormatList(format))

            {

                if (fd.FormatTag == AudioCompressionManager.PcmFormatTag)

                {

                    WaveFormat wfFd = AudioCompressionManager.GetWaveFormat(fd.FormatHandle);

                    if (wf.wBitsPerSample == wfFd.wBitsPerSample && wf.nChannels ==

                    wfFd.nChannels && wfFd.nSamplesPerSec == samplesPerSec)

                    {

                        byte[] buffer = AudioCompressionManager.Convert(format, fd.FormatHandle, data, false);

                        format = fd.FormatHandle;

                        data = buffer;

                        wf = wfFd;

                    }

                }

            }

        }

 

        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;

        }


Up

32. It can play from an array of doubles?

        PlayerEx pl = new PlayerEx();

 

        private static void PlayArray(PlayerEx pl)

        {

            double fs = 8000; // sample freq

            double freq = 1000; // desired tone

            short[] mySound = new short[4000];

            for (int i = 0; i < 4000; i++)

            {

                double t = (double)i / fs; // current time

                mySound[i] = (short)(Math.Cos(t * freq) * (short.MaxValue));

            }

            IntPtr format = AudioCompressionManager.GetPcmFormat(1, 16, (int)fs);

            pl.OpenPlayer(format);

            byte[] mySoundByte = new byte[mySound.Length * 2];

            Buffer.BlockCopy(mySound, 0, mySoundByte, 0, mySoundByte.Length);

            pl.AddData(mySoundByte);

            pl.StartPlay();

        }


Up

33. I was evaluating your product to use in an application for Asterisk(VOIP) solution, but I found there is no output support for SLINEAR. Do you plan to support this format? This would be a great option since there is no Windows application to make the conversion for Asterisk.

Alvas.Audio supports SLINEAR files. See code below.

            Wav2Sln(@"C:\AlvasAudio\obrigada.wav", @"C:\AlvasAudio\obrigada.sln");

        //---

        private static void Wav2Sln(string inFile, string outFile)

        {

            IntPtr newFormat = AudioCompressionManager.GetPcmFormat(1, 16, 8000);

            WaveReader wr = new WaveReader(File.OpenRead(inFile));

            IntPtr oldFormat = wr.ReadFormat();

            byte[] data = wr.ReadData();

            wr.Close();

            byte[] buffer = AudioCompressionManager.Convert(oldFormat, newFormat, data, false);

            using (RawWriter bw = new RawWriter(File.Create(outFile)))

            {

                bw.WriteData(buffer);

            }

        }


Up

34. How to convert a wave file into an raw alaw 8Khz mono file?

            string pcmFile = @"C:\AlvasAudio\obrigada.wav";

            string alawFile = @"C:\AlvasAudio\obrigada.alaw";

            Pcm2ALaw(pcmFile, alawFile);

        //---

        private static void Pcm2ALaw(string wavFile, string alawFile)

        {

            WaveReader wr = new WaveReader(File.OpenRead(wavFile));

            IntPtr format = wr.ReadFormat();

            byte[] data = wr.ReadData();

            wr.Close();

            WaveFormat wfAlaw = new WaveFormat();

            wfAlaw.wFormatTag = AudioCompressionManager.ALawFormatTag;

            wfAlaw.nChannels = 1;

            wfAlaw.nSamplesPerSec = 8000;

            FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(wfAlaw);

            WaveFormat wf = AudioCompressionManager.GetWaveFormat(format);

            if (wf.wFormatTag != AudioCompressionManager.PcmFormatTag)//Decode if not PCM data

            {

                Decode2Pcm(ref format, ref data, ref wf);

            }

            if (wf.nSamplesPerSec != wfAlaw.nSamplesPerSec || wf.nChannels != wfAlaw.nChannels)

            {

                Resample(ref format, ref data, ref wf, wfAlaw.nSamplesPerSec, wfAlaw.nChannels);

            }

 

            byte[] buffer = AudioCompressionManager.Convert(format, fdArr[0].FormatHandle, data, false);

            RawWriter bw = new RawWriter(File.Create(alawFile));

            bw.WriteData(buffer);

            bw.Close();

        }

 

        private static void Resample(ref IntPtr format, ref byte[] data, ref WaveFormat wf, int samplesPerSec, short channels)

        {

            IntPtr newFormat = AudioCompressionManager.GetPcmFormat(channels, wf.wBitsPerSample, samplesPerSec);

            byte[] buffer = AudioCompressionManager.Convert(format, newFormat, data, true);

            format = newFormat;

            wf = AudioCompressionManager.GetWaveFormat(newFormat);

            data = buffer;

        }

 

        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;

        }


Up

35. We need to be able to essentially convert a wav file while adjusting its speed by a factor.

            ChangeSpeed(@"g:\AlvasAudio\obrigada.wav", @"g:\AlvasAudio\obrigada1.wav", 50);//two times as quickly

            ChangeSpeed(@"g:\AlvasAudio\obrigada.wav", @"g:\AlvasAudio\obrigada2.wav", 200);//two times as slowly

 

        public static void ChangeSpeed(string inFile, string outFile, int persent)

        {

            if (persent < 1)

            {

                throw new ArgumentOutOfRangeException("persent");

            }

            WaveReader wr = new WaveReader(File.OpenRead(inFile));

            IntPtr inFormat = wr.ReadFormat();

            byte[] data = wr.ReadData();

            wr.Close();

            WaveWriter ww = new WaveWriter(File.Create(outFile), AudioCompressionManager.FormatBytes(inFormat));

            WaveFormat wf = AudioCompressionManager.GetWaveFormat(inFormat);

            WaveFormat wfPrev = wf;

            if (wf.wFormatTag != AudioCompressionManager.PcmFormatTag)//Decode if not PCM da

            {

                Decode2Pcm(ref inFormat, ref data, ref wf);

            }

            int samplesPerSecond = wf.nSamplesPerSec * persent / 100;

            IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(wf.nChannels, wf.wBitsPerSample, samplesPerSecond);

            byte[] buffer = AudioCompressionManager.Convert(inFormat, pcmFormat, data, false);

            if (!wfPrev.Equals(wf))

            {

                buffer = AudioCompressionManager.Convert(inFormat, ww.GetFormat(), buffer, false);

            }

            ww.WriteData(buffer);

            ww.Close();

        }


Up

36. Does the Alvas.Audio library work with Terminal Services?

Due to the way audio drivers/codecs are remapped using TS with Windows 2000, the library will not work through TS when connecting to a Windows 2000 Server. It works fine from the console.

Up

37. How to send audio stream in the browser?

    public static void ResponseAudioStream(HttpResponse Response, string voxFile, int samplesPerSec)

    {

        BinaryReader br = new BinaryReader(File.OpenRead(voxFile));

        MemoryStream pcmStream = new MemoryStream();

 

        IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(1, 16, samplesPerSec);

        WaveWriter ww = new WaveWriter(pcmStream, AudioCompressionManager.FormatBytes(pcmFormat));

        Vox.Vox2Wav(br, ww);

        WaveReader wr = new WaveReader(pcmStream);

 

        byte[] pcmData = pcmStream.ToArray();

 

        br.Close();

        ww.Close();

        wr.Close();

        pcmStream.Close();

 

        Response.ContentType = "audio/x-wav";

        Response.BinaryWrite(pcmData);

        Response.End();

    }


Up

38. How to Play big audio files?

        private void btnPlay_Click(object sender, EventArgs e)

        {

            StartPlay(File.OpenRead(@"c:\audio\big.wav"));

        }

 

        public MainForm()

        {

            InitializeComponent();

            playEx.Done += new PlayerEx.DoneEventHandler(playEx_Done);

        }

 

        void playEx_Done(object sender, DoneEventArgs e)

        {

            ReadData();

        }

 

        private PlayerEx playEx = new PlayerEx();

        private WaveReader wr = null;

        private int pos = 0;

        private int seconds = 5;

        private int len = 0;

 

        public void StartPlay(Stream _stream)

        {

            if (playEx.State == DeviceState.Paused)

            {

                playEx.ResumePlay();

            }

            else

            {

                pos = 0;

                wr = new WaveReader(_stream);

                len = wr.GetDurationInMS() / 1000;

                IntPtr format = wr.ReadFormat();

                playEx.OpenPlayer(format);

                ReadData();

                playEx.StartPlay();

            }

        }

 

        private void ReadData()

        {

            if (pos <= len)

            {

                byte[] data = wr.ReadData(pos, seconds);

                pos += seconds;

                playEx.AddData(data);

            }

        }


Up

39. Simple RecorderEx example

using System;

using System.Windows.Forms;

using Alvas.Audio;

using System.IO;

 

namespace SimpleRecorder

{

    public partial class RecorderForm : Form

    {

        public RecorderForm()

        {

            InitializeComponent();

            Init();

        }

 

        private void Init()

        {

            btnStop.Enabled = false;

            rex = new RecorderEx();

            IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(1, 16, 44100);

            rex.Format = pcmFormat;//AudioCompressionManager.GetCompatibleFormat(pcmFormat, AudioCompressionManager.Gsm610FormatTag);

            rex.Open += new EventHandler(rex_Open);

            rex.Data += new RecorderEx.DataEventHandler(rex_Data);

            rex.Close += new EventHandler(rex_Close);

        }

 

        void rex_Close(object sender, EventArgs e)

        {

            ww.Close();

            ww = null;

        }

 

        void rex_Data(object sender, DataEventArgs e)

        {

            ww.WriteData(e.Data);

        }

 

        void rex_Open(object sender, EventArgs e)

        {

            if (ww != null)

            {

                ww.Close();

            }

            string fileName = Path.ChangeExtension(Application.ExecutablePath, ".wav");

            ww = new WaveWriter(File.Create(fileName),

                AudioCompressionManager.FormatBytes(rex.Format));

        }

 

        private RecorderEx rex;

        private WaveWriter ww;

 

        private void btnRec_Click(object sender, EventArgs e)

        {

            rex.StartRecord();

            EnableButtons();

        }

 

        private void EnableButtons()

        {

            btnStop.Enabled = !btnStop.Enabled;

            btnRec.Enabled = !btnRec.Enabled;

        }

 

        private void btnStop_Click(object sender, EventArgs e)

        {

            rex.StopRecord();

            EnableButtons();

        }

    }

}


Up

40. Simple PlayerEx example

using System;

using System.Windows.Forms;

using Alvas.Audio;

using System.IO;

 

namespace SimpleRecorder

{

    public partial class PlayerForm : Form

    {

        public PlayerForm()

        {

            InitializeComponent();

        }

 

        private PlayerEx plex = new PlayerEx();

 

        private void Play(string fileName)

        {

            using (WaveReader wr = new WaveReader(File.OpenRead(fileName)))

            {

                IntPtr format = wr.ReadFormat();

                byte[] data = wr.ReadData();

                plex.OpenPlayer(format);

                plex.AddData(data);

            }

            plex.StartPlay();

        }

 

        private void btnPlay_Click(object sender, EventArgs e)

        {

            Play(@"G:\AlvasAudio\gsm.wav");

        }

 

        private void btnStop_Click(object sender, EventArgs e)

        {

            if (plex.State != DeviceState.Closed)

            {

                plex.ClosePlayer();

            }

        }

 

    }

}


Up

41. Can you tell me whether the player will support playing Dialogic .vox (adpcm) format?

        private PlayerEx playEx = new PlayerEx();

 

        private void button1_Click(object sender, EventArgs e)

        {

            Stream str = Vox2Wav(@"c:\audio\8000.vox", 8000);

            WaveReader wr = new WaveReader(str);

            IntPtr format = wr.ReadFormat();

            byte[] data = wr.ReadData();

            str.Close();

            playEx.OpenPlayer(format);

            playEx.AddData(data);

            playEx.StartPlay();

        }

 

        private static Stream Vox2Wav(string voxFile, int samplesPerSec)

        {

            BinaryReader br = new BinaryReader(File.OpenRead(voxFile));

            IntPtr format = AudioCompressionManager.GetPcmFormat(1, 16, samplesPerSec);

            MemoryStream ms = new MemoryStream();

            WaveWriter ww = new WaveWriter(ms, AudioCompressionManager.FormatBytes(format));

            Vox.Vox2Wav(br, ww);

            br.Close();

            return ms;

        }


Up

42. I expected that the RecorderEx.Data event would be raised whenever a buffer (size determined by BufferSize) was filled, but it's only raised on the half-second. Is there any way to reduce this?

            recEx.AutoSizeBuffer = false;

            WaveFormat wf = AudioCompressionManager.GetWaveFormat(recEx.Format);

            recEx.BufferSize = AudioCompressionManager.Milliseconds2Bytes(wf, 100);//100 milliseconds


Up

43. How do I Boost the volume of an existing WAVE file - How can I make it louder?

        private static void ChangeVolume(string inFile, string outFile, int persent)

        {

            Stream inStream = File.OpenRead(inFile);

            Stream outStream = File.Create(outFile);

            WaveReader wr = new WaveReader(inStream);

            IntPtr format = wr.ReadFormat();

            byte[] data = wr.ReadData();

            wr.Close();

            byte[] buffer = AudioCompressionManager.ChangeVolume(format, data, persent);

            WaveWriter ww = new WaveWriter(outStream, AudioCompressionManager.FormatBytes(format));

            ww.WriteData(buffer);

            ww.Close();

        }


Up

44. Do you have any examples or sample applications that record directly to mp3?

        void recEx_DataMp3(object sender, DataEventArgs e)

        {

            mw.WriteData(e.Data);

        }

 

        private Mp3Writer mw;

        RecorderEx recEx = new RecorderEx();

 

        public void RecordMp3(string fileName)

        {

            recEx.Close += new EventHandler(recEx_CloseMp3);

            recEx.Data += new RecorderEx.DataEventHandler(recEx_DataMp3);

            FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(AudioCompressionManager.MpegLayer3FormatTag);

            IntPtr format = fdArr[fdArr.Length - 1].FormatHandle;//GetMp3Format(2, 56, 24000);

            recEx.Format = format;

            mw = new Mp3Writer(File.Create(fileName));

            recEx.StartRecord();

        }


Up

45. Can Alvas.NET perform mp3 playing in C# with selected sound card. I have multiple sound card on my PC.

        private void PlayMp3()

        {

            playEx.PlayerID = 0;//select your sound card

            string fileName = @"c:\test.mp3";

            Mp3Reader br = new Mp3Reader(File.OpenRead(fileName));

            IntPtr format = br.ReadFormat();

            byte[] data = br.ReadData();

            br.Close();

            playEx.OpenPlayer(format);

            playEx.AddData(data);

            playEx.StartPlay();

        }


Up

46. I would like to know if it is possible to record both line-in and line-out from a soundcard (full duplex).

    public class RecordPlayForm : Form

    {

        public RecordPlayForm()

        {

            InitializeComponent();

            Init();

        }

 

        RecorderEx rex = new RecorderEx();

        PlayerEx play = new PlayerEx();

        IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(1, 16, 44100);

 

        private void Init()

        {

            rex.Data += new RecorderEx.DataEventHandler(rex_Data);

            rex.Open += new EventHandler(rex_Open);

            rex.Close += new EventHandler(rex_Close);

            rex.Format = pcmFormat;

        }

 

        void rex_Open(object sender, EventArgs e)

        {

            play.OpenPlayer(pcmFormat);

            play.StartPlay();

        }

 

        void rex_Close(object sender, EventArgs e)

        {

            play.ClosePlayer();

        }

 

        void rex_Data(object sender, DataEventArgs e)

        {

            play.AddData(e.Data);

        }

 

        private void btnRecordPlay_Click(object sender, EventArgs e)

        {

            rex.StartRecord();

        }

 

        private void btnStop_Click(object sender, EventArgs e)

        {

            rex.StopRecord();

        }

    }


Up

47. Does Alvas.Audio support 64bit operating systems?

Yes. You need change your project property "Project/ Properties.../Build/Platform Target" to "x86" and rebuild.

Up

48. How can I check frequency (sample rate) of MP3 file? The only way I could find is to use FormatDetails struct and parse frequency out of it's FormatName property. However, I'm sure there are nicer way to achieve this :)

Please use WaveFormat.nSamplesPerSec field.

Up

49. I am a newbie trying to recode MP3 file to a different bit rate/sample rate/mode. Like changing the Bit rate, Sample rate or changing from stereo to mono or their combination. I would really appreciate any help, with code if possible.

To change you need to decode mp3 to pcm. Edit pcm and encoding back to mp3. The example shows how to change the frequency to 8000.

        public void Mp3(string inFile)

        {

            //mp3 -> mp3 mono 8000 samples per second example

            int sps = 8000;

            short mono = 1;

            string outFile = inFile + ".mp3";

            Mp3Reader mr = new Mp3Reader(File.OpenRead(inFile));

            IntPtr formatMp3 = mr.ReadFormat();

            byte[] dataMp3 = mr.ReadData();

            mr.Close();

            IntPtr formatPcm = AudioCompressionManager.GetCompatibleFormat(formatMp3, AudioCompressionManager.PcmFormatTag);

            //mp3 -> pcm

            byte[] dataPcm = AudioCompressionManager.Convert(formatMp3, formatPcm, dataMp3, false);

            WaveFormat wf = AudioCompressionManager.GetWaveFormat(formatPcm);

            IntPtr formatPcm8000 = AudioCompressionManager.GetPcmFormat(mono, wf.wBitsPerSample, sps);

            //pcm -> pcm 8000 sps

            byte[] dataPcm8000 = AudioCompressionManager.Convert(formatPcm, formatPcm8000, dataPcm, false);

            //pcm8000 -> mp3 8000 sps

            IntPtr formatMp3_8000 = AudioCompressionManager.GetCompatibleFormat(formatPcm8000, AudioCompressionManager.MpegLayer3FormatTag);

            byte[] dataMp3_8000 = AudioCompressionManager.Convert(formatPcm8000, formatMp3_8000, dataPcm8000, false);

            Mp3Writer mw = new Mp3Writer(File.Create(outFile));

            mw.WriteData(dataMp3_8000);

            mw.Close();

        }


Up

50. Can you give an example to convert a mp3 file from 320kbps bit rate, stereo, 44khz sample rate to 48kbps bit rate, mono, 22khz.

        public void Mp3(string inFile)

        {

            //mp3 -> mp3 mono 48000 samples per second example

            int sps = 48000;

            short mono = 1;

            string outFile = inFile + ".mp3";

            Mp3Reader mr = new Mp3Reader(File.OpenRead(inFile));

            IntPtr formatMp3 = mr.ReadFormat();

            byte[] dataMp3 = mr.ReadData();

            mr.Close();

            IntPtr formatPcm = AudioCompressionManager.GetCompatibleFormat(formatMp3, AudioCompressionManager.PcmFormatTag);

            //mp3 -> pcm

            byte[] dataPcm = AudioCompressionManager.Convert(formatMp3, formatPcm, dataMp3, false);

            WaveFormat wf = AudioCompressionManager.GetWaveFormat(formatPcm);

            IntPtr formatPcm8000 = AudioCompressionManager.GetPcmFormat(mono, wf.wBitsPerSample, sps);

            //pcm -> pcm 48000 sps

            byte[] dataPcm8000 = AudioCompressionManager.Convert(formatPcm, formatPcm8000, dataPcm, false);

            //pcm8000 -> mp3 48000 sps

            IntPtr formatMp3_8000 = AudioCompressionManager.GetCompatibleFormat(formatPcm8000, AudioCompressionManager.MpegLayer3FormatTag);

            byte[] dataMp3_8000 = AudioCompressionManager.Convert(formatPcm8000, formatMp3_8000, dataPcm8000, false);

            Mp3Writer mw = new Mp3Writer(File.Create(outFile));

            mw.WriteData(dataMp3_8000);

            mw.Close();

        }


Up

51. Our company needs audio control, which can record separately and independently right and left channel from stereo input. Has Alvas.Audio got such functionality?

Yes, You can use AudioCompressionManager.SplitStereo method for split one stereo to 2 mono.

using System;

using Alvas.Audio;

using System.IO;

using System.Windows.Forms;

 

namespace ConvertMp3

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            Init();

        }

 

        private void Init()

        {

            rex.Open += new EventHandler(rex_Open);

            rex.Data += new RecorderEx.DataEventHandler(rex_Data);

            rex.Close += new EventHandler(rex_Close);

        }

 

        void rex_Data(object sender, DataEventArgs e)

        {

            IntPtr formatMono = IntPtr.Zero;

            AudioCompressionManager.SplitStereo(rex.Format, e.Data, ref

formatMono,

                ref leftData, ref rightData);

            if (ww1 == null)

            {

                byte[] formatBytes =

AudioCompressionManager.FormatBytes(formatMono);

                ww1 = new WaveWriter(File.Create("left.wav"), formatBytes);

                ww2 = new WaveWriter(File.Create("right.wav"), formatBytes);

            }

            ww1.WriteData(leftData);

            ww2.WriteData(rightData);

        }

 

        void rex_Open(object sender, EventArgs e)

        {

        }

 

        void rex_Close(object sender, EventArgs e)

        {

            ww1.Close();

            ww2.Close();

            ww1 = null;

            ww2 = null;

        }

 

        RecorderEx rex = new RecorderEx();

        WaveWriter ww1;

        WaveWriter ww2;

        byte[] leftData = null;

        byte[] rightData = null;

 

        private void btnRecord_Click(object sender, EventArgs e)

        {

            rex.Format = AudioCompressionManager.GetPcmFormat(2, 16, 44100);

            rex.StartRecord();

        }

 

        private void btnStop_Click(object sender, EventArgs e)

        {

            rex.StopRecord();

        }

    }

}


Up

52. How can I get higher quality when converting from .vox to .mp3.

Vox2Mp3(@"c:\audio\files\8000.vox", 8000, 16000);

 

 

        private static void Vox2Mp3(string voxFile, int samplesPerSecFrom,

int samplesPerSecTo)

        {

            BinaryReader br = new BinaryReader(File.OpenRead(voxFile));

            MemoryStream pcmStream = new MemoryStream();

            IntPtr pcmFormat = AudioCompressionManager.GetPcmFormat(1, 16,

samplesPerSecFrom);

            WaveWriter ww = new WaveWriter(pcmStream,

AudioCompressionManager.FormatBytes(pcmFormat));

            Vox.Vox2Wav(br, ww);

            br.Close();

 

            WaveReader wr = new WaveReader(pcmStream);

            byte[] pcmData = wr.ReadData();

            wr.Close();

            IntPtr pcmFormat2 = AudioCompressionManager.GetPcmFormat(1, 16,

samplesPerSecTo);

            byte[] pcmData2 = AudioCompressionManager.Convert(pcmFormat,

pcmFormat2, pcmData, false);

 

            IntPtr mp3Format =

AudioCompressionManager.GetCompatibleFormat(pcmFormat2,

AudioCompressionManager.MpegLayer3FormatTag);

            byte[] data = AudioCompressionManager.Convert(pcmFormat2,

mp3Format, pcmData2, false);

            string mp3File = voxFile + ".mp3";

            Mp3Writer mw = new Mp3Writer(File.Create(mp3File));

            mw.WriteData(data);

            ww.Close();

            mw.Close();

        }


Up

53. Could you be more specific about adding the control to the toolbox.

Right-click on Toolbox, click "Add Tab" and enter "Alvas.Audio", click "Choose Items...", click "Browse..." and select Alvas.Audio.dll. Click "OK".

Up

54. After the file has been played I want to delete it, but I get an “access denied” error, because the file is in use. Is there a way to release the file from the DSReader (or PlayerEx) so that I can delete it?

DSReader.Close();

Up

55. I'm looking for .net a component like yours that can convert .wma to .mp3 - can it easily to that.

        private void WmaToMp3(string fileName)

        {

            DsReader dr = new DsReader(fileName);

            IntPtr format = dr.ReadFormat();

            IntPtr formatMp3 =

AudioCompressionManager.GetCompatibleFormat(format,

AudioCompressionManager.MpegLayer3FormatTag);

            byte[] data = dr.ReadData();

            dr.Close();

            byte[] dataMp3 = AudioCompressionManager.Convert(format,

formatMp3, data, false);

            Mp3Writer mw = new Mp3Writer(File.Create(fileName + ".mp3"));

            mw.WriteData(dataMp3);

            mw.Close();

        }


Up

56. Does Alvas.Audio work with Windows 7 RTM?

Yes

Up

57. Is it possible to increase/amplify the volume of mp3 file using Alvas.Audio library?

        public static void ChangeVolumeMp3(string inFile, string outFile)

        {

            Mp3Reader mr = new Mp3Reader(File.OpenRead(inFile));

            byte[] data =

AudioCompressionManager.ChangeVolume(mr.ReadFormat(), mr.ReadData(), 50);

            mr.Close();

            Mp3Writer mw = new Mp3Writer(File.Create(outFile));

            mw.WriteData(data);

            mw.Close();

        }


Up

58. Is it possible to work directly on free licence file formats like Ogg Vorbis?

Yes. You need only install "Ogg Vorbis for MSACM" codec
http://www.free-codecs.com/Ogg_Vorbis_CODEC_for_MSACM_download.htm

Up

59. Can I convert an MP3 file to .VOX format?

        public static void Mp3ToVox(string mp3File, string voxFile)

        {

            int samplesPerSec = 8000;

            Mp3Reader mr = new Mp3Reader(File.OpenRead(mp3File));

            IntPtr format = mr.ReadFormat();

            byte[] data = mr.ReadData();

            mr.Close();

            IntPtr formatPcm = AudioCompressionManager.GetCompatibleFormat(format, AudioCompressionManager.PcmFormatTag);

            WaveFormat wfPcm = AudioCompressionManager.GetWaveFormat(formatPcm);

            byte[] dataPcm = AudioCompressionManager.Convert(format, formatPcm, data, false);

            if (wfPcm.nSamplesPerSec != samplesPerSec)

            {

                Resample(ref formatPcm, ref dataPcm, ref wfPcm, samplesPerSec);

            }

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(voxFile));

            BinaryReader br = new BinaryReader(new MemoryStream(dataPcm));

            Vox.Raw2Vox(br, bw, wfPcm.wBitsPerSample);

            br.Close();

            bw.Close();

        }

 

        private static void Resample(ref IntPtr format, ref byte[] data, ref WaveFormat wf, int samplesPerSec)

        {

            IntPtr newFormat = AudioCompressionManager.GetPcmFormat(wf.nChannels, wf.wBitsPerSample, samplesPerSec);

            byte[] buffer = AudioCompressionManager.Convert(format, newFormat, data, false);

            format = newFormat;

            wf = AudioCompressionManager.GetWaveFormat(newFormat);

            data = buffer;

        }


Up

60. I have a byte array of PCM audio. I would like to convert that to a byte array of GSM audio (and back). Would your Alvas.Audio library be able to do that?

        private static void TestGsmPcm()

        {

            IntPtr formatPcm = AudioCompressionManager.GetPcmFormat(1, 16,

8000);

            byte[] dataPcm = null;//your pcm data

            IntPtr formatGsm;

            byte[] dataGsm;

            //pcm -> gsm

            Convert(formatPcm, dataPcm,

AudioCompressionManager.Gsm610FormatTag, out formatGsm, out dataGsm);

            //gsm -> pcm

            Convert(formatGsm, dataGsm,

AudioCompressionManager.PcmFormatTag, out formatPcm, out dataPcm);

        }

 

        private static void Convert(IntPtr formatIn, byte[] dataIn, short

formatTag, out IntPtr formatOut, out byte[] dataOut)

        {

            formatOut =

AudioCompressionManager.GetCompatibleFormat(formatIn, formatTag);

            dataOut = AudioCompressionManager.Convert(formatIn, formatOut,

dataIn, false);

        }


Up

61. Is there a way to use a specific codec? For example, say I install the lame.acm as part of my application installation. Then the user decides to installs other codecs for some reason. Can I specifically ensure that I use my specific codec?

        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

62. We're having some troubles with big audio files when we attempt to convert them from mp3 to wav: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

        public static bool Mp3ToWav(string inFile, string outFile)

        {

            using (Mp3Reader mp3 = new Mp3Reader(File.OpenRead(inFile)))

            {

                try

                {

                    IntPtr mp3Format = mp3.ReadFormat();

                    IntPtr pcmFormat = AudioCompressionManager.GetCompatibleFormat(mp3Format, AudioCompressionManager.PcmFormatTag);

 

                    AcmConverter acm = new AcmConverter(mp3Format, pcmFormat, false);

                    int sec = 1000;

                    int i = 0;

                    using (WaveWriter ww = new WaveWriter(File.OpenWrite(outFile), AudioCompressionManager.FormatBytes(pcmFormat)))

                    {

                        while (true)

                        {

                            byte[] mp3Data = mp3.ReadData(i, 1000);

                            if (mp3Data.Length == 0)

                            {

                                break;

                            }

                            byte[] pcmData = acm.Convert(mp3Data);

                            ww.WriteData(pcmData);

                            i += sec;

                        }

                        ww.Close();

                    }

                    mp3.Close();

                    GC.Collect();

                    return true;

                }

                catch (Exception ex)

                {

                    mp3.Close();

                    Console.WriteLine("\tCan not convert Mp3 to Wav, " + ex.ToString());

                    return false;

                }

            }

        }


Up

63. Can Alvas.Audio can detect silence detection?

Yes. Please see RecordPlay demo "skip silent"

Up

64. I would like to be able to select the input device like Microphone or CD Audio when recording sound.

Please see RecordPlay example

Up

65. Does your audio control allow real time monitoring of the lenght of the recording? Basically while its recording, can I see position with the scroll bar?

Yes. Please see RecordPlay demo

Up

66. Can your audio library playback Shoutcast or Icecast radio streams? I also need to extract metadata from stream.

Imports Alvas.Audio

 

Public Class MainForm

 

    Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click

        ReadRadio("http://www.wmph.org:7050/wmph64k")

    End Sub

 

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click

 

        If Not t Is Nothing AndAlso t.ThreadState = Threading.ThreadState.Running Then

            t.Abort()

            btnStop.Enabled = False

            btnPlay.Enabled = True

        End If

    End Sub

 

    Private plex As PlayerEx = New Alvas.Audio.PlayerEx(True)

    Private t As Threading.Thread

 

    Private Sub ReadRadio(ByVal StreamURL As String)

        btnStop.Enabled = True

        btnPlay.Enabled = False

        t = New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf ThreadProc))

        t.Start(StreamURL)

    End Sub

 

    Private Sub ThreadProc(ByVal StreamURL As Object)

        Dim WebReq As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(StreamURL), System.Net.HttpWebRequest)

 

        Dim MyURI As New Uri(StreamURL)

 

        WebReq.Headers.Clear()

        WebReq.Timeout = 5000

        WebReq.Headers.Add("GET", MyURI.AbsolutePath & " HTTP/1.0")

        WebReq.UserAgent = "WinampMPEG/5.0"

        WebReq.Headers.Add("Icy-MetaData", "1")

        Dim WebRes As System.Net.WebResponse = WebReq.GetResponse()

        Dim oReader As System.IO.Stream = WebRes.GetResponseStream()

        Dim MetaInterval As Integer = WebRes.Headers("icy-metaint")

        Dim data(MetaInterval - 1) As Byte

        Dim b As Byte = 0

        Dim BlockCount As Integer

        Try

            While True

 

                b = oReader.ReadByte()

                If BlockCount = MetaInterval Then

                    If plex.State = DeviceState.Closed Then

                        Dim mr As Mp3Reader = New Mp3Reader(New IO.MemoryStream(data))

                        Dim format As IntPtr = mr.ReadFormat()

                        mr.Close()

                        plex.OpenPlayer(format)

                        plex.StartPlay()

                    End If

                    plex.AddData(data)

                    Dim MetaDataLength As Integer = b * 16

 

                    If MetaDataLength > 0 Then

                        Dim MetaArray(MetaDataLength - 1) As Byte

                        oReader.Read(MetaArray, 0, MetaDataLength)

                        Dim AEnc As New System.Text.ASCIIEncoding

 

                        Dim TempMetaData As String = AEnc.GetString(MetaArray)

 

                        'Trim it down

                        Dim StartPosition As Integer = TempMetaData.IndexOf("'") + 1

                        Dim EndPosition As Integer = TempMetaData.IndexOf("';", StartPosition)

                        TempMetaData = TempMetaData.Substring(StartPosition, EndPosition - StartPosition)

                        Console.WriteLine(TempMetaData)

                    End If

                    BlockCount = 0

                    Continue While

 

                Else

                    data(BlockCount) = b

                End If

 

                BlockCount = BlockCount + 1

            End While

        Finally

            oReader.Close()

            plex.ClosePlayer()

        End Try

    End Sub

 

    Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed

        btnStop.PerformClick()

    End Sub

End Class


Up

67. First, can you jump to a specific spot in a wav file and start recording from there? Meaning could I record for say five seconds, then replay the sound, then jump to the middle of the recording and start recording again from there?

Yes. Please see RecordPlay example

Up

68. I'm listening to an internet radio station over my speakers, and I'd like to record what I hear, and directly to an mp3 file. Can your alvas.audio contol record 'what you hear'? If so, how?

using System;

using System.Windows.Forms;

using Alvas.Audio;

using System.IO;

using System.Threading;

 

namespace RadioCs

{

    public partial class MainForm : Form

    {

 

        public MainForm()

        {

            InitializeComponent();

            FormClosed += Form1_FormClosed;

            btnPlay.Click += btnPlay_Click;

            btnStop.Click += btnStop_Click;

        }

 

        private void btnPlay_Click(System.Object sender, System.EventArgs e)

        {

            ReadRadio("http://www.wmph.org:7050/wmph64k");

        }

 

 

        private void btnStop_Click(System.Object sender, System.EventArgs e)

        {

            if ((t != null) && t.ThreadState == ThreadState.Running)

            {

                t.Abort();

                btnStop.Enabled = false;

                btnPlay.Enabled = true;

            }

        }

 

        private PlayerEx plex = new Alvas.Audio.PlayerEx(true);

        private System.Threading.Thread t;

 

        private void ReadRadio(string StreamURL)

        {

            btnStop.Enabled = true;

            btnPlay.Enabled = false;

            t = new Thread(new ParameterizedThreadStart(ThreadProc));

            t.Start(StreamURL);

        }

 

        private void ThreadProc(object StreamURL)

        {

            System.Net.HttpWebRequest WebReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(StreamURL.ToString());

 

            Uri MyURI = new Uri(StreamURL.ToString());

 

            WebReq.Headers.Clear();

            WebReq.Timeout = 5000;

            WebReq.Headers.Add("GET", MyURI.AbsolutePath + " HTTP/1.0");

            WebReq.UserAgent = "WinampMPEG/5.0";

            WebReq.Headers.Add("Icy-MetaData", "1");

            System.Net.WebResponse WebRes = WebReq.GetResponse();

            System.IO.Stream oReader = WebRes.GetResponseStream();

            int MetaInterval = Int32.Parse(WebRes.Headers["icy-metaint"]);

            byte[] data = new byte[MetaInterval];

            byte b = 0;

            Mp3Writer mw = new Mp3Writer(File.Create("out.mp3"));

            int BlockCount = 0;

            try

            {

                while (true)

                {

                    b = (byte)oReader.ReadByte();

                    if (BlockCount == MetaInterval)

                    {

                        //Metadata loop

                        mw.WriteData(data);

                        if (plex.State == DeviceState.Closed)

                        {

                            Mp3Reader mr = new Mp3Reader(new MemoryStream(data));

                            IntPtr format = mr.ReadFormat();

                            mr.Close();

                            plex.OpenPlayer(format);

                            plex.StartPlay();

                        }

                        plex.AddData(data);

                        int MetaDataLength = b * 16;

 

                        if (MetaDataLength > 0)

                        {

                            byte[] MetaArray = new byte[MetaDataLength];

                            oReader.Read(MetaArray, 0, MetaDataLength);

                            System.Text.ASCIIEncoding AEnc = new System.Text.ASCIIEncoding();

 

                            string TempMetaData = AEnc.GetString(MetaArray);

 

                            //Trim it down

                            int StartPosition = TempMetaData.IndexOf("'") + 1;

                            int EndPosition = TempMetaData.IndexOf("';", StartPosition);

                            TempMetaData = TempMetaData.Substring(StartPosition, EndPosition - StartPosition);

                            Console.WriteLine(TempMetaData);

                        }

                        BlockCount = 0;

                        continue;

                    }

                    else

                    {

                        data[BlockCount] = b;

                    }

                    BlockCount = BlockCount + 1;

                }

            }

            finally

            {

                oReader.Close();

                mw.Close();

                plex.ClosePlayer();

            }

        }

 

        private void Form1_FormClosed(System.Object sender, System.Windows.Forms.FormClosedEventArgs e)

        {

            btnStop.PerformClick();

        }

    }

}


Up

69. I try to convert a file on my web page but the process get stuck. The web page seems like it tries to load something but won't go on. What can I do?

Demo version shows the Nag-Screen. Use the Alt+Tab to find it and click "OK" button.

Up

70. I'm trying to trial your software, building it into our web application but the trial version I have downloaded won't work in my web app as it keeps trying to pop up a 'nag screen' which causes the app to throw an error. Is there any way to turn this off?

For test this you need start your web app under built-in VisualStudio web server instead of IIS and press NagScreen "OK" button.
Please use Alt+Tab for find NagScreen. This is limitation of the trial version.

Up

71. We are evaluating your Alvas.Audio product for a .net server side mixer and aren't able to evaluate it completely since we keep getting this error: 'Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.' The error seems to come from the Alvas.Audio.AboutBox.ShowNagScreen, which I would guess has to do that we are running a demo. Is there any way of testing server side things without getting that error just to make sure that it works for our project?

What type of applications do you use? For test purpose please
1. use the built-in VisualStudio webserver instead of IIS for ASP.Net application.
2. Or use the console application instead of Windows Service.

Up

72. When converting audio from Wav to Mp3 and NOT using the Wave2Mp3 function, do you always need to convert the wave data into PCM data before converting it to MP3? Is there a reason for doing that?

Wave is container format. Please see
http://en.wikipedia.org/wiki/Wav. Wave files can contain audio in various formats (PCM, ADPCM, MP3 and other). PCM(http://en.wikipedia.org/wiki/PCM) is uncompressed format. Other audio formats are compressed.

Before converting data from one compressed format to another they need to be unpacked in PCM (uncompressed format).
Standard scheme of converting data: [CompressedFormat1] -> PCM -> [CompressedFormat2].
Up

73. I have to connect to a SHOUTcast stream, take 5 seconds of the sound then detect if there is silence (no sound above -14db). Would you be so kind to provide us with some sample?

using System;

using System.Windows.Forms;

using System.Net;

using System.IO;

using Alvas.Audio;

 

namespace RadioCs

{

    public partial class frmMain : Form

    {

        public frmMain()

        {

            InitializeComponent();

            t.Interval = 15 * 60 * 1000;

            t.Tick += new EventHandler(t_Tick);

            t.Enabled = true;

        }

 

        Timer t = new Timer();

 

        void t_Tick(object sender, EventArgs e)

        {

            if (CheckSilent("http://www.wmph.org:7050/wmph64k", 10000, -14))

            {

                Console.WriteLine("Alert!");

            }

        }

 

        private static short dB2Short(double dB)

        {

            double times = Math.Pow(10, dB / 10);

            return (short)(short.MaxValue * times);

        }

 

        private bool CheckSilent(string StreamURL, int timeOut, double mindb)

        {

            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(StreamURL);

 

            Uri MyURI = new Uri(StreamURL);

 

            WebReq.Headers.Clear();

            WebReq.Timeout = timeOut;

            WebReq.Headers.Add("GET", MyURI.AbsolutePath + " HTTP/1.0");

            WebReq.UserAgent = "WinampMPEG/5.0";

            WebReq.Headers.Add("Icy-MetaData", "1");

            WebResponse WebRes = WebReq.GetResponse();

            Stream oReader = WebRes.GetResponseStream();

            int MetaInterval = int.Parse(WebRes.Headers["icy-metaint"]);

            byte[] data = new byte[MetaInterval];

            byte b = 0;

            int BlockCount = 0;

            int pass = 0;

            MemoryStream ms = new MemoryStream();

            try

            {

                while (true)

                {

 

                    b = (byte)oReader.ReadByte();

                    if (BlockCount == MetaInterval)

                    {

                        ms.Write(data, 0, data.Length);

                        pass += 1;

                        if (pass >= 5)

                        {

                            Mp3Reader mr = new Mp3Reader(ms);

                            IntPtr format = mr.ReadFormat();

                            short[] buffer = AudioCompressionManager.RecalculateData(format, ms.ToArray(), -1);

                            mr.Close();

                            int silentLevel = dB2Short(mindb);

                            for (int i = 0; i < buffer.Length; i++)

                            {

                                if (buffer[i] > silentLevel)

                                {

                                    return false;

                                }

                            }

                            return true;

                        }

                        int MetaDataLength = b * 16;

 

                        if (MetaDataLength > 0)//skip metadata

                        {

                            byte[] MetaArray = new byte[MetaDataLength];

                            oReader.Read(MetaArray, 0, MetaDataLength);

                        }

                        BlockCount = 0;

                        continue;

                    }

 

                    else

                    {

                        data[BlockCount] = b;

                    }

 

                    BlockCount = BlockCount + 1;

                }

            }

            finally

            {

                oReader.Close();

            }

        }

 

    }

}


Up

74. I have multiple audio tracks with nothing but music. I have multiple recorded voice tracks no longer than 2-3 seconds each. What I would like to do is 'overlay' a voice track onto an audio track at a specified time and output the results to a single file. E.g. Audio track is 2 minutes long, and I would like to insert the voice track at 23 seconds as well 1m 05 seconds and at 1m 40 seconds. Can Alvas.Audio accomplish this sort of task for me??

Imports System.IO

Imports Alvas.Audio

 

Public Class Form1

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        MixMany("c:\audio\files\")

 

    End Sub

 

    Private Shared Sub Debug(ByVal name As String, ByVal wf As WaveFormat)

        Dim format As String = "Variable: [{0}], FormatTag: {1}, Channels: {2}, SamplesPerSec: {3}, BitsPerSample: {4}, BlockAlign: {5}, AvgBytesPerSec: {6}"

        Console.WriteLine(format, name, wf.wFormatTag, wf.nChannels, wf.nSamplesPerSec, wf.wBitsPerSample, wf.nBlockAlign, wf.nAvgBytesPerSec)

    End Sub

 

    Private Shared Sub MixMany(ByVal dir As String)

 

        Dim format1 As IntPtr

        Dim data1 As Byte()

 

        ReadData(dir + "The Friendship Song.mp3", format1, data1)

 

        Dim format2 As IntPtr

        Dim data2 As Byte()

 

        ReadData(dir + "Kailin 1.mp3", format2, data2)

 

        Dim wf1 As WaveFormat = AudioCompressionManager.GetWaveFormat(format1)

        Debug("wf1", wf1)

        Dim wf2 As WaveFormat = AudioCompressionManager.GetWaveFormat(format2)

        Debug("wf1", wf2)

 

        If Not wf1.Equals(wf2) Then

            data2 = AudioCompressionManager.Convert(format2, format1, data2, False)

        End If

 

        Dim data As Byte() = AudioCompressionManager.MixMany(format1, data1, data2, wf1.nSamplesPerSec * 27.1, wf1.nSamplesPerSec * 83.28)

        Dim formatMp3 As IntPtr = AudioCompressionManager.GetCompatibleFormat(format1, AudioCompressionManager.MpegLayer3FormatTag)

        Debug("wfMp3", AudioCompressionManager.GetWaveFormat(formatMp3))

 

        Dim dataMp3 As Byte() = AudioCompressionManager.Convert(format1, formatMp3, data, False)

 

        Dim mw As New Mp3Writer(File.Create(dir + "Test002.mp3"))

        mw.WriteData(dataMp3)

        mw.Close()

 

        MsgBox("Done!")

 

    End Sub

 

    Private Shared Sub ReadData(ByVal fileName As String, ByRef format1 As IntPtr, ByRef data1 As Byte())

        Dim dr1 As New Mp3Reader(File.OpenRead(fileName))

        format1 = dr1.ReadFormat()

        data1 = dr1.ReadData()

        dr1.Close()

        Dim format1Pcm As IntPtr = AudioCompressionManager.GetCompatibleFormat(format1, AudioCompressionManager.PcmFormatTag)

        Dim data1Pcm() As Byte = AudioCompressionManager.Convert(format1, format1Pcm, data1, False)

        format1 = format1Pcm

        data1 = data1Pcm

    End Sub

 

End Class


Up

75. Effectively, I have a block of memory which contains A-law data and I want to play the data using vb.net. Can you provide some sample code on how I can achieve this with PlayerEx?

        Private playEx As PlayerEx = New PlayerEx()

 

        Private Sub Play(ByVal data As Byte())

            Dim wf As WaveFormat = New WaveFormat()

            wf.wFormatTag = AudioCompressionManager.MuLawFormatTag ' or AudioCompressionManager.ALawFormatTag

            wf.nChannels = 1 ' or 2

            wf.nSamplesPerSec = 8000 ' or other

            Dim format As IntPtr = AudioCompressionManager.GetFormatList(wf)(0).FormatHandle

            playEx.OpenPlayer(format)

            playEx.AddData(data)

            playEx.StartPlay()

        End Sub


Up

76. Can I use Alvas.Audio to play(stream) MP3 from the buffer of byte array. Please explain it with sample code in c#.

        private void btnTest_Click(object sender, EventArgs e)

        {

            PlayMp3Array(File.ReadAllBytes("play.mp3"));

        }

 

        PlayerEx plex = new PlayerEx();

 

        private void PlayMp3Array(byte[] data)

        {

            MemoryStream ms = new MemoryStream(data);

            Mp3Reader mr = new Mp3Reader(ms);

            plex.OpenPlayer(mr.ReadFormat());

            plex.AddData(mr.ReadData());

            mr.Close();

            plex.StartPlay();

        }


Up