Reading Samples from Mic Input

Status
Not open for further replies.

snirtikam

Member
I'm trying to read samples from mic with audio shield. I'm using readBuffer() to do so, but the data that is displayed for each sample of 128 bit array doesnt make any sense to me. If i'm reading from microphone then shouldn't the sampled data be random? I've posted my code below and the Serial monitor capture of what i'm getting. Any help would be appreciated on what i'm doing wrong. Thank you!

serial output:
dataOut.JPG

my code:

//
// Microphone to Speaker output

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>


// GUItool: begin automatically generated code
AudioInputI2S Mic; //microphone
AudioRecordQueue MicMem; //queue for microphone
AudioOutputI2S headphones; //output
AudioConnection patchCord1(Mic, 0, MicMem, 0);
AudioConnection patchCord2(Mic, 0, headphones,0);
AudioConnection patchCord3(Mic, 0, headphones,1);
AudioControlSGTL5000 sgtl5000_1; //xy=339.6666564941406,285.6666488647461
// GUItool: end automatically generated code
int16_t data1[128];


const int micInput = AUDIO_INPUT_MIC;

void setup() {
Serial.begin(9600);
AudioMemory(20);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
sgtl5000_1.inputSelect(micInput);
sgtl5000_1.micGain(36);
delay(1000);
}

void loop() {
MicMem.begin();
int16_t *data = MicMem.readBuffer();

for(int i = 0; i < 128; i++) {
Serial.println(data);
}
MicMem.freeBuffer(); // do not use "data" after this!
MicMem.end();
delay(500);
}
 
- Please use code tags next time, without indention your code is difficult to read.
- There is an example "Audio/Recorder" under "Examples" which shows you the correct usage of AudioRecordQueue.
 
Your code isn't checking for readBuffer() to return NULL, which it does until data is actually available.

Then your code is reading whatever data happens to be present at address zero, which is the ARM exception and interrupt vector table in flash memory. Since your program is fairly small, the 32 addresses are all zeros in the upper 16 bits, which is why you're seeing half the data as zeros. Most of the vector table is populated with the address of an "unused" default handler function, which is why you're seeing the same number repeated.
 
Thank you for the input; it really helped. I was able to get the data that I need and manipulate it. So, now I filled the sampled data into 512 int16_t array, how can I take this array and play it on speaker, or send it to DAC. I've been looking though examples and "simpleplayer" has a "play(data)" object, but that wont play the array that I have. How can I accomplish that? Thank you!
 
Status
Not open for further replies.
Back
Top