简体   繁体   English

Android AudioRecord和AudioTrack编解码器选项?

[英]Android AudioRecord and AudioTrack codec options?

I currently use the AudioTrack and AudioRecord classes in Android. 我目前在Android中使用AudioTrack和AudioRecord类。

I use the pure PCM data but I was wondering what my options are for other codecs? 我使用纯PCM数据,但我想知道我的其他编解码器的选项是什么?

From this page it seems I can only encode and decode using AMR narrowband? 这个页面看来,我只能使用AMR窄带进行编码和解码?

I currently set up the Audio classes as follows: 我目前设置Audio类如下:

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);

So my question is how do I change the encoding from PCM to one of the other supported codecs? 所以我的问题是如何将编码从PCM更改为其他支持的编解码器之一?

When I try to change ENCODING_PCM_16BIT on AudioFormat I only get the options of default or invalid encoding along with the PCM options. 当我尝试在AudioFormat上更改ENCODING_PCM_16BIT时,我只能获得默认或无效编码选项以及PCM选项。

Any links to tutorials on encoding and decoding audio on Android would be great if anyone knows of any or any help here greatly appreciated. 如果有人知道任何或任何帮助,那么在Android上编辑和解码音频教程的任何链接都会很棒。

Thanks 谢谢

EDIT: I have changed my code to the following: 编辑:我已将我的代码更改为以下内容:

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? 代码运行正常,但我想知道它实际上将音频编码为AMR_NB,如果这不是一个正确的方法吗?

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 我在使用原始PCM时遇到缓冲区溢出,但由于使用MediaRecorder.AudioEncoder.AMR_NB而不是AudioFormat.PCM使用新代码,因此没有出现

As the documentation states for AudioRecord and AudioTrack : 正如AudioRecordAudioTrack的文档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. 你只能使用8位和16位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. 如果您想要其他格式的音频,请不要使用AudioRecordAudioTrack (尝试MediaRecorderMediaPlayer ),否则您必须使用自己的代码对其进行转码,可能需要利用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 (eg, SIP). AudioRecordAudioTrack专门设计用于OpenCORE多媒体引擎不支持音频的情况,因为它不是支持的编解码器或不支持的流媒体协议(例如,SIP)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM