linux 录取声音速度太快,麻烦帮忙看下什么情况,急!!!!!!!

jason87629 2014-03-31 10:48:18
#define LENGTH 30 /* how many seconds of speech to store */
#define RATE 8000 /* the sampling rate */
#define SIZE 16 /* sample size: 8 or 16 bits */
#define CHANNELS 1 /* 1 = mono 2 = stereo */
以上是设置参数。

sound_fd = open("/dev/dsp", O_RDWR); //打开声音设备
if (sound_fd < 0)
{
printf("open of /dev/dsp failed\n");
return;
}

int arg,status;

arg = SIZE;
status = ioctl(sound_fd, SOUND_PCM_WRITE_BITS, &arg); //设置采样时的量化位数
if (status == -1)
{
printf("SOUND_PCM_WRITE_BITS ioctl failed\n");
return;
}
if (arg != SIZE)
{
printf("unable to set sample size\n");
return;
}

arg = CHANNELS;
status = ioctl(sound_fd, SOUND_PCM_WRITE_CHANNELS, &arg); //设置采样时的声道数目
if (status == -1)
{
printf("SOUND_PCM_WRITE_CHANNELS ioctl failed\n");
return;
}
if (arg != CHANNELS)
{
printf("unable to set number of channels\n");
return;
}

arg = RATE;
ioctl(sound_fd, SOUND_PCM_WRITE_RATE, &arg); //设置采样时的采样频率
if (status == -1)
{
printf("SOUND_PCM_WRITE_RATE ioctl failed\n");
return;
}

unsigned char v_stream_rbuf[LENGTH*RATE*SIZE*CHANNELS/8/1000];//每次读取数据的大小
LENGTH是每次读取30秒,/1000就是每次读取30毫秒,/8我同事说正常是bit数据,/8就系byte字节,这样定就是读取30毫秒的字节音频数据

之后就是线程不断执行read,读取mic的声音数据了
read(sound_fd, v_stream_rbuf, sizeof(v_stream_rbuf));

但经测试,用计数器read完后次数+1,另外线程每秒打印次数出来,显示是171、172上下左右的次数,就是每秒能读取170多次声音数据,按照我这边设计是每次读取30毫秒,每秒大概是30+次的声音数据的,请问是哪里出问题呢?

把/8这个去掉就是unsigned char v_stream_rbuf[LENGTH*RATE*SIZE*CHANNELS/1000];
测试每秒读取11、12次

哪位朋友熟悉声音方面的麻烦帮帮忙吧,急啊!!!!!!!!!!!!
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jason87629 2014-03-31
  • 打赏
  • 举报
回复
哪位朋友熟悉声音方面的麻烦帮帮忙吧,急啊!!!!!!!!!!!!
jason87629 2014-03-31
  • 打赏
  • 举报
回复
哪位朋友熟悉声音方面的麻烦帮帮忙吧,急啊!!!!!!!!!!!!

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧