audio board and byte manipulation

Status
Not open for further replies.

eldecog

New member
Hello World,

I would like to manipulate the values from AUDIO_INPUT_LINEIN.
I use memcpy(buffer, queue1.readBuffer(), 256) to read the values and store them to a byte called buffer.
But the values are not byte(8 bits) but int16.
I have to combine them somehow.
I use this command to do it : intValeurR = (buffer[i+1] << 8) | buffer;
but it doesn't work.

My question is simple: how to get the integer 16 values from AUDIO_INPUT_LINEIN on the audio board in order to manipulate them the way I want in my program ?

Thank you all
 
Just create buffer as an array of int16_t.

Code:
int16_t buffer[128];

Then you can access the samples directly from the array. Easy!
 
Thanks a lot Paul!!
Then I think my problem is something else because for both input, left and right I get the same value, and those values don't seems to be right. never change and both the same.
This is my code:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>

// GUItool: begin automatically generated code
AudioControlSGTL5000 sgtl5000_1;
AudioInputI2S i2s1; //xy=223,143
AudioRecordQueue fileL; //xy=632,116
AudioRecordQueue fileR; //xy=650,182
AudioConnection patchCord1(i2s1, 0, fileL, 0);
AudioConnection patchCord2(i2s1, 1, fileR, 0);
// GUItool: end automatically generated code

// which input on the audio shield will be used?
const int myInput = AUDIO_INPUT_LINEIN;
//Permet de stocker le temps en ms et savoir où on en est.
unsigned long ulngTime;

void setup() {
AudioMemory(60);
pinMode(13, OUTPUT);

//Enable the audio shield
sgtl5000_1.enable();
sgtl5000_1.inputSelect(myInput);
}

void loop(){
int16_t bufferL[128];
int16_t bufferR[128];

memcpy(bufferL, fileL.readBuffer(), 128);
fileL.freeBuffer();
memcpy(bufferR, fileR.readBuffer(), 128);
fileR.freeBuffer();

for (int i=0;i<128;i++){
Serial.println(bufferR);
delay(1);
}
}
 
Ok I found my error it was very simple after have read the doc :/
I had to add this line in setup :
fileR.begin();
of course
 
You should also call available() and only attempt to read when it tell you 1 or more buffers are actually waiting in the queue for you.
 
Status
Not open for further replies.
Back
Top