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

uint8 is inadequate to represent the intensity of the sound. #58

Closed yama-yeah closed 1 year ago

yama-yeah commented 1 year ago

If the bit depth is set to 16, the uint8, which can only represent up to 2^8, seems inadequate because it must represent values up to 2^16. In short, I think we need to change the return value of MicStream.microphone to Future<Stream\?>.

anarchuser commented 1 year ago

I'm aware of this issue but there is no trivial solution. Changing the return stream to a Stream<Uint16List> compromises performance when using 8 bit PCM. Instead, I chose to return the stream from the native backend as-is, meaning for 16 bit PCM every Uint16 is split into two consecutive Uint8 that need to be reassembled by the user.

When Dart as a language has matured enough, I hope to get rid of this annoyance. But right now, not doing any preprocessing on my side is the cleanest choice.

yama-yeah commented 1 year ago

Thank you for your prompt reply. I understood it was due to Dart's specifications. Thanks for the great package!