Other Audiostreamer possibility of setting the buffersize


Well-Known Member
Licensed User
can audiostreamer library have this functionality

setBufferSizeInBytes which i found some reference to it here


its really needed to reduce the buffer size on some phones that have a larger buffer size

this will give much more flexibility of the usage of audiostreamer

here is a brief of what this function can do

added in API level 23
public AudioRecord.Builder setBufferSizeInBytes (int bufferSizeInBytes)
Sets the total size (in bytes) of the buffer where audio data is written during the recording. New audio data can be read from this buffer in smaller chunks than this size. See AudioRecord.getMinBufferSize(int, int, int) to determine the minimum required buffer size for the successful creation of an AudioRecord instance. Since bufferSizeInBytes may be internally increased to accommodate the source requirements, use AudioRecord.getBufferSizeInFrames() to determine the actual buffer size in frames.


Licensed User
Longtime User
Sub Process_Globals
   Private audioStream As AudioStreamer
End Sub

Sub SomeSub
    audioStream.Initialize("AudioStream", 8000, True, 16, audioStream.VOLUME_MUSIC)
   'Fetch AudioStreamer's recording buffer
   Dim r As Reflector
   r.Target = audioStream
   'Let's see what we currently have
   Dim recordBuffer() As Byte = r.GetField("recordBuffer")
   Log($"Record buffer size: ${recordBuffer.Length}"$)
   'Create a new recording buffer and assign it to the AudioStreamer object.
   'For demo purposes, we just make the new size 1/2 of the original size
   Dim newBuffer(bufferLength/2) As Byte
   r.SetField2("recordBuffer", newBuffer)
   'Let's see what we have after the change
   Dim recordBuffer2() As Byte = r.GetField("recordBuffer")
   Log($"New record buffer size: ${recordBuffer2.Length}"$)
End Sub

Please note that this does not actually change Android's recording buffer size. What it does change is the buffer size that AudioStreamer uses for recording. By default, AudioStreamer will make its recording buffer size the same as AudioRecord's MinBufferSize. So if a phone has a 2KB Buffer, AudioStreamer's initial buffer/recording size will be 2KB. So the RecordBuffer event will occur after every 2KB worth of recording. If, for example, one replaces AudioStreamer's buffer with a 512 byte buffer, one will cause AudioStreamer to call the RecordBuffer event more often (in this case, after every 512 bytes).
Upvote 0