您当前的位置: 首页 > 

顺其自然~

暂无认证

  • 2浏览

    0关注

    1317博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

单双声道及采样率转换

顺其自然~ 发布时间:2022-06-17 15:35:46 ,浏览量:2

1.单声道转双声道

每隔一个采样插入一个采样

if(rhwparams.format == SND_PCM_FORMAT_S16_LE){
    for(tempi=0;tempips32PcmBuffer+tempi);
        *((short *)audiobuf+tempi*2+1)=*((short *)pstAiFrame->ps32PcmBuffer+tempi);
    }
}
else if(rhwparams.format = SND_PCM_FORMAT_S32_LE){
    for(tempi=0;tempips32PcmBuffer+tempi);
        *((long *)audiobuf+tempi*2+1)=*((long *)pstAiFrame->ps32PcmBuffer+tempi);
    }
}

2.双声道转单声道

先获取每个声道中数据字节数,去掉右声道的数据

#include
#include
#include

int judge(char filename[])   //判断是否为双声道文件
{
FILE *fp;
int j=0;
// char *c,c1;
if((fp=fopen(filename,"rb"))==NULL)
{
printf("error!\n");
exit(0);
}
fseek(fp,22L,0);        //定位到文件的第23个字节
fread(&j,1,1,fp);       //读取储存音频声道数的信息
// printf("%d\n",j);
if(j==1)
{
printf("this is mono file!\n");   //如果是单声道文件,则退出
exit (0);
}

fseek(fp,34L,0);        //定位到第35个字节

fread(&j,1,1,fp);    //读取音频文件的每个声道中各个样本的数据位数。

return (j/8);

fclose(fp);

}



void change(char file1name[],char file2name[],int i)       //进行声道覆盖

{

FILE *in,*out;

long int *c = new long int[i];       //开辟以每个声道中各个样本的数据位数的数组空间

int j;

if((in=fopen(file1name,"rb"))==NULL)

{

printf("error!\n");

exit(0);

}

// in=fopen(file1name,"r");

if((out=fopen(file2name,"wb"))==NULL)  //判断输出的文件是否能打开

{

printf("error!\n");

exit(0);

}

for(j = 0;j = argc, "Expecting an input file name\n");



    input = argv[optind];



    printf("input file [%s]\n", input);

    printf("output file [%s]\n", output);

    printf("new rate: [%d]\n", new_rate);

    printf("quality: [%d]\n", quality);



    ifd = open(input, O_RDONLY);

    FAILIF(ifd             
关注
打赏
1662339380
查看更多评论
0.0407s