Example VU Meter using Windows Media Graph API?

时间:2016-11-09 08:29:45

标签: c# uwp windows-10

The question says it all. I would like to create the simplest possible VU-meter example, using the new UWP Media Graph API, but so far, I haven't found any good examples.

There are a couple of questions in this:

  1. I am using the "normal" code to enumerate my microphones:

    var deviceInformation = await DeviceInformation.FindAllAsync(MediaDevice.GetAudioCaptureSelector());
    

However, when I create an AudioGraphSettings object, I cannot find a property to pass the device found. There is a property named DesiredRenderDeviceAudioProcessing however, I'm not sure I understand it's purpose.

  1. Following the best examples I've found, I proceed to create a graph, and use that to get an InputNode as such:

    var creationResult = await AudioGraph.CreateAsync(settings);
    
    if (creationResult.Status != AudioGraphCreationStatus.Success)
        return;
    
    _graph = creationResult.Graph;
    
    var inputNodeCreationResult = await _graph.CreateDeviceInputNodeAsync(Windows.Media.Capture.MediaCategory.Media);
    
    if (inputNodeCreationResult.Status != AudioDeviceNodeCreationStatus.Success)
    {
        DestroyGraph();
        return;
    }
    
    _inputNode = inputNodeCreationResult.DeviceInputNode;
    

From here on, I'm running blind. Not finding any good tutorials, examples or documentation to help me.

I am only interested in sound level (dB), not the waveform. Is there anyone that can help me complete this, or point me to some decent documentation?

1 个答案:

答案 0 :(得分:1)

"场景2:设备捕获"来自Windows Universal Samples - Audio Creation项目应提供一些指导。从您的代码看起来您​​似乎正在进行中。可能只是添加以下内容:

_frameOutputNode = _graph.CreateFrameOutputNode();
_frameOutputNode.Start();

_graph.QuantumProcessed += Graph_QuantumProcessed;
_graph.Start();  

并使用Graph_QuantumProcessed回调分析对AudioFrame的调用所提供的_frameOutputNode.GetFrame()

希望它有所帮助。