I'm trying to capture audio from a microphone and no matter what buffer
size (bufferSizeInBytes
) I set at construct time of AudioRecord
, when
I do a AudioRecord.read
I always get 8192
bytes of audio data (128
ms). I would like the AudioRecord.read
be able to read 40ms
of data
(2560 bytes
). The only working sample code that I can find is Sipdroid
(RtpStreamSender.java
) which I haven't tried.
Here's the relevant piece of my code:
public void run()
{
running = true;
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URG ENT_AUDIO);
try {
frameSize = AudioRecord.getMinBufferSize(samplingRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
Log.i(TAG, "trying to capture " + String.format("%d", frameSize) + " bytes");
record = new AudioRecord(MediaRecorder.AudioSource.MIC, samplingRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO, 开发者_运维百科AudioFormat.ENCODING_PCM_16BIT, frameSize);
record.startRecording();
byte[] buffer = new byte[frameSize];
while (running)
{
record.read(buffer, 0, frameSize);
Log.i(TAG, "Captured " + String.format("%d", frameSize) + " bytes of audio");
}
record.stop();
record.release();
} catch (Throwable t) {
Log.e(TAG, "Failed to capture audio");
}
}
My questions/comments are:
- Is this a limitation of AudioRecord class and/or the particular device ?
- I don't see a method to query the supported sampling rate (steps of bufferSizeInBytes) a given device can do. It would be nice if there's one.
- Can we use AudioRecord.OnRecordPositionUpdateListener and how?
- In above code encoding pcm in 8 bit is not working. why? if anyone tried sipdroid code, help me. Thanks in advance,
精彩评论