5

我目前在 Android 中使用 AudioTrack 和 AudioRecord 类。

我使用纯 PCM 数据,但我想知道其他编解码器有哪些选择?

这个页面看来我只能使用 AMR 窄带进行编码和解码?

我目前设置音频类如下:

arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
                     11025,
                     AudioFormat.CHANNEL_CONFIGURATION_MONO,
                     AudioFormat.ENCODING_PCM_16BIT,
                     buffersize);

atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                     11025,
                     AudioFormat.CHANNEL_CONFIGURATION_MONO,
                     AudioFormat.ENCODING_PCM_16BIT,
                     buffersize,
                     AudioTrack.MODE_STREAM);

所以我的问题是如何将编码从 PCM 更改为其他支持的编解码器之一?

当我尝试在 AudioFormat 上更改 ENCODING_PCM_16BIT 时,我只会获得默认或无效编码的选项以及 PCM 选项。

如果有人知道这里的任何帮助或任何帮助,任何指向 Android 上编码和解码音频的教程的链接都会非常感谢。

谢谢

编辑:我已将代码更改为以下内容:

arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
                     11025,
                     AudioFormat.CHANNEL_CONFIGURATION_MONO,
                     **MediaRecorder.AudioEncoder.AMR_NB**,
                     buffersize);

atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                     11025,
                     AudioFormat.CHANNEL_CONFIGURATION_MONO,
                     **MediaRecorder.AudioEncoder.AMR_NB**,
                     buffersize,
                     AudioTrack.MODE_STREAM);

The code runs properly but I'm wondering does it actually encode the Audio as AMR_NB and if this is not a proper way to do it?

I was getting a buffer overflow when using raw PCM but none have appeared since using the new code with the MediaRecorder.AudioEncoder.AMR_NB used instead of the AudioFormat.PCM

4

1 回答 1

3

As the documentation states for AudioRecord and AudioTrack:

audioFormat     the format in which the audio data is represented. See ENCODING_PCM_16BIT and ENCODING_PCM_8BIT

you can only work with 8-bit and 16-bit PCM. If you want audio in other formats, either don't use AudioRecord and AudioTrack (try MediaRecorder and MediaPlayer) or you will have to transcode it using your own code, possibly leveraging the NDK.

AudioRecord and AudioTrack are designed specifically for cases where the audio in question is not supported by the OpenCORE multimedia engine, either because it's not a supported codec or not a supported streaming protocol (e.g., SIP).

于 2010-02-03T13:57:37.960 回答