|
找不到合适的版块发这贴...就在这里向大家请教了,请不吝赐教
小弟想在QQ2440板上做一个语音采集与压缩程序,现在用一段测试代码在我的主机上可以正常录音放音,但重新编译后转到板上就不行了,测试代码如下:
- /** record.c **/
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #define LENGTH 5 /* 存储秒数 */
- #define RATE 48000 /* 采样频率 */
- #define SIZE 16 /* 量化位数 */
- #define CHANNELS 1 /* 声道数目 */
- /* 用于保存数字音频数据的内存缓冲区 */
- unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];
- int main()
- {
- int fd; /* 声音设备的文件描述符 */
- int arg; /* 用于ioctl调用的参数 */
- int status; /* 系统调用的返回值 */
- /* 打开声音设备 */
- fd = open("/dev/dsp", O_RDWR); //O_RDONLY,O_WRONLY,O_RDWR
- if (fd < 0)
- {
- perror("open of /dev/dsp failed");
- exit(1);
- }
- /* 设置采样时的量化位数 */
- arg = SIZE;
- status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
- if (status == -1)
- perror("SOUND_PCM_READ_BITS ioctl failed");
- if (arg != SIZE)
- perror("unable to set sample size");
- /* 设置采样时的声道数目 */
- arg = CHANNELS;
- status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
- if (status == -1)
- perror("SOUND_PCM_READ_CHANNELS ioctl failed");
- if (arg != CHANNELS)
- perror("unable to set number of channels");
- /* 设置采样时的采样频率 */
- arg = RATE;
- status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
- if (status == -1)
- perror("SOUND_PCM_READ_RATE ioctl failed");
- /* 循环,直到按下Control-C */
- //while (1)
- int i = 0;
- for (i=0; i<1; i++)
- {
- #if 0 //test ok
- int fdwav;
- fdwav = open("stereo_48_16.wav", O_RDONLY);
- if (fdwav < 0)
- {
- perror("open of wav failed");
- exit(1);
- }
- status = read(fdwav, buf, sizeof(buf));
- if (status != sizeof(buf))
- perror("read wrong number of bytes");
- printf("music testing...\n");
-
- status = write(fd, buf, sizeof(buf));
- if (status != sizeof(buf))
- perror("wrote wrong number of bytes");
- #endif
-
- //#if 0
-
- printf("Say something: \n");
- status = read(fd, buf, sizeof(buf)); /* 录音 */
- if (status != sizeof(buf))
- perror("read wrong number of bytes");
- else
- printf("Said! \n");
- //#endif
- //#if 0
- printf("You said:\n");
- status = write(fd, buf, sizeof(buf)); /* 回放 */
- if (status != sizeof(buf))
- perror("wrote wrong number of bytes");
-
- /* 在继续录音前等待回放结束 */
- status = ioctl(fd, SOUND_PCM_SYNC, 0);
- if (status == -1)
- perror("SOUND_PCM_SYNC ioctl failed");
- //#endif
- }
- close(fd);
-
- return 0;
- }
复制代码
在板子上运行是出现以下信息:
read wrong number of bytes: Illegal seek
dma2:loadbuffer:timeout loading buffer
在板子上可以正常播放stereo_48_16.wav(一段音乐),但是mp3就不行了
初来乍到,请大侠多多指教
板子内核是linux2.6.13
|
|