naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.58k stars 1.1k forks source link

Can I get the device info from ASIO controlpanel by C#? #1185

Open hlz2516 opened 2 months ago

hlz2516 commented 2 months ago

In the process of researching simultaneous recording and playback, I found that in my C # code, the input and output sampling rates are manually written(like this):

            var drivers = AsioOut.GetDriverNames();
            var asioOut = new AsioOut(drivers[0]);
            var bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(48000, 4));
            asioOut.InitRecordAndPlayback(bufferedWaveProvider, 2, 48000);
            asioOut.AudioAvailable += AsioOut_AudioAvailable;

I think they should be the same as the sample rate of the input and output device currently being used instead of being manually written, but I don't know how to do it. After calling ShowControlPanel(), moving the mouse over an audio device in the control panel will display the corresponding sample rate, as shown in the figure: Snipaste_2024-09-21_02-10-21 I want to get the sample rate of the currently used device in this control panel, but I found that NAudio doesn't seem to have a corresponding API.