0

I'm using NAudio and ASIO to play a sequence of wav files. I need to use ASIO because the audio card supports only that. I was able to play each wav in this way:

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

Now I need to insert 1 second of silent before the starting of the wav. The only way I found is to use an OffsetSampleProvider, but if I do like this

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

The first wav plays just fine, but as soon as I stop() the waveOutDevice or I try to reinstantiate a new one the execution of the program stops at that position with

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

I'm not able to understand why. Please help. Thanks

nikez
  • 11
  • 2

1 Answers1

0

with ASIO, it is better to just open the output device once, leave it playing and then change its input. You could for example add and remove items from a MixingSampleProvider used as input.

Mark Heath
  • 48,273
  • 29
  • 137
  • 194