Skip to content

Conversation

@tgraupmann
Copy link
Contributor

Start with Menu form.
Added FormClosed event to stop output capture.
Added Output Devices to the dropdown list.
Added Output Devices to graph. (This could be improved to change the buffer size based on the output channels and sample rate of the selected output device for the graph)

@swharden
Copy link
Owner

Thanks for this @tgraupmann! I'll continue to work on it to improve support for different bit depths and sample rates. I'll share what I learn here as I go 👍

@swharden
Copy link
Owner

Hi @tgraupmann, I refactored this some more so all devices (inputs and outputs) are passed as a WasapiCapture object, then can be opened differently as needed. Here are the highlights.

Audio devices are passed into forms

readonly WasapiCapture AudioDevice; public FftMonitorForm(WasapiCapture audioDevice) { InitializeComponent(); AudioDevice = audioDevice; AudioDevice.DataAvailable += WaveIn_DataAvailable; AudioDevice.StartRecording(); FormClosed += FftMonitorForm_FormClosed; } private void FftMonitorForm_FormClosed(object? sender, FormClosedEventArgs e) { AudioDevice.StopRecording(); AudioDevice.Dispose(); }

Input and output devices can share a collection

public readonly MMDevice[] AudioDevices = new MMDeviceEnumerator() .EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active) .ToArray();
foreach (MMDevice device in AudioDevices) { string deviceType = device.DataFlow == DataFlow.Capture ? "INPUT" : "OUTPUT"; string deviceLabel = $"{deviceType}: {device.FriendlyName}"; lbDevice.Items.Add(deviceLabel); }
private WasapiCapture GetSelectedDevice() { MMDevice selectedDevice = AudioDevices[lbDevice.SelectedIndex]; return selectedDevice.DataFlow == DataFlow.Render ? new WasapiLoopbackCapture(selectedDevice) : new WasapiCapture(selectedDevice); }
@swharden swharden merged commit 3676019 into swharden:main Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants