【发布时间】:2013-08-25 20:49:15
【问题描述】:
如标题所示,我需要从 char 缓冲区中读取短整数
缓冲区
uint8_t *data[AV_NUM_DATA_POINTERS]
这是AVFrame frame结构的一个字段,由对ffmpeg函数的调用填充
avcodec_decode_audio4(avctx,frame,got_frame_ptr,avpkt)
但是,我需要将此缓冲区读取为有符号 16 位整数的缓冲区,因为这是编解码器上下文指示的示例格式 avctx->sample_fmt==AV_SAMPLE_FMT_S16
我尝试使用 memcpy 来执行此操作,但我没有成功获得合理的值,因此我尝试按照 StackOverflow 中一些相关问题的建议使用联合结构。我的代码如下: 联合 CharToStruct{ uint8_t myCharArray[2]; 短期价值; } 呈现声音;
audioRet=avcodec_decode_audio4(avctx,frame,got_frame_ptr,avpkt);
if(got_frame_ptr){
audioRet=audioRet/2;
int b=0;
for(int i=0;i<audioRet;i++){
presentSound.myCharArray[0]=frame->data[0][2*i+1];
presentSound.myCharArray[1]=frame->data[0][2*i]
dbuf[((i-b)/2)*8+info->mLeft+b]=info->presentSound.value;//the reason of the offset by 8 here is because I will be writing the result to a multichannel device
}
有了这个,值是合理的,但是当我使用 portaudio 将它写入设备时,我只会听到咔嗒声。我是否以错误的方式进行转换?你能帮我用一些更好的方法来做这个阅读吗?
非常感谢您的帮助
阿尔巴
【问题讨论】:
标签: c++ casting ffmpeg short portaudio