经过一番研究,我发现这可以在Android的libaudioflinger中捕获音频数据。
我认为音频数据正在这里写入 HAL:
ssize_t framesWritten = mNormalSink->write((char *)mSinkBuffer + offset, count);
所以,我想将 mSinkBuffer + 偏移量保存到一个文件中(我预计它将是原始 PCM 音频文件)。我使用这些流将其写入文件:
std::ofstream audioData ("/data/audiodata.raw", std::fstream::app);
audioData.write((char *)mSinkBuffer + offset, count);
audioData.close();
该文件已成功写入,并且其中包含数据。但是,当我使用 aplay 或 ffplay 播放 PCM 文件 (audiodata.raw) 时,我得到的唯一声音是噪音。
aplay -t raw -c 2 -f S16_LE -r 48000 audiodata.raw
我担心aplay的配置。所以我打印了一些 libaudioflinger 的日志:
10-07 10:14:54.575 1300 1366 I AudioFlinger: I/O handle: 13
10-07 10:14:54.575 1300 1366 I AudioFlinger: Standby: no
10-07 10:14:54.575 1300 1366 I AudioFlinger: Sample rate: 48000 Hz
10-07 10:14:54.575 1300 1366 I AudioFlinger: HAL frame count: 512
10-07 10:14:54.575 1300 1366 I AudioFlinger: HAL format: 0x1 (AUDIO_FORMAT_PCM_16_BIT)
10-07 10:14:54.575 1300 1366 I AudioFlinger: HAL buffer size: 2048 bytes
10-07 10:14:54.575 1300 1366 I AudioFlinger: Channel count: 2
10-07 10:14:54.575 1300 1366 I AudioFlinger: Channel mask: 0x00000003 (front-left, front-right)
10-07 10:14:54.575 1300 1366 I AudioFlinger: Processing format: 0x5 (AUDIO_FORMAT_PCM_FLOAT)
10-07 10:14:54.576 1300 1366 I AudioFlinger: Processing frame size: 8 bytes
10-07 10:14:54.576 1300 1366 I AudioFlinger: Pending config events:
10-07 10:14:54.576 1300 1366 I AudioFlinger: none
10-07 10:14:54.576 1300 1366 I AudioFlinger: Output device: 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
10-07 10:14:54.576 1300 1366 I AudioFlinger: Input device: 0 (AUDIO_DEVICE_NONE)
10-07 10:14:54.576 1300 1366 I AudioFlinger: Audio source: 0 (default)
我不知道我做错了什么。请帮我!
提前谢谢你!