【问题标题】:Mixing wave files using AudioGraph (UWP)使用 AudioGraph (UWP) 混合波形文件
【发布时间】:2016-05-16 21:45:17
【问题描述】:

我正在尝试在 UWP 中使用 AudioGraph api 混合两个波形文件。我创建了以下代码,它打开了两个已录制的波形文件,创建了一个 AudioGraph、一个 AudioSubmixNode、两个 AudioFileInputNode 和一个 AudioFileOutputNode 对象。

我调用 graph.Start() 来使图混合两个文件并将它们存储到 AudioFileOutputNode 中。但是,发生的情况是 AudioGraph 永远不会停止并继续扩展输出文件。我让它运行了一段时间,最终文件变成了大约 1.1GB,直到我关闭了应用程序!

我尝试处理 AudioGraph 的 QuantumProcessed 事件,我注意到该事件在调用 graph.start() 后被无休止地调用。我尝试在此事件中停止图表,但该事件被一次又一次地调用,最终结果文件变得越来越大。

我想问是否有人可以帮助解决这个问题。

非常感谢。

        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();

编辑:源波形文件具有相同的长度(这无关紧要)、相同的比特率并且都有两个通道。

【问题讨论】:

  • 有一个样本AudioGraph sample,我测试它很好用。
  • @JaydenGu 嗨,Jayden,感谢您的回复。我仔细研究了这个示例,但没有一个场景是关于将 AudioFileInputNode 路由到 AudioFileOutputNode。

标签: c# audio win-universal-app windows-10-universal


【解决方案1】:

感谢 Mike Taulty,我终于修复了它。请看下面的解决方案:

  this.remainingFiles = 2;
  this.input1.FileCompleted += OnFileCompleted;
  this.input2.FileCompleted += OnFileCompleted;

然后我们处理 OnFileCompleted 如下:

async void OnFileCompleted(AudioFileInputNode sender, object args)
{
  if(--this.remainingFiles == 0)
  {
    this.graph.Stop();
    await this.output.FinalizeAsync();
    this.graph.Dispose();
  }
}

但是,请注意此事件处理程序中的线程安全措施。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-23
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    相关资源
    最近更新 更多