Android Question AudioStreamer clarification/java method access

OliverA

Expert
Licensed User
Longtime User
In the library post "Audio library v1.5 - New AudioStreamer object", it states
The purpose of AudioStreamer is to make it simple to stream audio from the microphone and to the speakers. Internally it is based on AudioTrack and MediaRecorder.
I'm not 100% convinced that MediaRecorder is used to record the audio, but that instead AudioRecord is used. The only reason I'm speculating for AudioRecord is that AudioRecord supports the same encodings as AudioTrack, but MediaRecorder seems to support none of the encodings that AudioTrack understands.

If I happen to be correct that AudioRecord is used, how can I access the underlying getMinBufferSize? And is this the size used in AudioRecord's constructor?

As to AudioStreamer's PlayerBufferSize property, is it equivalent to AudioTrack's getMinBufferSize?

AudioRecord encoding formats: https://developer.android.com/reference/android/media/AudioRecord.html#getAudioFormat()
AudioTrack encoding formats: https://developer.android.com/reference/android/media/AudioTrack.html#getAudioFormat()
MediaRecorder encoding formats: https://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder
AudioRecord getMinBufferSize: https://developer.android.com/reference/android/media/AudioRecord.html#getMinBufferSize(int, int, int)
AudioRecord constructor: https://developer.android.com/reference/android/media/AudioRecord.html#AudioRecord(int, int, int, int, int)
AudioTrack getMinBufferSize: https://developer.android.com/refer...dioTrack.html#getMinBufferSize(int, int, int)
 

OliverA

Expert
Licensed User
Longtime User
If I happen to be correct that AudioRecord is used, how can I access the underlying getMinBufferSize?
Just in case someone else needs it
B4X:
Dim joAudioFormat As JavaObject
joAudioFormat = joAudioFormat.InitializeStatic("android.media.AudioFormat")
Dim joAudioRecord As JavaObject
joAudioRecord = joAudioRecord.InitializeStatic("android.media.AudioRecord")

Dim sampleRate as Int = 8000
Dim channelConfig as Int = joAudioFormat.GetField("CHANNEL_IN_MONO")
'Dim channelConfig as Int = joAudioFormat.GetField("CHANNEL_IN_STEREO")
Dim audioFormat as Int = joAudioFormat.GetField("ENCODING_PCM_16BIT")
'Dim audioFormat as Int = joAudioFormat.GetField("ENCODING_PCM_8BIT")

Dim buffSize As Int = joAudioRecord.RunMethod("getMinBufferSize", Array As Object (sampleRate, channelConfig, audioFormat))
Log(buffSize)
 
Upvote 0
Top