internal LiveSoundLine(int DeviceID) { this.DeviceID = DeviceID; Capabilities = WaveIn.GetCapabilities(DeviceID); input = new WaveIn(WaveCallbackInfo.FunctionCallback()); input.DataAvailable += Wave_DataAvailable; if (Capabilities.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_48S16)) { input.WaveFormat = new WaveFormat(48000, 16, 2); } input.StartRecording(); }
public void Setup() { WaveInCapabilities capabilities = WaveIn.GetCapabilities(deviceNumber); foreach (int waveFormat in Enum.GetValues(typeof(SupportedWaveFormat))) { if (capabilities.SupportsWaveFormat((SupportedWaveFormat)waveFormat)) { SetWaveFormat((SupportedWaveFormat)waveFormat); break; } } }
public AudioDevice GetBestCapability(WaveInCapabilities device) { int sampleRate = 44100; int bitrate = 16; if (device.Channels == 1) { //mono if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_96M16)) { bitrate = 16; sampleRate = 96000; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_96M08)) { bitrate = 8; sampleRate = 96000; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_48M16)) { bitrate = 16; sampleRate = 48000; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_48M08)) { bitrate = 8; sampleRate = 48000; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_4M16)) { bitrate = 16; sampleRate = 44100; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_4M08)) { bitrate = 8; sampleRate = 44100; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_2M16)) { bitrate = 16; sampleRate = 22050; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_2M08)) { bitrate = 8; sampleRate = 22050; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_1M16)) { bitrate = 16; sampleRate = 11025; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_1M08)) { bitrate = 8; sampleRate = 11025; } else { bitrate = 0; sampleRate = 0; } } else { //stereo /*SupportedWaveFormat[] formats = new SupportedWaveFormat[] { SupportedWaveFormat.WAVE_FORMAT_1S08, SupportedWaveFormat.WAVE_FORMAT_1S16, * SupportedWaveFormat.WAVE_FORMAT_2S08, SupportedWaveFormat.WAVE_FORMAT_2S16, * SupportedWaveFormat.WAVE_FORMAT_4S08, SupportedWaveFormat.WAVE_FORMAT_4S16, * SupportedWaveFormat.WAVE_FORMAT_48S08, SupportedWaveFormat.WAVE_FORMAT_48S16, * SupportedWaveFormat.WAVE_FORMAT_96S08, SupportedWaveFormat.WAVE_FORMAT_96S16};*/ if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_96S16)) { bitrate = 16; sampleRate = 96000; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_96S08)) { bitrate = 8; sampleRate = 96000; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_48S16)) { bitrate = 16; sampleRate = 48000; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_48S08)) { bitrate = 8; sampleRate = 48000; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_4S16)) { bitrate = 16; sampleRate = 44100; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_4S08)) { bitrate = 8; sampleRate = 44100; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_2S16)) { bitrate = 16; sampleRate = 22050; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_2S08)) { bitrate = 8; sampleRate = 22050; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_1S16)) { bitrate = 16; sampleRate = 11025; } else if (device.SupportsWaveFormat(SupportedWaveFormat.WAVE_FORMAT_1S08)) { bitrate = 8; sampleRate = 11025; } else { bitrate = 0; sampleRate = 0; } } return(new AudioDevice() { BitRate = bitrate, SampleRate = sampleRate, Channels = device.Channels, DeviceName = device.ProductName }); }