OS: Android 6.0
Kernel: 3.10.92
当录音异常时需要把数据dump出来判断问题出在哪一层,RK虽然在HAL层已经提供了dump方法,但有点问题:
static ssize_t read_frames(struct stream_in *in, void *buffer, ssize_t frames)
{
......
while (frames_wr < frames) {
size_t frames_rd = frames - frames_wr;
if (in->resampler != NULL) {
...... //流程1
} else {
......
#ifdef ALSA_IN_DEBUG
fwrite(buffer,frames_wr * frame_size,1,in_debug);
#endif
......
}
}
由于上层录音的采样率和硬件实际采的不一样,因此会走流程一,这样即使ALSA_IN_DEBUG宏打开了也不会有效,因此可以将读取数据的过程放在read_frames()外:
static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
size_t bytes)
{
......
ret = read_frames(in, buffer, frames_rq);
if (ret > 0)
ret = 0;
#ifdef ALSA_IN_DEBUG
fwrite(buffer,bytes ,1,in_debug);
#endif
......
}
另外,要先在/data/下创建debug.pcm,否则无法开机。
static int adev_open_input_stream(......)
{
......
#ifdef ALSA_IN_DEBUG
in_debug = fopen("/data/debug.pcm","wb");//please touch /data/debug.pcm first
#endif
......
}
抓出来的数据如果无法判定是否正常,用正弦波作为录音数据测试。