NAudio AudioMeterInformation works only if “control mmsys.cpl sounds” is open

醉酒当歌 提交于 2019-12-12 03:55:42

问题


I'm trying to capture the sound of MIC (DataFlow.Capture), but AudioMeterInformation.PeakValues only works if sound properties is open (control mmsys.cpl sounds)

Working example

But when i close sound properties..

My code

    private void calculateChannels(Object source, ElapsedEventArgs e)
    {
        dev = devEnum.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia);

        try
        {
            double currentLeftChannel = 100 - (dev.AudioMeterInformation.PeakValues[0] * 100);
            double currentRightChannel = 100 - (dev.AudioMeterInformation.PeakValues[1] * 100);

            // this function just "smooth" the progress bar
            this.leftChannel = round(this.leftChannel, currentLeftChannel);
            this.rightChannel = round(this.rightChannel, currentRightChannel);

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }

    }

I'm used (-100) on the result because my progress bar is inverted (black colors are actually the progress)

DataFlow.Render is working fine, even without properties open.

How can I fix this?


回答1:


I found the solution. I had to put WaveInEvent on my constructor to enable the device.

waveInStream = new WaveInEvent();
waveInStream.WaveFormat = new WaveFormat(44100, 1);
waveInStream.StartRecording();

Now, It is working.



来源:https://stackoverflow.com/questions/42123754/naudio-audiometerinformation-works-only-if-control-mmsys-cpl-sounds-is-open

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!