This project has moved. For the latest updates, please go here.

How to read in from a two channels Microhone

Feb 6, 2014 at 3:35 PM
ok right now i have a Microphone Array ( IDT High Definition Audio CODEC) with 2 channels and I am pull data from both channels
int deviceNumber = 0;
            waveIn = new WaveIn();
            waveIn.BufferMilliseconds = 250;
            waveIn.DeviceNumber = deviceNumber;
            waveIn.DataAvailable += waveIn_DataAvailable;
            waveIn.WaveFormat = new WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
I get back 44100 Bytes Recorded at a time. Now I only need 65536 Bytes to pass to my fft, The data is in 16 bit samples so convert them
and there are some negative numbers so I do this :
 byte[] buffer = e.Buffer;
            int bytesRecorded = e.BytesRecorded;
            points = new RollingPointPairList(32768/2);
            buffer1 = new double[(32768/2)];
            int tempint = 0;
            for (int index = 0; index < 32768; index += 2)

                buffer1[tempint] = ((buffer[index + 1] << 8) |
                                      buffer[index + 0]);
                if (buffer1[tempint] > 32767)
                    buffer1[tempint] = buffer1[tempint] - 65536;



is that the right way to read from two channels and pass it to a FFT?
I am reading from both the channels right?
is there anything I am missing ? or I should add to make this work better ?
Feb 7, 2014 at 2:59 AM
ok i just turn my array mic setting down to 0
and I am still reading in values
how can that be?
Feb 7, 2014 at 2:36 PM
I dont understand why your FFT requires 65536 bytes, it seems very excessive. It should be 2048 floats/samples (1024 per channel).

Are you sending the FFT data to a spectrum analyser?

spectrum analysers only need 2048 FFT floats every 100ms to draw a smooth animation.

You should really use a Sample Aggregator to collect the samples and tell it to send the data 10 times a second. The Aggregator may look complex at first but believe me its quite simple and the best way to do it. At least give it a try.
Feb 7, 2014 at 2:57 PM

my fft requires 2^samples, I only pick 65536 bytes because the more samples you have the better your fft works, right>

I am outputting the information to a graph

check out these
youtube vid:

this is my program I have...

so does my code look right to you?
Feb 7, 2014 at 3:17 PM
Edited Feb 7, 2014 at 3:53 PM
It looks like that graph only updates every 250ms so you only need a snapshot of the audio every quarter of a second.

The SampleAggregator will collect (or cycle over) the samples, then calculate and send the current snapshot to the graph when needed.

That graph appears to need around 2048 float of FFT data. Calculating the FFT on absolutely all the samples would be redundant
Feb 12, 2014 at 4:57 PM
I tried to drop the simple down to 2048 and the FFT is now not get as close to the right frequency as it was before
Feb 13, 2014 at 7:59 AM
Take a bigger snapshot until you are happy with the frequency detail. 4096, 8192 etc..