简体   繁体   中英

Naudio Asio Record and Playback simultaneously on multiple channels

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.

https://stackoverflow.com/questions/22543513/naudio-using-asio-to-record-audio-and-output-with-a-guitar

NAudio Asio Record and Playback

How to record and playback with NAudio using AsioOut

NAudio AsioOut + Sockets

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!!

这是我创建的一个简单示例 ,它同时访问输入和输出ASIO缓冲区并执行样本的低级操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM