public bool DeviceExists(string deviceName, AudioDeviceType deviceType = AudioDeviceType.Both) { bool hasDevice = false; HotkeyAudioDevice device = null; if ((deviceType == AudioDeviceType.Output || deviceType == AudioDeviceType.Both) && !hasDevice) { device = GetDevice(deviceName, AudioDeviceType.Output); if (device != null) { hasDevice = true; } } if ((deviceType == AudioDeviceType.Input || deviceType == AudioDeviceType.Both) && !hasDevice) { device = GetDevice(deviceName, AudioDeviceType.Input); if (device != null) { hasDevice = true; } } return(hasDevice); }
public static void GetDevices() { List <HotkeyAudioDevice> audioOutputDevicesList = new List <HotkeyAudioDevice>(); for (int deviceId = 0; deviceId < WaveOut.DeviceCount; deviceId++) { WaveOutCapabilities capabilities = WaveOut.GetCapabilities(deviceId); HotkeyAudioDevice audioDevice = new HotkeyAudioDevice(); audioDevice.AudioDeviceId = deviceId; audioDevice.AudioDeviceName = capabilities.ProductName; audioOutputDevicesList.Add(audioDevice); } Instance.AudioOutputDevices = audioOutputDevicesList; List <HotkeyAudioDevice> audioInputDevicesList = new List <HotkeyAudioDevice>(); for (int deviceId = 0; deviceId < WaveIn.DeviceCount; deviceId++) { WaveInCapabilities capabilities = WaveIn.GetCapabilities(deviceId); HotkeyAudioDevice audioDevice = new HotkeyAudioDevice(); audioDevice.AudioDeviceId = deviceId; audioDevice.AudioDeviceName = capabilities.ProductName; audioInputDevicesList.Add(audioDevice); } Instance.AudioInputDevices = audioInputDevicesList; }
public AudioRecorder(HotkeyAudioDevice device, int secondsToHold = 30) { Device = device; SecondsToHold = secondsToHold; WaveSource = new WaveIn(); WaveSource.DeviceNumber = device.AudioDeviceId; WaveSource.WaveFormat = new WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(device.AudioDeviceId).Channels); MaximumBytes = WaveSource.WaveFormat.AverageBytesPerSecond * (SecondsToHold + 1); WaveSource.DataAvailable += new EventHandler <WaveInEventArgs>(waveSource_DataAvailable); WaveSource.RecordingStopped += new EventHandler <StoppedEventArgs>(waveSource_RecordingStopped); RecordedBytes = new ReadWriteBuffer((int)MaximumBytes); Device.Recorders.Add(this); }
public AudioPassthrough(HotkeyAudioDevice input, HotkeyAudioDevice output, AutoTuneSettings autoTuneSettings) { LastPauseOrStart = new DateTime(2000, 1, 1); _autoTuneSettings = autoTuneSettings; _waveSource = new WaveIn(); WaveSource.DeviceNumber = input.AudioDeviceId; //WaveSource.WaveFormat = new WaveFormat(); WaveSource.WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(44100, 1); WaveSource.RecordingStopped += WaveSource_RecordingStopped; WaveSource.DataAvailable += WaveSource_DataAvailable; //WaveSource.BufferMilliseconds = 300; //_waveInProvider = new JoeWaveInProvider(WaveSource); //StereoToMonoProvider16 stereoToMonoprovider = new StereoToMonoProvider16(_waveInProvider); //_wave16ToFloatProvider = new Wave16ToFloatProvider(stereoToMonoprovider); //var test3 = ; MemoryStream = new MemoryStream(new byte[8192]); var rawSourceStream = new RawSourceWaveStream(MemoryStream, WaveFormat.CreateIeeeFloatWaveFormat(44100, 1)); //_autoTuner = new AutoTuneWaveProvider(_wave16ToFloatProvider, AutoTuneSettings); _autoTuner = new AutoTuneWaveProvider(rawSourceStream, AutoTuneSettings); _waveFloatTo16Provider = new WaveFloatTo16Provider(_autoTuner); _monoToStereoProvider = new MonoToStereoProvider16(_waveFloatTo16Provider); //_monoToStereoProvider = new MonoToStereoProvider16(_autoTuner); _waveOutput = new WaveOutEvent(); WaveOutput.DeviceNumber = output.AudioDeviceId; WaveOutput.PlaybackStopped += WaveOutput_PlaybackStopped; WaveOutput.Init(_monoToStereoProvider); //JoeWaveOutEvent joeWaveOut = new JoeWaveOutEvent(); //joeWaveOut.DeviceNumber = output.AudioDeviceId; //joeWaveOut.DesiredLatency = 329; //joeWaveOut.NumberOfBuffers = 7; //joeWaveOut.Init(_monoToStereoProvider); //DirectSoundDeviceInfo foundDeviceInfo = null; //foreach (DirectSoundDeviceInfo deviceInfo in DirectSoundOut.Devices) //{ // if (deviceInfo.Description.Contains(output.AudioDeviceName)) // { // foundDeviceInfo = deviceInfo; // break; // } //} //if (foundDeviceInfo != null) //{ // DirectSoundOutput = new DirectSoundOut(foundDeviceInfo.Guid, 300); // DirectSoundOutput.PlaybackStopped += DirectSoundOutput_PlaybackStopped; // DirectSoundOutput.Init(_monoToStereoProvider); //} }