2017-02-26 139 views
0

我正在使用NAudio和ASIO播放一系列wav文件。我需要使用ASIO,因爲音頻卡僅支持該功能。我能夠以這種方式播放每個wav:NAudio ASIO播放wav

 waveRead = new WaveFileReader(completeStreamMS); //completeStreamMS is a memorystream 
    waveRead.Position = 0; 
    pcm = new WaveChannel32(waveRead); 
    reductionStream = new BlockAlignReductionStream(pcm); 
    reductionStream.Position = 0; 
    waveOutDevice.Init(reductionStream); 
    waveOutDevice.Play(); 

現在我需要在wav開始之前插入1秒的無聲。我發現的唯一方法是使用一個OffsetSampleProvider,但如果我不喜歡這個

 ISampleProvider isp = WaveExtensionMethods.ToSampleProvider(waveRead); 
    var offset = new SampleProviders.OffsetSampleProvider(isp); 
    offset.DelayBy = TimeSpan.FromSeconds(1); 
    var wp = new SampleProviders.SampleToWaveProvider(offset); 
    waveOutDevice.Init(wp);` 
    waveOutDevice.Play(); 

第一WAV發揮就好了,但只要我停止()的waveOutDevice或我試着重新實例一個新的程序執行停止在該位置

System.ExecutionEngineException 
Cannot intercept exception. Debugged program can not be continued and properties can not be evaluated. 

我無法理解爲什麼。請幫忙。 謝謝

回答

0

與ASIO,最好打開輸出設備一次,讓它播放,然後改變它的輸入。例如,您可以添加和刪除用作輸入的MixingSampleProvider中的項目。