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.