Java Android:LAME将PCM数据从AudioRecorder转换为MP3,但MP3文件有一些噪音

Java Android:LAME将PCM数据从AudioRecorder转换为MP3,但MP3文件有一些噪音,java,android,audio,lame,Java,Android,Audio,Lame,我在Android应用程序上使用LAME,以便将PCM数据从AudioRecorder转换为MP3。我可以生成MP3文件,但它有一些噪音 这是我的部分jni代码: jbyte *bufferArray = (*env)->GetByteArrayElements(env, buffer, NULL); //Convert To Short int shortLength = length / 2; short int shortBufferArray[shortLength]; int i

我在Android应用程序上使用LAME,以便将PCM数据从AudioRecorder转换为MP3。我可以生成MP3文件,但它有一些噪音

这是我的部分jni代码:

jbyte *bufferArray = (*env)->GetByteArrayElements(env, buffer, NULL);
//Convert To Short
int shortLength = length / 2;
short int shortBufferArray[shortLength];
int i ;
for(i=0;i<shortLength;i++){
    int index = 2*i;
    shortBufferArray[i] = (bufferArray[index+1] << 8) |  bufferArray[index];
}

int mp3BufferSize = (int)(shortLength*1.5+7200);
unsigned char output[mp3BufferSize];
int encodeResult;
if(lame_get_num_channels(lame)==2){
    encodeResult = lame_encode_buffer_interleaved(lame, shortBufferArray, shortLength/2, output, mp3BufferSize);
}else{
    encodeResult = lame_encode_buffer(lame, shortBufferArray, shortBufferArray, shortLength, output, mp3BufferSize);
}

if(encodeResult < 0){
    return NULL;
}
jbyteArray result = (*env)->NewByteArray(env, encodeResult);
(*env)->SetByteArrayRegion(env, result, 0, encodeResult, output);
(*env)->ReleaseByteArrayElements(env, buffer, bufferArray, 0);
return result;
jbyte*bufferArray=(*env)->GetByteArrayElements(env,buffer,NULL);
//变短
int shortLength=长度/2;
short int shortBufferArray[shortLength];
int i;
for(i=0;iSetByteArrayRegion(env,result,0,encodeResult,output);
(*env)->ReleaseByteArrayElements(env,buffer,bufferArray,0);
返回结果;
我调用此jni函数将PCM数据编码为MP3数据,然后将MP3数据写入文件以构建一个MP3文件。PCM数据全部编码后,生成MP3文件。似乎播放MP3文件是正常的,但MP3文件的质量很差,即使我使用320kbps作为其比特率。MP3文件中有一些噪音,但为什么?

shortBufferArray[i]=(BufferArray[index+1]
shortBufferArray[i] = (bufferArray[index+1] << 8) |  bufferArray[index];
shortBufferArray[i] = (bufferArray[index+1] << 8) |  ((unsigned char) bufferArray[index]);