【问题标题】:Android AudioRecord MP3 encoding AudioFormat.CHANNEL_IN_STEREOAndroid AudioRecord MP3 编码 AudioFormat.CHANNEL_IN_STEREO
【发布时间】:2013-10-14 15:15:15
【问题描述】:

我似乎被这个问题困住了,

我正在努力 https://github.com/yhirano/SimpleLameLibForAndroid 在 channelConfig AudioFormat.CHANNEL_IN_STEREO 模式下工作。

如果我使用 channelConfig = AudioFormat.CHANNEL_IN_MONO 但不使用 STEREO 调用以下代码,则可以完美运行。

我玩过

 short[] buffer = new short[mSampleRate * (16 / 8) * nChannels * 5]
 byte[] mp3buffer = new byte[(int) (7200 + buffer.length * 2 * 1.25)];

bu 似乎无法正常工作。我的意思是它可以工作,但录制的声音非常非常慢。听听这个例子https://dl.dropboxusercontent.com/u/1465252/1381762795295.mp3

Lame encoded mp3 audio slowed down - Android 似乎还有另一个类似的问题没有解决方案。

有人可以帮忙吗?

代码如下:

  new Mp3Audio(MediaRecorder.AudioSource.MIC, 44100, AudioFormat.CHANNEL_IN_STEREO, A udioFormat.ENCODING_PCM_16BIT, 128);


 public Mp3Audio(int audioSource, int sampleRate, int channelConfig, int audioFormat, int bitRate) {
    if (sampleRate <= 0) {
        throw new InvalidParameterException(
                "Invalid sample rate specified.");
    }

    mSampleRate = sampleRate;
    mBitRate = bitRate;
    if (channelConfig == AudioFormat.CHANNEL_IN_MONO) {
        nChannels = 1;
    } else {
        nChannels = 2;
    }
    builder = new Builder(mSampleRate, nChannels, mSampleRate, mBitRate);
    //builder = new Builder(44100, 1, 44100, 128);

    builder.quality(6); 

    mEncoder = builder.create();
    cAmplitude = 0;
    payloadSize = 0;
    aFormat = audioFormat;
    aSource = audioSource;
    mChannelConfig = channelConfig;


}
     public void start() {
 final int minBufferSize = AudioRecord.getMinBufferSize(mSampleRate, mChannelConfig, aFormat) * mBufferSizeFactor;      
            if (minBufferSize < 0) {
                AppHelper.Log(tag, "MSG_ERROR_GET_MIN_BUFFERSIZE");
                return;
            }
            AppHelper.Log(tag, "minBufferSize: " +      AppHelper.humanReadableByteCount(minBufferSize, true));
            aRecorder = new AudioRecord(
                    aSource, 
                    mSampleRate,
                    mChannelConfig,
                    aFormat, 
                    minBufferSize);




            short[] buffer = new short[mSampleRate * (16 / 8) * nChannels * 5]; // SampleRate[Hz] * 16bit * Mono * 5sec 
            AppHelper.Log(tag, "buffer: " + AppHelper.humanReadableByteCount(buffer.length, true));
            byte[] mp3buffer = new byte[(int) (7200 + buffer.length * 2 * 1.25)];
            AppHelper.Log(tag, "mp3buffer: " + AppHelper.humanReadableByteCount(mp3buffer.length, true));

…… .......

【问题讨论】:

  • 您需要在问题中包含对 LAME 库的调用。

标签: android performance audiorecord lame jini


【解决方案1】:

如果您使用 2 个通道 (.stereo) 进行录制,则需要调用 lame_encode_buffer_interleaved() 为您提供指针。

我花了几天时间才弄明白,这是你可以使用的代码:

if (lame_get_num_channels(glf) == 2)
    {
        result = lame_encode_buffer_interleaved(glf, j_buffer_l, samples/2, j_mp3buf, mp3buf_size);
    }
    else
    {
        result = lame_encode_buffer(glf, j_buffer_l, j_buffer_r, samples, j_mp3buf, mp3buf_size);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-27
    • 2013-11-18
    • 2018-02-20
    • 2012-06-08
    • 1970-01-01
    • 2012-09-23
    • 2011-06-10
    • 2012-09-28
    相关资源
    最近更新 更多