1
votes

Today I was trying to make simple C# application to display real-time volume of system sound. I have success with NAudio library using this code:

var enumerator = new MMDeviceEnumerator();
var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);

while (true)
{
    Console.Write("\r{0}", device.AudioMeterInformation.MasterPeakValue);
}

// Output: 0,2314617

The problem is that I want to get audio volume of each speaker of my 7.1 audio system instead of master volume, so the output will look like:

Speaker1: 0,435462
Speaker2: 0,237462
Speaker3: 0,535962
Speaker4: 0,335862
Speaker5: 0,835462
Speaker6: 0,635462
Speaker7: 0,335462
Subwoofer: 0,236562

Is there any way I can do it? If there is a way can you provide an example?

1
You are probably looking for PeakValues instead of MasterPeakValue.Roman R.
@RomanR. Oh yeeahh! Thank you very much! I don´t know how I could not see it before.Samuel Tulach

1 Answers

1
votes

Based on Roman R. comment I figured out this solution:

    var enumerator = new MMDeviceEnumerator();
    var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);

    while (true)
    {
        for (int i = 0;i< device.AudioMeterInformation.PeakValues.Count;i++)
        {
            Console.WriteLine("ID: " + i + " : " + device.AudioMeterInformation.PeakValues[i]);
        }
    }