Routing AudioFileInputNode to AudioFileOutputNode

Apr 28, 2016 at 6:38 PM
I'm trying to mix two wave files using AudioGraph api in UWP. I've created the following code which opens two already recorded wave files, creates one AudioGraph, one AudioSubmixNode, two AudioFileInputNode and one AudioFileOutputNode object.

I call graph.Start() to make the graph mix two files and store them into the AudioFileOutputNode. However, what happens is that the AudioGraph never stops and keep expanding the output file. I left it running for a while and the end file became something like 1.1GB!

I tried handling the QuantumProcessed event of the AudioGraph and I noticed that this event gets called endlessly after calling graph.start(). I tried stopping the graph in this event but the event gets called again and again and the end result is not playable and the end result file size is way less than the input files.

I was wondering to ask if anybody could help to resolve this problem please.

Many thanks.
        AudioGraphSettings setting;
        AudioGraph graph;
        AudioFileInputNode input1;
        AudioFileInputNode input2;
        AudioFileOutputNode output;
        AudioSubmixNode submix;

        IStorageFile musicFile1 = await folder.GetFileAsync("1.wav");
        IStorageFile musicFile2 = await folder.GetFileAsync("2.wav");
        IStorageFile finalFile = await folder.CreateFileAsync("Final.wav", CreationCollisionOption.ReplaceExisting);

        setting = new AudioGraphSettings(Windows.Media.Render.AudioRenderCategory.Media);
        CreateAudioGraphResult graphResult = await AudioGraph.CreateAsync(setting);
        graph = graphResult.Graph;

        CreateAudioFileInputNodeResult inputResult1 = await graph.CreateFileInputNodeAsync(musicFile1);
        CreateAudioFileInputNodeResult inputResult2 = await graph.CreateFileInputNodeAsync(musicFile2);
        CreateAudioFileOutputNodeResult outputResult = await graph.CreateFileOutputNodeAsync(finalFile);

        input1 = inputResult1.FileInputNode;
        input2 = inputResult2.FileInputNode;
        output = outputResult.FileOutputNode;

        submix = graph.CreateSubmixNode();
        input1.AddOutgoingConnection(submix);
        input2.AddOutgoingConnection(submix);
        submix.AddOutgoingConnection(output);

        graph.Start();