NAudio AudioMeterInformation仅在"控制mmsys.cpl声音"开了

时间:2017-02-08 21:15:55

标签: c# wpf naudio

我试图捕捉MIC(DataFlow.Capture)的声音,但AudioMeterInformation.PeakValues仅在声音属性打开时有效(控制mmsys.cpl声音)

工作示例

Working

但当我关闭声音属性时..

Not working

我的代码

    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);
        }

    }

我在结果上使用了(-100),因为我的进度条被反转(黑色实际上是进度)

DataFlow.Render工作正常,即使没有打开属性。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。我必须在构造函数上放置WaveInEvent以启用设备。

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

现在,它正在发挥作用。