question

GarethWilliams-0328 avatar image
0 Votes"
GarethWilliams-0328 asked ·

QuantumStarted gives me random blocks of zero memory

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.


windows-uwpwindows-uwp-runtime
· 5
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, can you provide a minimum runnable demo so we can analyze your problem? It's hard to locate where the issue is. This might be related to the AudioGraph class. But I need to sample to test so that I can confirm it.

0 Votes 0 ·

Hello
Yes I have put together a minimal project showing this.
It's a 500KB zip but forum won't let me attach it to this message.
How can I get it to you?

0 Votes 0 ·

I also have a little more info on this too.
I think I have two different issues.
One is in accurately knowing when the audio graph is completed.
I am currently using FileCompleted event to stop the graph - but I wonder if this is racing at the end with the QuantumStarted event and so I don't get all of the samples? It's always a few thousand samples different on length.

Secondly I do get corrupt data from successive runs on the samples I do receive.
The app demo I put together allows you to select a file.
It loads the waveform twice and compares what it has.
I never see issues between samples received with wav files.
But with w4a files I do see issues.
Some times it passes the checks and sometimes not.
Maybe it's a codec issue?
I haven't tried other formats yet.

0 Votes 0 ·

Also the music file should be a usual music track, a few minutes long. I haven't tried with shorter or longer tracks.

0 Votes 0 ·
RichardZhang-MSFT avatar image
0 Votes"
RichardZhang-MSFT answered ·

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.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GarethWilliams-0328 avatar image
0 Votes"
GarethWilliams-0328 answered ·

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

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.