0

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;
  }
user397232
  • 1,750
  • 6
  • 21
  • 30
  • 1
    How is gNumSamples used? maybe the application considers a 'Sample' to be 4 words of data? – luke Jun 22 '10 at 03:16

1 Answers1

0

I just came across this question when looking for nesC. Just answering it for whatever it's worth.

If you look at the audioRecord function, they are multiplying numSamples by 4 to compensate for the division by 4 (BUFFERLEN/4) earlier. Without the full context, I cannot tell why they have to divide it in the first place. My guess would be gBuffer is divided into 4 parts, each part storing numSamples, so when the producer is writing to one part, the consumer can read from another part.

user330167
  • 156
  • 6