fd = open("/dev/dsp", O_RDWR);
fd2 = open("/tmp/shengdao/sund",O_WRONLY);
下面是我录音的部分代码,这段代码可以正常的录音后回放出来。 但我在这段代码中加入了一个把语音数据写入fd2指向文件中,再这段代码运行一段时间后,我停止运行。
while (1) {
printf("Say something:\n");
status = read(fd, buf, sizeof(buf)); /* 录音 */
if((write(fd2,buf,status))<0) // 写入文件
{
printf("write /tmp/shengdao/sund fail\n");
}
if (status != sizeof(buf))
perror("read wrong number of bytes");
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");
}
我现在在上面的基础上修改了代码,通过从fd2指向的文件中把声音数据读取出来播放,下面是代码, 但不知道为什么,就是不能播放不出我之前录进去的声音
while (1) {
status = read(fd2, buf, sizeof(buf)); /*读数据 */
printf("You said:\n");
status = write(fd, buf, sizeof(buf)); /* 放声音 */
if (status != sizeof(buf))
perror("wrote wrong number of bytes");
}
麻烦大家帮我看看到底是为什么?我被这个纠缠几天了