anarchuser / mic_stream

Flutter plugin to get an infinite audio stream from the microphone
https://pub.dev/packages/mic_stream
GNU General Public License v3.0
100 stars 68 forks source link

buffer time (size) configuration #70

Open renanyoy opened 1 year ago

renanyoy commented 1 year ago

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

anarchuser commented 1 year ago

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.

renanyoy commented 1 year ago

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 commented 1 year ago

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

anarchuser commented 1 year ago

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

anarchuser commented 1 year ago

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