通过 aplay 以指定的格式播放 单声道WAV文件结果比较:
Playing WAVE '/usr/share/sounds/alsa/48k_mono.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono aplay: set_params:1305: Channels count non available
可正常播放.
区别在于 hw 和 plughw , 参考 Difference between “hwplug” and “hw” 得出结论
: accesses the hardware device directly. // 直接访问硬件
: inserts sample rate and format conversion plugins, if needed. ///通过采样率和格式转换插件
可以通过mediainfo查看文件信息, 发现为1通道格式,Codec driver 需要播放的2 channel所以需要plug转换为2 channel才可以播放.
特意找了一个2 channel / 48kHz , 验证猜测结果。 不加plug可正常播放
? alsa mediainfo Front_Left.wav General Complete name : 48k_mono.wav Format : Wave File size : 139 KiB Duration : 1 s 480 ms Overall bit rate mode : Constant Overall bit rate : 768 kb/s Audio Format : PCM Format settings : Little / Signed Codec ID : 1 Duration : 1 s 480 ms Bit rate mode : Constant Bit rate : 768 kb/s Channel(s) : 1 channel Sampling rate : 48.0 kHz Bit depth : 16 bits Stream size : 139 KiB (100%)
上面的例子是播放指定格式的wav事实上,音频文件对指定的收集和播放设备也有同样的理解: 使用plughw
如果设置的配置参数与实际硬件支持的参数不一致,程序员就不必太在意接口,ALSA 数据将自动转换。 如果使用hw
我们必须检测硬件是否支持设置的参数。 hw
和plughw
后两个数字分别表示card号和device号。
[1] https://blog.51cto.com/yiluohuanghun/868048 [2] https://developer.aliyun.com/article/438059