This project has moved and is read-only. For the latest updates, please go here.

Four channel audio INPUT

Feb 17, 2012 at 3:08 PM

I am trying to capture four channels of audio from an Alesis io4 four channel sound card. I am desperately trying to find some examples of how to do this but all I can find are examples of multi-channel output, which does not seem relevant to me. any help would be greatly appreciated!



Feb 17, 2012 at 3:16 PM

I'm not sure you'll be able to do this with NAudio until we implement ASIO recording I'm afraid. Have you tried WaveIn with 4 channels?

Feb 17, 2012 at 3:42 PM
Edited Feb 17, 2012 at 3:44 PM

thanks mark. what i have tried is this:

(if channels are 2 it works but not with 4)

int channels = 4;

WaveIn waveInStream = new WaveIn();

waveInStream.DeviceNumber = 0;       //this is my device - WaveIn.GetCapabilities(0).Channels == 2  

waveInStream.WaveFormat = new WaveFormat(waveInStream.WaveFormat.SampleRate, channels); //works only when channel is 2

waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);

Feb 17, 2012 at 3:46 PM

yes, they don't tend to bother making the waveIn and waveOut drivers suport multi-channel. You could try WasapiIn if you are on Windows Vista or 7

Feb 17, 2012 at 4:08 PM

could you elaborate or point me to an example. i can't find any reference to WasapiIn. which name space is this part of?

Feb 17, 2012 at 4:10 PM

NAudio.CoreAudioApi.WasapiCapture might work for you

Feb 17, 2012 at 4:52 PM

ok great thanks, so far so good. that seems to start and it's indicating four channel audio!

next issue: the encoding is WaveFormatEncoding.Extensible

in my DataAvailable handler i'd like to decode this into samples for each of the four channels. is there an easy way to do this?

Feb 17, 2012 at 4:54 PM

BitConverter class is probably best. What bit depth is it recording at?

Feb 17, 2012 at 5:02 PM

bits per sample: 32

extra size: 22

channels: 4

i was expecting 4x16 bits - so not quite sure how to unpack this? assume it's not just interleaved in a simple way?

Feb 17, 2012 at 5:07 PM

yes they will be interleaved, but it looks like integers. BitConverter.ToInt32(buffer, offset) will do it

Feb 20, 2012 at 4:09 PM
Edited Feb 20, 2012 at 4:15 PM

i am struggling to decode the data stream. it certainly seems to have 4 bytes per chunk. however, when i convert this using the bitconverter method as you describe i get very large numbers even on channel with no input. so i suspect it might by byte ordering. this is a sample of the first 8 bytes in the data:

//ch1 - signal input

data[0] 0

data[1] 0

data[2] 64

data[3] 185

//ch2 - no signal input
data[4] 0

data[5] 0

data[6] 0

data[7] 184

//ch3.&4 like ch2


is it possible this is stored as bigendian? as that would make  more sense to then!

Feb 20, 2012 at 5:51 PM
Edited Feb 20, 2012 at 6:01 PM

i think i solved the issue with byte order - it does indeed seem to be big endian.

but  another question on this - i am handling the DataAvailable event obviously to get my information. all i need is amplitude and i'd like to determine this with as little latency as possible. at the moment this event isn't being called very often. is there a way to get this more often with less data?

btw - as i don't need an output (to the souncard or a file) ive just started capture by calling wasapiIn.StartRecording(); this seems to work fine.

Feb 25, 2012 at 3:48 PM

Please could you provide me your code for initialisation ?

I try to use the MAYA44 Soundcard with 4 channels, but no success.