Beispiel #1
0
        public static SoundFormat[] WaveFormatToSoundFormats(MMInterop.WaveFormat formats)
        {
            List <SoundFormat> soundFormats = new List <SoundFormat>();
            Array allValues = Enum.GetValues(typeof(MMInterop.WaveFormat));

            foreach (var value in allValues)
            {
                MMInterop.WaveFormat vformat = (MMInterop.WaveFormat)value;
                if ((int)value == 0) // WAVE_INVALID_FORMAT
                {
                    continue;
                }
                if ((formats & vformat) == vformat)
                {
                    SoundFormat format = WaveFormatToSoundFormat(vformat);
                    soundFormats.Add(format);
                }
            }
            return(soundFormats.ToArray());
        }
Beispiel #2
0
        public static SoundFormat WaveFormatToSoundFormat(MMInterop.WaveFormat format)
        {
            switch (format)
            {
            case MMInterop.WaveFormat.WAVE_FORMAT_1M08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 1, 11025));

            case MMInterop.WaveFormat.WAVE_FORMAT_1M16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 1, 11025));

            case MMInterop.WaveFormat.WAVE_FORMAT_1S08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 2, 11025));

            case MMInterop.WaveFormat.WAVE_FORMAT_1S16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 2, 11025));

            case MMInterop.WaveFormat.WAVE_FORMAT_2M08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 1, 22050));

            case MMInterop.WaveFormat.WAVE_FORMAT_2M16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 1, 22050));

            case MMInterop.WaveFormat.WAVE_FORMAT_2S08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 2, 22050));

            case MMInterop.WaveFormat.WAVE_FORMAT_2S16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 2, 22050));

            case MMInterop.WaveFormat.WAVE_FORMAT_44M08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 1, 44100));

            case MMInterop.WaveFormat.WAVE_FORMAT_44M16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 1, 44100));

            case MMInterop.WaveFormat.WAVE_FORMAT_44S08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 2, 44100));

            case MMInterop.WaveFormat.WAVE_FORMAT_44S16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 2, 44100));

            case MMInterop.WaveFormat.WAVE_FORMAT_48M08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 1, 48000));

            case MMInterop.WaveFormat.WAVE_FORMAT_48M16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 1, 48000));

            case MMInterop.WaveFormat.WAVE_FORMAT_48S08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 2, 48000));

            case MMInterop.WaveFormat.WAVE_FORMAT_48S16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 2, 48000));

            case MMInterop.WaveFormat.WAVE_FORMAT_96M08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 1, 96000));

            case MMInterop.WaveFormat.WAVE_FORMAT_96M16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 1, 96000));

            case MMInterop.WaveFormat.WAVE_FORMAT_96S08:
                return(new SoundFormat(SoundFormatTag.PCM, 8, 2, 96000));

            case MMInterop.WaveFormat.WAVE_FORMAT_96S16:
                return(new SoundFormat(SoundFormatTag.PCM, 16, 2, 96000));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }