Closed chi-tea-72 closed 4 years ago
Hello,
shortOut
is the number of 16-bit items => we'll need shortOut * 2
of 8-bit items to store the same amount of data.
Ok thanks for the response. I think I understand now.
So here you're taking the Uint8List you passed over the method channel and converting into a short ByteBuffer: https://github.com/CasperPas/flutter-sound-stream/blob/7948a871d0dd6e408f702b9f18bb146032e56266/android/src/main/kotlin/vn/casperpas/sound_stream/SoundStreamPlugin.kt#L338 to be able to playback the 16 bit values correctly.
If my understanding is correct, I should be able to do something similar in Dart like Uint16List.view(theUint8ListChunk.buffer)
to get the correct list of 16-bit integers to pass to my function that expects 16-bit pcm?
yes, theoretically, it should works
Hello,
I'm not super familiar with audio so I wanted to ask two questions:
1) I have a function that expects 16-bit pcm data. In the conversion from shortArray (Kotlin) to Uint8List (dart) due to that limitation you mention, are you losing audio data (going from 16-bits to 8-bits), or is it spread across a pair of indices in the Uint8List, or something else?
2) I was wondering if making this line: https://github.com/CasperPas/flutter-sound-stream/blob/7948a871d0dd6e408f702b9f18bb146032e56266/lib/recorder_stream.dart#L46 an Int32List instead would still work?
I'm not super familiar with Kotlin, but this line: https://github.com/CasperPas/flutter-sound-stream/blob/7948a871d0dd6e408f702b9f18bb146032e56266/android/src/main/kotlin/vn/casperpas/sound_stream/SoundStreamPlugin.kt#L390 kind of looks like you may be allocating 32 bits here and then packing the lower bits with the audio data? If so, then maybe using a method like asInt16List with an offset of 2 would get the desired 16 bit number: https://api.dart.dev/stable/2.8.4/dart-typed_data/ByteBuffer/asInt16List.html?
Thanks