我在使用我的应用程序时出现缓冲区溢出RECORDING
。录制在Service
. 我无法弄清楚为什么我会从AudioFlinger
.
下面我实例化AudioRecord
对象并设置它的回调。
bufferSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
aRecorder = new AudioRecord(audioSource, sampleRate, channelConfig, audioFormat, bufferSize);
aRecorder.setRecordPositionUpdateListener(updateListener);
bytesPerSample = bitsPerSample / 8;
int bytesPerFrame = nChannels * bytesPerSample;
framePeriod = bufferSize / bytesPerFrame; // nr of frames that can be kept in a bufferSize dimension
int result = aRecorder.setPositionNotificationPeriod(framePeriod);
buffer = new byte[bufferSize];
audioRecord 回调:
private AudioRecord.OnRecordPositionUpdateListener updateListener = new AudioRecord.OnRecordPositionUpdateListener(){
public void onPeriodicNotification(AudioRecord recorder){
int result = aRecorder.read(buffer, 0, buffer.length);
}
public void onMarkerReached(AudioRecord recorder)
{}
};
我怀疑这个问题与以下有关:aRecorder.setPositionNotificationPeriod(framePeriod);
-也许这个 e 的周期太大了bufferSiz
,一个更快(更小)的周期将解决这个问题。
有人可以告诉我如何摆脱缓冲区溢出吗?