0

tl;dr I want to put data from asio_DataAvailable(object sender, AsioAudioAvailableEventArgs e) event into a BufferedWaveProvider and play them back.

Hello,

I am trying to make an app, which will record audio to a file, but also play it back to the user while recording. I managed to do it using WaveInEvent and WaveOutEvent and a BufferedWaveProvider. But I thought that ASIO would have a better latency, so I wanted to do the same thing using it.

I found questions here on this topic, but none of them contained a complete answer and I couldn't work it out based on them. Could you please post a complete working example of the code?

NAudio Asio Record and Playback

How to record and playback with NAudio using AsioOut

I tried the version with Marshal.Copy, but got IndexOutOfRangeException. The buffers (e.InputBuffers[i]) seems to not have enough samples. I also want to work with the audio further (save it to a file) and at the same time play another audio (using MixingSampleProvider), so just simple copying the buffers probably doesn't work for me.

Mnaukal
  • 36
  • 1
  • 5

1 Answers1

0

The ASIO driver model is based on a single callback where you can access the recorded buffers and write to the playback buffers. This is great for super low latency playback, but the InputBuffers are just IntPtrs to a block unmanaged memory for each channel. So the size of that array is the number of input channels, not the number of samples. You will need to know a fair bit about pointer dereferencing and bit manipulation to successfully use them as ASIO supports multiple different bit depths and sample formats, and you have to use the correct one if you are wanting to access low-level audio like this.

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