This is the code from TestAVBoardM.nc file in nesC language:
#define BUFFERLEN 32768
uint32_t gBuffer[BUFFERLEN] __attribute__((aligned(32)));
uint32_t gNumSamples = BUFFERLEN/4;
event void Audio.ready(result_t success)
{
call Audio.audioRecord(gBuffer,gNumSamples));
return;
}
The buffer gBuffer is used to store sound recording samples. Samples are 16-bit stereo samples packed into a 32-bit word. Left samples are in the low 16 bits. Right samples are in the high 16 bits.
What makes me confused is the number of samples gNumSamples. As I understand, gNumSamples should be BUFFERLEN since gBuffer[i] is 32-bit word (16 bits for left channel + 16 for right channel). Am I right? (I changed gNumSamples = BUFFERLEN
and it didn't work).
Thanks for your help.
This is how gBuffer is used:
command result_t Audio.audioRecord(uint32_t *buffer, uint32_t numSamples){
uint32_t *pBuf;
uint32_t bufpos;
bool initPlay;
atomic{
initPlay = gInitPlay;
}
if(initPlay == TRUE){
//gate the acceptance of a record command until we signal audio.ready();
return FAIL;
}
atomic{
pBuf = gRxBuffer;
bufpos = gRxBufferPos;
}
if( (bufpos != 0) || (pBuf != NULL)){
//gate acceptance due to ongoing record command
return FAIL;
}
atomic{
gRxBuffer = buffer;
gRxBufferPos = 0;
gRxNumBytes = numSamples * 4;
}
call BulkTxRx.BulkReceive((uint8_t *)buffer, ((numSamples*4) > 8188)? 8188: (numSamples*4));
return SUCCESS;
}