android网络mp3格式化,performance - Android AudioRecord MP3 encoding AudioFormat.CHANNEL_IN_STEREO - Stack...

I seem to be stuck with this problem,

I am trying to get

https://github.com/yhirano/SimpleLameLibForAndroid

to work on channelConfig AudioFormat.CHANNEL_IN_STEREO mode.

Below code works perfectly if i call it with channelConfig = AudioFormat.CHANNEL_IN_MONO but not with STEREO.

I have played around with

short[] buffer = new short[mSampleRate * (16 / 8) * nChannels * 5]

byte[] mp3buffer = new byte[(int) (7200 + buffer.length * 2 * 1.25)];

bu cannot seem to get it working. I mean it works but recorded sound is like very very slow. Listen to this example https://dl.dropboxusercontent.com/u/1465252/1381762795295.mp3

There seems to be another similar question at Lame encoded mp3 audio slowed down - Android without a solution.

Can anybody help?

Here is the code:

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

......

.......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值