我在我的应用程序中使用
音频记录回调函数:
我猜测问题与以下代码有关:
请问有人知道如何消除缓冲区溢出吗?
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];
音频记录回调函数:
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);
,可能是周期对于这个bufferSize
来说太大了,通过更快(更小)的周期可以解决问题。请问有人知道如何消除缓冲区溢出吗?