Wish AudioStreamer: 2 additional methods and 1 additional property

OliverA

Expert
Licensed User
I wish for 1 additional read-only property:
1) RecordBufferSize As Int
This should contain the buffer size that AudioStreamer uses to conduct the recordings.

I wish for two additional methods for AudioStreamer:
1) StartRecording2(Size As Int)
Where Size is the amount of bytes AudioStreamer should read when using AudioRecord's read method. If Size is < 1 or > RecordBufferSize, then either throw/return an error or just use RecordBufferSize. Why is this needed? In VOIP applications, the time it takes to record a voice sample, transfer it across the network and play it on the other end should be less than 150ms (see https://www.voip-info.org/qos/). It looks like AudioRecord's read method is blocking (see https://stackoverflow.com/questions...n-it-ever-read-more-data-than-has-been-record and https://stackoverflow.com/questions/4569421/problem-of-read-method-in-audiorecord-class). For most phones that may not be an issue. For example, if a phone has a minimum recording buffer requirement of 640 bytes, and the recording audio settings are 8000 Hertz, 16 bit PCM, Mono, the recording will block for up to 40ms to retrieve the necessary data. That would leave 110ms to pack up the data, sent it across the network and play it on the other end. It looks like some phones may have larger buffers, with one case being 2024 bytes. That would take roughly 126ms to read, leaving only 24ms left to for sending and playback. By allowing one to tell AudioStreamer how much to read from the initially set recording buffer, one would gain better control/more consistent control over the delays that may occur in VOIP on various phones with their various buffer sizes.

2) Write2(Data() as Byte, Offset as Int, Length as Int)
When using UDP, this method would keep me from using ByteConverter to write the incoming UDP's backet into another Byte array before playing it. In other words, instead of code like this:
B4X:
Sub UDP_PacketArrived (Packet As UDPPacket)
       Dim buffer(Packet.Length) As Byte
       bc.ArrayCopy(Packet.Data,Packet.Offset,buffer,0,Packet.Length)
       audioStream.Write(buffer)
End Sub
I could just write
B4X:
Sub UDP_PacketArrived (Packet As UDPPacket)
       audioStream.Write2(Packet.Data,Packet.Offset,Packet.Length)
End Sub
without needing to allocate an intermediate buffer.
 

OliverA

Expert
Licensed User
You can override recordBuffer with a new array with the help of Reflector.
Now that I know the object's name, that will also take care of RecordBufferSize, since I can just get the buffer, check it's length and then overwrite it. Thank you! I'll post a code snippet in the code snippets forum once I have something working, just in case someone else is interested/in need of this functionality.

Better late than never: https://www.b4x.com/android/forum/t...of-setting-the-buffersize.101331/#post-636483
 
Last edited:
Top