/// <summary> /// Create a new instance of <see cref="LoopbackProvider"/>. /// </summary> /// <param name="Device"><see cref="WasapiLoopbackDevice"/> to use.</param> /// <param name="IncludeSilence">Whether to record silence?... default = true</param> public LoopbackProvider(WasapiLoopbackDevice Device, bool IncludeSilence = true) { _deviceIndex = Device.DeviceIndex; _proc = Procedure; if (IncludeSilence) { _silencePlayer = new Silence(PlaybackDevice.Devices.First(Dev => Dev.Info.Driver == Device.Info.ID)); } BassWasapi.Init(_deviceIndex, Procedure: _proc); BassWasapi.CurrentDevice = Device.DeviceIndex; var info = BassWasapi.Info; WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(info.Frequency, info.Channels); }
/// <summary> /// Create a new instance of <see cref="LoopbackProvider"/>. /// </summary> /// <param name="Device"><see cref="MMDevice"/> to use.</param> /// <param name="IncludeSilence">Whether to record silence?... default = true</param> public LoopbackProvider(MMDevice Device, bool IncludeSilence = true) { _capture = new WasapiLoopbackCapture(Device); _capture.DataAvailable += (Sender, Args) => DataAvailable?.Invoke(this, new DataAvailableEventArgs(Args.Buffer, Args.BytesRecorded)); _capture.RecordingStopped += (Sender, Args) => RecordingStopped?.Invoke(this, new EndEventArgs(Args.Exception)); var mixFormat = _capture.WaveFormat; WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(mixFormat.SampleRate, mixFormat.Channels); if (!IncludeSilence) { return; } _silenceOut = new WasapiOut(Device, AudioClientShareMode.Shared, false, 100); _silenceOut.Init(new SilenceProvider()); }