Sunday, December 27, 2009

What is a Wave file?

WAV (WAVE) is a container format for storing records of the digitized audio stream. Under Windows, this format is often used as a wrapper for uncompressed audio (PCM). However, in WAV container you can put sound, compressed almost in any codec.
Thus your WAV-file can contain data in different audio formats, such as the IMA ADPCM, Microsoft ADPCM, CCITT A-Law, CCITT u-Law, GSM 6.10, MPEG Layer-3 (mp3) and others.
Code below, you can use to test audio-format data stored in your WAV-file.

        private void WhatIsWaveFile(string fileName)

        {

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

            IntPtr format = wr.ReadFormat();

            wr.Close();

            WaveFormat wf = AudioCompressionManager.GetWaveFormat(format);

            string tag = null;

            switch (wf.wFormatTag)

            {

                case AudioCompressionManager.PcmFormatTag :

                    tag = "PCM";

                    break;

                case AudioCompressionManager.ALawFormatTag :

                    tag = "A-Law";

                    break;

                case AudioCompressionManager.MuLawFormatTag :

                    tag = "Mu-Law";

                    break;

                case AudioCompressionManager.Gsm610FormatTag :

                    tag = "GSM 6.10";

                    break;

                case AudioCompressionManager.ImaAdpcmFormatTag :

                    tag = "IMA ADPCM";

                    break;

                case AudioCompressionManager.AdpcmFormatTag :

                    tag = "Microsoft ADPCM";

                    break;

                case AudioCompressionManager.MpegLayer3FormatTag :

                    tag = "ISO/MPEG Layer3";

                    break;

                default:

                    tag = wf.wFormatTag.ToString();

                    break;

            }

            Console.WriteLine("File '{0}' contains '{1}' data", fileName, tag);

        }


Audio Library needed for this example is here(Alvas.Audio Free Trial).

kick it on DotNetKicks.com

Shout it

No comments:

Post a Comment