nesC(类C)问题
这是来自 TestAVBoardM.nc nesC语言文件:
#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;
}
缓冲区gBuffer用于存储录音样本。样本是打包到 32 位字中的 16 位立体声样本。左侧样本位于低 16 位。正确的样本位于高 16 位。
让我困惑的是样本数量gNumSamples。据我了解,gNumSamples 应该是 BUFFERLEN,因为 gBuffer[i] 是 32 位字(左通道 16 位 + 右通道 16 位)。我说得对吗? (我更改了gNumSamples = BUFFERLEN
,但它不起作用)。
感谢您的帮助。
gBuffer 的使用方式如下:
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚在寻找nesC时遇到了这个问题。只是回答它的价值。
如果您查看 audioRecord 函数,您会发现它们将 numSamples 乘以 4,以补偿之前除以 4 (BUFFERLEN/4) 的情况。如果没有完整的上下文,我无法解释为什么他们必须首先划分它。我的猜测是 gBuffer 分为 4 个部分,每个部分存储 numSamples,因此当生产者写入一个部分时,消费者可以从另一部分读取。
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.