我想测试 aplay 是否可以连续播放波形文件,因此首先在 shell 窗口中尝试 2 个不同的命令(对目标进行腻子):
aplay -P -c 1 -t raw -r 16000 -f S16_LE audio/test1.raw
aplay -P -c 1 -t wav -r 32000 -f S16_LE audio/test2.wav
两者都在工作。
现在我创建了一个简单的程序 main() 以使用 C++ 自动运行:
char ac[100] = {0};
int n = 0;
while (1)
{
printf("---%d \n", ++n);
strcpy(ac, "sudo nice -n -10 aplay -P -c 1 -t raw -r 16000 -f S16_LE audio/test1.raw");
system(ac);
delay(1000); //delay 1s
strcpy(ac, "sudo nice -n -10 aplay -P -c 1 -t wav -r 32000 -f S16_LE audio/test2.wav");
system(ac);
delay(1000);
}
延迟()函数:
int delay(int nMs)
{
struct timespec requested_time, remaining;
requested_time.tv_nsec = (nMs%1000)*1000000;
requested_time.tv_sec = (nMs/1000);
return nanosleep (&requested_time, &remaining);
}
结果是 aplay 卡在 test2.wav 处:
root@linaro-ubuntu-desktop:/TEST# sudo nice -n -10 aplay -P -c 1 -t raw -r 16000 -f S16_LE audio/test1.raw
Playing raw data 'audio/test1.raw' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono --- ok, heard
root@linaro-ubuntu-desktop:/TEST# sudo nice -n -10 aplay -P -c 1 -t wav -r 32000 -f S16_LE audio/test2.wav
Playing WAVE 'audio/test2.wav' : Signed 16 bit Little Endian, Rate 32000 Hz, Mono --- ok, heard
root@linaro-ubuntu-desktop:/TEST# ./Test
--- 1
Playing raw data 'audio/test1.raw' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
Playing WAVE 'audio/test2.wav' : Signed 16 bit Little Endian, Rate 32000 Hz, Mono --- ok, heard
^CAborted by signal Interrupt...
--- 2
Playing raw data 'audio/test1.raw' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono --- nok, no sound, hang
^CAborted by signal Interrupt...
Playing WAVE 'audio/test2.wav' : Signed 16 bit Little Endian, Rate 32000 Hz, Mono --- nok, no sound, hang
^CAborted by signal Interrupt...
--- 3
Playing raw data 'audio/test1.raw' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono --- nok, no sound, hang
^CAborted by signal Interrupt...
^C
这超出了我的知识范围...任何人都可以帮助解释以及如何防止这种情况吗?我使用的操作系统是:
lsb_release -a:
No LSB modules are available.
Distributor ID: Linaro
Description: Linaro 11.10 (development branch)
Release: 11.10
Codename: oneiric
cat /proc/version:
Linux version 3.0.35-2666-gbdde708 (root@jt-G31M-S2L) (gcc version 4.6.2 20110630 (prerelease) (Freescale MAD -- Linaro 2011.07 -- Built at 2011/08/10 09:20) ) #14 SMP PREEMPT Thu May 26 11:21:54 CST 2016
声卡是wm8962-audio。