I have an usb audio board that supports asio driver with 4 inputs and 4 outputs. I want to send and receive data simultaneously. But currently I can receive and send data only to one channels at a time. I cannot figure out how to set it in asioOut class from Naudio c# library.
It is possible to have one AudioAvailable event for each channel? Similar to waveIn / waveOut classes. How can I achive this?
Here is my code:
int sampleRate = 44100;
int channels = 4;
buffWaveProvider = new BufferedWaveProvider(new NAudio.Wave.WaveFormat(sampleRate, 32, channels));
asioOut = new AsioOut(radioForm.driverName);
asioOut.ChannelOffset = OUTdevID;
asioOut.InputChannelOffset = INdevId;
asioOut.AudioAvailable += OnAsioOutAudioAvailable;
asioOut.InitRecordAndPlayback(buffWaveProvider, channels, sampleRate);
asioOut.Play();
for AudioAvailable event I have to send for each input channel the inputstream on different multicast address:
public void OnAsioOutAudioAvailable(object sender, AsioAudioAvailableEventArgs e)
{
if (speakersOn && e.InputBuffers.Length != 0 && !monitorRequest)
{
byte[] buf = new byte[e.SamplesPerBuffer*4];
for (int i = 0; i < e.InputBuffers.Length; i++)
{
Marshal.Copy(e.InputBuffers[i], buf, 0, e.SamplesPerBuffer*4);
}
e.WrittenToOutputBuffers = true;
udp4VoiceSend.Send(buf, buf.Length);
}
}
Is there a way to access input buffers for each channel?
For the outputs I've checked the naudio source code and I saw I can set the number of output channels to waveProvider.WaveFormat.Channels. So I suppose that when calling InitRecordAndPlayback method the IWaveProvider buffer should have 4 channels.
None of stackoverflow post about this subject helped me. I've tried them all.
NAudio Asio Record and Playback
How to record and playback with NAudio using AsioOut
Thanks!
UPDATE:
I've checked the Naudio Demo Project, Asio Recording Panel and seems that I can listen to only one channel at a time:
The naudio driver class creates 4 input and 4 output buffers as expected, but I'm not able to access them.
In AsioRecordingPanel file if asioOut object listens to 1 channel and user wants to change channel the object is disposed.
Is a library limitation or a driver limitation?
When I add samples to asio buffer it's possible to send data directly to an output channel?
if (Main.buffWaveProvider != null)
Main.buffWaveProvider.AddSamples(data, 0, dataLen);
Thanks!!