naudio / NAudio

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

Basic input level monitor - ASIO not showing up #720

Open emanueltilly opened 3 years ago

emanueltilly commented 3 years ago

This is probably a incredibly dumb question, but I'm trying to get input levels of my Dante Virtual Soundcard (ASIO) but its not showing up at all when I enumerate devices. Using NuGet package 1.10.0. Is there anything I can do to my code to make it work?

    private WaveIn recorder;

    public Form1()
    {
        InitializeComponent();

        recorder = new WaveIn();
        recorder.StartRecording();

        MMDeviceEnumerator en = new MMDeviceEnumerator();
        var devices = en.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);
        comboBox1.Items.AddRange(devices.ToArray());
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (comboBox1.Text != "")
        {
            var singledevice = (MMDevice)comboBox1.SelectedItem;
            try { progressBar1.Value = (int)(singledevice.AudioMeterInformation.PeakValues[0] * 100); } catch { }
            try { progressBar2.Value = (int)(singledevice.AudioMeterInformation.PeakValues[1] * 100); } catch { }
            try { progressBar3.Value = (int)(singledevice.AudioMeterInformation.PeakValues[2] * 100); } catch { }
            try { progressBar4.Value = (int)(singledevice.AudioMeterInformation.PeakValues[3] * 100); } catch { }

        }
     }
markheath commented 3 years ago

The MMDeviceEnumerator will find all WASAPI devices. To enumerate ASIO devices, use the AsioOut class instead

emanueltilly commented 3 years ago

Ah I see. Now I'm finding my ASIO devices, but I can't seem to get the PeakValues for the audio meter when using the AsioOut class?

markheath commented 3 years ago

With ASIO, you have to generate your own peak values, by capturing sound and examining the sample values. It's a very low-level driver format.