mic_stream icon indicating copy to clipboard operation
mic_stream copied to clipboard

buffer time (size) configuration

Open renanyoy opened this issue 1 year ago • 5 comments

for now the buffer seems to be set at 200 milliseconds (at 44100). I would like to use mic_stream to do real time things would be nice if we could setup the buffer size in milliseconds as config parameter. for example in my case at 20ms for a 60 fps renderer

renanyoy avatar Jun 28 '23 07:06 renanyoy

Sorry, the buffer size gets decided by the native libraries themselves. You can have a look at the documentation of your platform of choice and find out whether there is any way to change it there. If you do find something we can integrate it.

anarchuser avatar Jul 10 '23 07:07 anarchuser

I forked mic_stream and patched it with a fixed buffer at 512 bytes for both iOS and Android. it works well.

https://github.com/aestesis/mic_stream

on android I had some doubts it could work cause of AudioRecord.getMinBufferSize but I just ignore its result and it works ;)

renanyoy avatar Jul 10 '23 08:07 renanyoy

btw, I use this code to transform the pcm values in float

    for (int i = 0; i < data.length; i += 2) {
      final int v0 = (data[i]) + (data[i + 1] << 8);
      final int value = v0 > 32767 ? v0 - 65536 : v0;
      final double vs = value / 32768.0;
      ...
}

I thing there is maybe a bug in your example

renanyoy avatar Jul 10 '23 09:07 renanyoy

a fixed buffer size certainly works to some degree. I need to test it to ensure it doesn't misbehave, though.

anarchuser avatar Jul 10 '23 10:07 anarchuser

also yes, the example isn't exactly good code. Feel free to improve it if you enjoy it.

anarchuser avatar Jul 10 '23 10:07 anarchuser