QuantumStarted gives me random blocks of zero memory

Gareth Williams 41 Reputation points
2020-04-02T15:53:36.24+00:00

Using AudioGraph with a CreateFileInputNodeAsync and CreateFrameOutputNode.
This is to allow me to open an audio file and extract the PCM data.
This is for waveform display.
This is kind of working.
But I am getting random blocks of zero memory given to me in the QuantumStarted event handler.
I can process the same audio file twice and get slightly different binary data.
Where the data differs there appears to be a load of zeros given to me.
But examining the binary data between two successive runs I can see where the differences start to happen the actual data is then given to me afterwards.
So the data is there - it's not missing.
It's as if the graph has given me a bunch of extra zero bytes.
Anyone come across this?
Any why is it happening?
It seems random but appears timing related.
If I add deliberate delay into the handler - to slow things down - I get less or no blocks of extra zeroes at all.

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Richard Zhang-MSFT 6,936 Reputation points
    2020-04-15T08:01:13.293+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Sorry for the late reply, the engineer has analyzed the sample code you provided, this is the test result and some suggestions:

    The issue is due to how AudioGraph works and that it may not be thread safe.

    It seems that the second call to load the waveform data starts before the first one really completes. If I force the Audio file to play back in real time by adding an AudioDeviceOutputNode and connecting the input node to it, then the samples match and the behavior is as expected.

    Sample code added to audio_waveform class in the load_waveform method after the AudioFrameOutputNode is connected to the AudioFileInputNode (audio_file_input_node.AddOutgoingConnection(audio_frame_output_node);):

    public async Task<int> load_waveform(StorageFile file)  
    {  
        ...  
      
        audio_file_input_node.AddOutgoingConnection(audio_frame_output_node);  
      
        // add  
        CreateAudioDeviceOutputNodeResult adonResult = await audio_graph.CreateDeviceOutputNodeAsync();  
        if (AudioDeviceNodeCreationStatus.Success != adonResult.Status)  
        {  
            audio_graph = null;  
            return -2;  
        }  
        AudioDeviceOutputNode outputNode = adonResult.DeviceOutputNode;  
        audio_file_input_node.AddOutgoingConnection(outputNode);  
      
        ...  
    }  
    

    If you want to extract waveform data, then AudioGraph's related API may not be the best choice, its purpose is to play audio and mix multiple sources, etc.

    You can try WASAPI, it may be more helpful:

    And look in the PlotData.h file for an example of plotting wave form data.

    If you have any questions, feel free to ask.

    Thanks.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Gareth Williams 41 Reputation points
    2020-04-15T09:22:50.677+00:00

    Thank you for taking the time and looking into this for me. I will investigate wasapi for this purpose.

    0 comments No comments