我在Android1.5上面用AudioRecord录制pcm时,用AudioTrack播放出来的全是噪音,以下是源码,谁做过这方面的,帮我分析一下。
录制:
int minBuffSize = AudioRecord.getMinBufferSize(8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT);
AudioRecord mAudioRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, minBuffSize*3);
//开始录音
mAudioRecorder.startRecording();
byte[] mBuffer = new byte[minBuffSize*3];
//从MIC获取音频数据到mBuffer中
int len = mAudioRecorder.read(mBuffer, 0, 1200);
播放:
int iMinBufSize = AudioTrack.getMinBufferSize(8000,
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT);
AudioTrack audioTrack=new AudioTrack(AudioManager.STREAM_MUSIC, 8000,
AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT,
iMinBufSize, AudioTrack.MODE_STREAM) ;
audioTrack.play();
audioTrack.write(data, 0, data.length);
阅读(3582) | 评论(0) | 转发(0) |