QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1902|回复: 0

QQ2440录音放音问题

[复制链接]
发表于 2009-4-17 15:29:12 | 显示全部楼层 |阅读模式
小弟想在QQ2440板上做一个语音采集与压缩程序,现在用一段测试代码在我的主机上可以正常录音放音,但重新编译后转到板上就不行了,测试代码如下:
  1. /** record.c **/

  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. #include <sys/types.h>
  5. #include <sys/ioctl.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <linux/soundcard.h>

  9. #define LENGTH 5    /* 存储秒数 */
  10. #define RATE 48000   /* 采样频率 */
  11. #define SIZE 16     /* 量化位数 */
  12. #define CHANNELS 1  /* 声道数目 */

  13. /* 用于保存数字音频数据的内存缓冲区 */
  14. unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];

  15. int main()
  16. {
  17.         int fd;        /* 声音设备的文件描述符 */
  18.         int arg;        /* 用于ioctl调用的参数 */
  19.         int status;   /* 系统调用的返回值 */

  20.         /* 打开声音设备 */
  21.         fd = open("/dev/dsp", O_RDWR); //O_RDONLY,O_WRONLY,O_RDWR
  22.         if (fd < 0)
  23.         {
  24.                 perror("open of /dev/dsp failed");
  25.                 exit(1);
  26.         }

  27.         /* 设置采样时的量化位数 */
  28.         arg = SIZE;
  29.         status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
  30.         if (status == -1)
  31.                 perror("SOUND_PCM_READ_BITS ioctl failed");
  32.         if (arg != SIZE)
  33.                 perror("unable to set sample size");

  34.         /* 设置采样时的声道数目 */
  35.         arg = CHANNELS;
  36.         status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
  37.         if (status == -1)
  38.                 perror("SOUND_PCM_READ_CHANNELS ioctl failed");
  39.         if (arg != CHANNELS)
  40.                 perror("unable to set number of channels");

  41.         /* 设置采样时的采样频率 */
  42.         arg = RATE;
  43.         status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
  44.         if (status == -1)
  45.                 perror("SOUND_PCM_READ_RATE ioctl failed");


  46.         /* 循环,直到按下Control-C */
  47.         //while (1)
  48.         int i = 0;       
  49.         for (i=0; i<1; i++)
  50.         {

  51.                 #if 0 //test ok
  52.                 int fdwav;
  53.                 fdwav = open("stereo_48_16.wav", O_RDONLY);
  54.                 if (fdwav < 0)
  55.                 {
  56.                         perror("open of wav failed");
  57.                         exit(1);               
  58.                 }

  59.                 status = read(fdwav, buf, sizeof(buf));
  60.                 if (status != sizeof(buf))
  61.                         perror("read wrong number of bytes");

  62.                 printf("music testing...\n");
  63.        
  64.                 status = write(fd, buf, sizeof(buf));
  65.                 if (status != sizeof(buf))
  66.                         perror("wrote wrong number of bytes");
  67.                 #endif
  68.                
  69.                 //#if 0
  70.                        
  71.                 printf("Say something: \n");
  72.                 status = read(fd, buf, sizeof(buf)); /* 录音 */
  73.                 if (status != sizeof(buf))
  74.                         perror("read wrong number of bytes");
  75.                 else
  76.                         printf("Said! \n");
  77.                 //#endif


  78.                 //#if 0
  79.                 printf("You said:\n");
  80.                 status = write(fd, buf, sizeof(buf)); /* 回放 */
  81.                 if (status != sizeof(buf))
  82.                         perror("wrote wrong number of bytes");
  83.                
  84.                 /* 在继续录音前等待回放结束 */
  85.                 status = ioctl(fd, SOUND_PCM_SYNC, 0);
  86.                 if (status == -1)
  87.                         perror("SOUND_PCM_SYNC ioctl failed");
  88.                 //#endif

  89.         }

  90.         close(fd);
  91.        
  92.         return 0;
  93. }
复制代码
在板子上运行是出现以下信息:
read wrong number of bytes: Illegal seek
dma2:loadbuffer:timeout loading buffer

在板子上可以正常播放stereo_48_16.wav(一段音乐),但是mp3就不行了
初来乍到,请大侠多多指教
板子内核是linux2.6.13
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-3-29 23:34 , Processed in 0.087662 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表