I'm having trouble using the AudioRecord class. I want to store the recorded data in a buffer, but I'm not sure if this is the right way to achieve this. I went through many examples, but most of them were complex and presented many different approaches. I am looking for a simple or simple explanation.
Here are my sound settings for my project:
int audioSource = AudioSource.MIC; int sampleRateInHz = 8000; int channelConfig = AudioFormat.CHANNEL_IN_MONO; int audioFormat = AudioFormat.ENCODING_PCM_16BIT; int bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat); short[] buffer = new short[bufferSizeInBytes]; AudioRecord audioRecorder = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes);
I am trying to create a write function:
public void Recording() { audioRecorder.startRecording(); ... audioRecorder.stop(); audioRecorder.release(); }
I know that I should use the .read function (short [] audioData, int offsetInShorts, int sizeInShorts). And here my problems begin. I am not sure how the audioData buffer works. I assume that the function places the recorded samples in audio data. What happens if it is completely filled with data? Does he start rewriting from an early position? If so, I believe that I need to copy all the collected samples somewhere else. Another question arises: how can I check if the buffer of the .read (...) function is full? Do I need to measure the time and contents of the copy buffer, or is there another way to achieve this? Also do I need to create a stream for the entire write operation?
Sorry to ask so many questions in one topic :)
android buffer
Arxas
source share