Arduino Audio recording to get RAW data

Hey guys, I'm looking for a way to record audio using a microphone and get its numeric RAW data. I don't wish to save it in an SD card or anything like that. Just get the numeric data. Are there any shields available that I can use? I want to record in 8KHz rate, mono and 1024 buffer size. Or is it possible through the use of Analog pins? If so, what is the general code that I can use? Please help me out! Thanks!!

and get its numeric RAW data.

What does that mean? If you read, periodically, the ADC that the microphone is connected to, you get data. It isn't RAW or cooked. It's data.

1/8000 = 125microseconds

int x = 0;
int dataArray[1000];
unsigned long currentMicros;
unsigned long period = 125;
unsigned long previousMicros;
byte running = 0;
void setup(){
Serial.begin(9600);

}
void loop(){
if ((digitalRead(startButton) == LOW) && running == 0){
running = 1;
currentMicros = micros(); // initialize time count
previousMicros = currentMicros;
}
if ( (running ==1) &&  (currentMicros - previousMicros) >= period){
previousMicros = previousMicros + period; // set up for next time check
dataArray[x] = analogRead(A0); // sample & save
x=x+1; // set up for next location
if (x==1000){
running = 0;
Serial.println("Done");
} // stop running
} // sample on time check
} // button check or running
} // end of loop

There you go, 1000 samples at 8 KHz rate. Or pretty close at least, I haven't tried compiling.
This will probably crash an Uno (or any '328P board), as you are saving 2000 bytes of data on a microcontroller which only has 2048 bytes of SRAM. Best bet, use a '1284P board with 16K of SRAM, or a Mega(2560) with 8K of SRAM.
http://www.crossroadsfencing.com/BobuinoRev17/

Thank you!! It was what I was looking for! As for the board I'm using, Its either a Mega 2560 or an Intel Galileo gen 1. So I think it should be fine. Does simply connecting the 3.5 mm jack leads to analog pin and ground pin in the board work for recording audio from microphone? Or should I have a circuit for this?

Ok That will not work in a Galileo because the A/D is way too slow, it is a crap board.

You will need an amplifier on the microphone to get the signal high enough to get any real data. The input also needs basing at 2.5v as well.

Oh, so its better to use a Mega then, which I do have luckily. I guess an RC circuit is best for amplifying the Mic output. I do have an adapter for a 3.5mm jack that does all of this but it needs a USB port. Dunno if Mega supports a USB port input.

I guess an RC circuit is best for amplifying the Mic output.

No you need an op-amp or some sort of transistor amplifier.

Dunno if Mega supports a USB port input.

It doesn't.

Just found my measurements of the Galileo analogue speed test I did:-
Galileo 1000 readings in 7.5 seconds! So that is a sample rate of 133Hz.

I see! Thanks for the info! So I have to go with the Mega only then. But one final thing. Is there like a USB shield for arduino that supports USB input indirectly? I did remember seeing a usb port in the Mega but that must be for outputs

EDIT: I saw a project where a person has used an electret microphone to do some voice recognition. Think this'll work in my case? Here's the link.

http://www.instructables.com/id/Speech-Recognition-with-Arduino/

Think this'll work in my case?

That carries the warning word instructables. This is code for a useless pile of crap written by some one with an over inflated opinion of their ability.

That microphone module must contain an amplifier and a bias circuit. Have you got one of those?

I don't have one ready made, but I believe I can build a simple op-amp and a bias circuit. As for the code, I plan to use analogRead to accept 1024 samples at the rate of 8000Hz, ie every 125 microseconds, as CrossRoads pointed out.

I don't have one ready made, but I believe I can build a simple op-amp and a bias circuit.

Then that should be OK then.

I didn't understand one other thing. I'n not familiar with DSP so I got confused here. 8000 Hz means 8000 samples per second right? which means an audio sample is taken every 125 Microseconds like CrossRoads pointed out. SO If we want 1024 samples, it makes sense to record for 125 * 1024 = 128,000 microseconds or 128 milliseconds. So how is it that when I use programs like audacity or matlab audiorecorder to record audio for 1 second at 8000 Hz rate, I still get 1024 samples recorded at 8000 Hz rate?

So how is it that when I use programs like audacity or matlab audiorecorder to record audio for 1 second at 8000 Hz rate, I still get 1024 samples recorded at 8000 Hz rate?

They lie or you are missing something like the header bytes in a file format.
How have you done this test to find out?
If it is on file size from the computer they often round up to the nearest K.

Ok sorry for the ambiguity. So basically, The sample rate, being 8000 Hz, the number of samples, being 1024 by default, and finally, the number of bits, which in my case is 16 bit. The output is double array with 1024 elements. Obviously the number of channels I'm using is 1. I can also change data type of output. Now, Even if I record an audio for 5 seconds, the array still has only 1024 elements, ie to say, 1024 samples.

Even if I record an audio for 5 seconds, the array still has only 1024 elements, ie to say, 1024 samples.

With what application? On what system. If it is the Mega then please post your code.
How do you know the array has only 1024 elements in it?

It's not using Arduino, but using MATLAB. When I record in MATLAB, it has those 1024 elements. Basically the whole point of all this was a speech recognition algorithm using only an electret microphone and arduino. I had the algorithm in MATLAB, so I was trying a similar approach in arduino. I just want to be able to differentiate between 4-5 commands to control motors using this electret mic.

So it is not an Arduino question but a MatLab one. I suggest you ask on a MatLab forum for this.