3852
- 收藏
- 点赞
- 分享
- 举报
请教如何播放双声道的PCM音频数据
Hi3518EV200。
我在打开输出设备后,打开并绑定了2个输出通道和解码通道,分别往2个解码通道发送数据,但是执行时只能听到通道0,也就是左声道的声音,通道2没声音且不断提示“[Func]:HI_MPI_AO_SendFrame [Line]:1854 [Info]:AO chn 1 is not enable”。
如果是打开输出设备后,只打开并绑定1个输出通道和解码通道,出来的声音很慢,听起来像是以单声道的速度在播放。
应该怎么做才能正确输出左右2个声道的声音呢?
[code]
int main()
{
HI_S32 ret;
VB_CONF_S vbConf;
MPP_SYS_CONF_S mppSysConf;
HI_S32 fdAcodec;
ACODEC_FS_E i2sFs;
AUDIO_DEV aoDev = 0;
AO_CHN aoChnL = 0;
AO_CHN aoChnR = 1;
ADEC_CHN adecChnL = 0;
ADEC_CHN adecChnR = 1;
AIO_ATTR_S aoAttr;
ADEC_ATTR_LPCM_S adecAttrLpcm;
ADEC_CHN_ATTR_S adecChnAttr;
MPP_CHN_S mppSrcChnL, mppDstChnL;
MPP_CHN_S mppSrcChnR, mppDstChnR;
AUDIO_STREAM_S streamL;
AUDIO_STREAM_S streamR;
FILE *fpL = NULL;
FILE *fpR = NULL;
char bufL[640] = {0};
char bufR[640] = {0};
HI_U32 size = 0;
//初始化MPP系统
HI_MPI_SYS_Exit();
HI_MPI_VB_Exit();
memset(&vbConf, 0, sizeof(VB_CONF_S));
HI_MPI_VB_SetConf(&vbConf);
HI_MPI_VB_Init();
mppSysConf.u32AlignWidth = 64;
HI_MPI_SYS_SetConf(&mppSysConf);
HI_MPI_SYS_Init();
//初始化AudioCodec
fdAcodec = open(ACODEC_FILE, O_RDWR);
ioctl(fdAcodec, ACODEC_SOFT_RESET_CTRL);
i2sFs = ACODEC_FS_44100;
ioctl(fdAcodec, ACODEC_SET_I2S1_FS, &i2sFs);
close(fdAcodec);
//打开输出设备
aoAttr.enSamplerate = AUDIO_SAMPLE_RATE_44100;
aoAttr.enBitwidth = AUDIO_BIT_WIDTH_16;
aoAttr.enWorkmode = AIO_MODE_I2S_MASTER;
aoAttr.enSoundmode = AUDIO_SOUND_MODE_STEREO;
aoAttr.u32EXFlag = 0;
aoAttr.u32FrmNum = 30;
aoAttr.u32PtNumPerFrm = 320;
aoAttr.u32ChnCnt = 2;
aoAttr.u32ClkSel = 0;
ret = HI_MPI_AO_SetPubAttr(aoDev, &aoAttr);
if(ret != HI_SUCCESS)
{
printf("HI_MPI_AO_SetPubAttr error: 0x%x\n", ret);
}
ret = HI_MPI_AO_Enable(aoDev);
if(ret != HI_SUCCESS)
{
printf("HI_MPI_AO_Enable error: 0x%x\n", ret);
}
//打开输出通道
ret = HI_MPI_AO_EnableChn(aoDev, aoChnL);
if(ret != HI_SUCCESS)
{
printf("HI_MPI_AO_EnableChn error: 0x%x\n", ret);
}
//HI_MPI_AO_EnableChn(aoDev, aoChnR); //根据文档描述不用使能此通道
//打开解码通道
adecChnAttr.enType = PT_LPCM;
adecChnAttr.u32BufSize = 20;
adecChnAttr.enMode = ADEC_MODE_PACK;
adecChnAttr.pValue = &adecAttrLpcm;
HI_MPI_ADEC_CreateChn(adecChnL, &adecChnAttr);
HI_MPI_ADEC_CreateChn(adecChnR, &adecChnAttr);
//绑定输出通道和解码通道
mppSrcChnL.enModId = HI_ID_ADEC;
mppSrcChnL.s32DevId = 0;
mppSrcChnL.s32ChnId = adecChnL;
mppDstChnL.enModId = HI_ID_AO;
mppDstChnL.s32DevId = aoDev;
mppDstChnL.s32ChnId = aoChnL;
HI_MPI_SYS_Bind(&mppSrcChnL, &mppDstChnL);
mppSrcChnR.enModId = HI_ID_ADEC;
mppSrcChnR.s32DevId = 0;
mppSrcChnR.s32ChnId = adecChnR;
mppDstChnR.enModId = HI_ID_AO;
mppDstChnR.s32DevId = aoDev;
mppDstChnR.s32ChnId = aoChnR;
HI_MPI_SYS_Bind(&mppSrcChnR, &mppDstChnR);
//设置音量
HI_MPI_AO_SetVolume(aoDev, 6);
//开始播放
#if(0)
fpL = fopen("/tfcard/chan1.wav", "r+");
fpR = fopen("/tfcard/chan1-1.wav", "r+");
while(1)
{
size = fread(bufL, 1, sizeof(bufL), fpL);
if(size == 0) break;
streamL.pStream = (HI_U8 *)bufL;
streamL.u32Len = size;
HI_MPI_ADEC_SendStream(adecChnL, &streamL, HI_TRUE);
size = fread(bufR, 1, sizeof(bufR), fpR);
if(size == 0) break;
streamR.pStream = (HI_U8 *)bufR;
streamR.u32Len = size;
HI_MPI_ADEC_SendStream(adecChnR, &streamR, HI_TRUE);
}
fclose(fpL);
fclose(fpR);
#else
fpL = fopen("/tfcard/chan2.wav", "r+");
while(1)
{
size = fread(bufL, 1, sizeof(bufL), fpL);
if(size == 0) break;
streamL.pStream = (HI_U8 *)bufL;
streamL.u32Len = size;
HI_MPI_ADEC_SendStream(adecChnL, &streamL, HI_TRUE);
}
fclose(fpL);
#endif
//关闭通道
HI_MPI_SYS_UnBind(&mppSrcChnL, &mppDstChnL);
HI_MPI_SYS_UnBind(&mppSrcChnR, &mppDstChnR);
HI_MPI_AO_DisableChn(aoDev, aoChnL);
HI_MPI_AO_DisableChn(aoDev, aoChnR);
HI_MPI_AO_Disable(aoDev);
HI_MPI_ADEC_DestroyChn(adecChnL);
HI_MPI_ADEC_DestroyChn(adecChnR);
//关闭MPP系统
HI_MPI_SYS_Exit();
HI_MPI_VB_Exit();
return 0;
}
[/code]
我在打开输出设备后,打开并绑定了2个输出通道和解码通道,分别往2个解码通道发送数据,但是执行时只能听到通道0,也就是左声道的声音,通道2没声音且不断提示“[Func]:HI_MPI_AO_SendFrame [Line]:1854 [Info]:AO chn 1 is not enable”。
如果是打开输出设备后,只打开并绑定1个输出通道和解码通道,出来的声音很慢,听起来像是以单声道的速度在播放。
应该怎么做才能正确输出左右2个声道的声音呢?
[code]
int main()
{
HI_S32 ret;
VB_CONF_S vbConf;
MPP_SYS_CONF_S mppSysConf;
HI_S32 fdAcodec;
ACODEC_FS_E i2sFs;
AUDIO_DEV aoDev = 0;
AO_CHN aoChnL = 0;
AO_CHN aoChnR = 1;
ADEC_CHN adecChnL = 0;
ADEC_CHN adecChnR = 1;
AIO_ATTR_S aoAttr;
ADEC_ATTR_LPCM_S adecAttrLpcm;
ADEC_CHN_ATTR_S adecChnAttr;
MPP_CHN_S mppSrcChnL, mppDstChnL;
MPP_CHN_S mppSrcChnR, mppDstChnR;
AUDIO_STREAM_S streamL;
AUDIO_STREAM_S streamR;
FILE *fpL = NULL;
FILE *fpR = NULL;
char bufL[640] = {0};
char bufR[640] = {0};
HI_U32 size = 0;
//初始化MPP系统
HI_MPI_SYS_Exit();
HI_MPI_VB_Exit();
memset(&vbConf, 0, sizeof(VB_CONF_S));
HI_MPI_VB_SetConf(&vbConf);
HI_MPI_VB_Init();
mppSysConf.u32AlignWidth = 64;
HI_MPI_SYS_SetConf(&mppSysConf);
HI_MPI_SYS_Init();
//初始化AudioCodec
fdAcodec = open(ACODEC_FILE, O_RDWR);
ioctl(fdAcodec, ACODEC_SOFT_RESET_CTRL);
i2sFs = ACODEC_FS_44100;
ioctl(fdAcodec, ACODEC_SET_I2S1_FS, &i2sFs);
close(fdAcodec);
//打开输出设备
aoAttr.enSamplerate = AUDIO_SAMPLE_RATE_44100;
aoAttr.enBitwidth = AUDIO_BIT_WIDTH_16;
aoAttr.enWorkmode = AIO_MODE_I2S_MASTER;
aoAttr.enSoundmode = AUDIO_SOUND_MODE_STEREO;
aoAttr.u32EXFlag = 0;
aoAttr.u32FrmNum = 30;
aoAttr.u32PtNumPerFrm = 320;
aoAttr.u32ChnCnt = 2;
aoAttr.u32ClkSel = 0;
ret = HI_MPI_AO_SetPubAttr(aoDev, &aoAttr);
if(ret != HI_SUCCESS)
{
printf("HI_MPI_AO_SetPubAttr error: 0x%x\n", ret);
}
ret = HI_MPI_AO_Enable(aoDev);
if(ret != HI_SUCCESS)
{
printf("HI_MPI_AO_Enable error: 0x%x\n", ret);
}
//打开输出通道
ret = HI_MPI_AO_EnableChn(aoDev, aoChnL);
if(ret != HI_SUCCESS)
{
printf("HI_MPI_AO_EnableChn error: 0x%x\n", ret);
}
//HI_MPI_AO_EnableChn(aoDev, aoChnR); //根据文档描述不用使能此通道
//打开解码通道
adecChnAttr.enType = PT_LPCM;
adecChnAttr.u32BufSize = 20;
adecChnAttr.enMode = ADEC_MODE_PACK;
adecChnAttr.pValue = &adecAttrLpcm;
HI_MPI_ADEC_CreateChn(adecChnL, &adecChnAttr);
HI_MPI_ADEC_CreateChn(adecChnR, &adecChnAttr);
//绑定输出通道和解码通道
mppSrcChnL.enModId = HI_ID_ADEC;
mppSrcChnL.s32DevId = 0;
mppSrcChnL.s32ChnId = adecChnL;
mppDstChnL.enModId = HI_ID_AO;
mppDstChnL.s32DevId = aoDev;
mppDstChnL.s32ChnId = aoChnL;
HI_MPI_SYS_Bind(&mppSrcChnL, &mppDstChnL);
mppSrcChnR.enModId = HI_ID_ADEC;
mppSrcChnR.s32DevId = 0;
mppSrcChnR.s32ChnId = adecChnR;
mppDstChnR.enModId = HI_ID_AO;
mppDstChnR.s32DevId = aoDev;
mppDstChnR.s32ChnId = aoChnR;
HI_MPI_SYS_Bind(&mppSrcChnR, &mppDstChnR);
//设置音量
HI_MPI_AO_SetVolume(aoDev, 6);
//开始播放
#if(0)
fpL = fopen("/tfcard/chan1.wav", "r+");
fpR = fopen("/tfcard/chan1-1.wav", "r+");
while(1)
{
size = fread(bufL, 1, sizeof(bufL), fpL);
if(size == 0) break;
streamL.pStream = (HI_U8 *)bufL;
streamL.u32Len = size;
HI_MPI_ADEC_SendStream(adecChnL, &streamL, HI_TRUE);
size = fread(bufR, 1, sizeof(bufR), fpR);
if(size == 0) break;
streamR.pStream = (HI_U8 *)bufR;
streamR.u32Len = size;
HI_MPI_ADEC_SendStream(adecChnR, &streamR, HI_TRUE);
}
fclose(fpL);
fclose(fpR);
#else
fpL = fopen("/tfcard/chan2.wav", "r+");
while(1)
{
size = fread(bufL, 1, sizeof(bufL), fpL);
if(size == 0) break;
streamL.pStream = (HI_U8 *)bufL;
streamL.u32Len = size;
HI_MPI_ADEC_SendStream(adecChnL, &streamL, HI_TRUE);
}
fclose(fpL);
#endif
//关闭通道
HI_MPI_SYS_UnBind(&mppSrcChnL, &mppDstChnL);
HI_MPI_SYS_UnBind(&mppSrcChnR, &mppDstChnR);
HI_MPI_AO_DisableChn(aoDev, aoChnL);
HI_MPI_AO_DisableChn(aoDev, aoChnR);
HI_MPI_AO_Disable(aoDev);
HI_MPI_ADEC_DestroyChn(adecChnL);
HI_MPI_ADEC_DestroyChn(adecChnR);
//关闭MPP系统
HI_MPI_SYS_Exit();
HI_MPI_VB_Exit();
return 0;
}
[/code]
我来回答
回答7个
时间排序
认可量排序
认可0
认可0
认可0
认可0
认可0
认可0
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2019-03-11 22:08:02
-
2015-09-14 22:52:09
-
2020-11-14 10:50:35
-
2020-11-11 15:42:55
-
2018-02-28 19:51:26
-
2023-07-19 13:30:50
-
2015-09-21 18:18:29
-
2019-02-16 16:57:43
-
2016-11-30 16:08:50
-
2017-04-17 16:32:47
-
2017-12-20 17:19:47
-
2020-06-19 09:50:26
-
2016-03-28 17:16:20
-
2017-07-24 16:36:47
-
2016-12-13 11:55:41
-
2016-05-17 16:22:50
-
2017-08-07 19:39:18
-
2017-04-28 10:44:47
-
2021-08-18 14:54:02
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5Hi3516CV610 如何使用SD卡升级固件
-
5cat /dev/logmpp 报错 <3>[ vi] [func]:vi_send_frame_node [line]:99 [info]:vi pic queue is full!
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认