[enh] PCM stream should convert to List<int>
See original GitHub issueHi,
I am trying to stream in near-realtime from the recorder (mic) to the player(headsets) - like many people, it seems 😃. I started from the streamLoop example, easy and cool.
My next-step: to add the processing in the middle. I take the uint8list from buffer.data and after converting to int16list I do the processing on it and back. I tried to use Codec.pcm16WAV, reason: when using Codec.pcm16, the processing itself in the middle works fine but in the headsets I got only a terrible ?white? noise mixed with silence. I really have no idea about the reasons…
I know the processing step itself is ok, and I think that it should work fine with pcm16WAV. I don’t know why with Codec.pcm16 I get this very -strange- behavior… I did a test with a classic wav file recorded from the phone but not with this library, and processing+playing worked without issues… but I would need to do the same in real-time with the stream.
I attach a mediainfo report of the file that worked with (played correctly from assets, with the processing in the middle):
Format : Wave
File size : 175 KiB
Duration : 4 s 63 ms
Overall bit rate mode : Constant
Overall bit rate : 353 kb/s
Format : PCM
Format settings : Little / Signed
Codec ID : 1
Duration : 4 s 63 ms
Bit rate mode : Constant
Bit rate : 352.8 kb/s
Channel(s) : 1 channel
Sampling rate : 22.05 kHz
Bit depth : 16 bits
Stream size : 175 KiB (100%)
I opened this file with basic code+minor mods of liveplayback.dart, with codec.pcm16(!) set to the player. This last result confused me.
After a bunch of shady errors I found that the record-to-stream feature is available only for pcm16 (nice to have: a 2words-note about that in the docs in that section, didn’t find any!). I don’t know why the app did not throw the exception in the flutter_sound_recorder.dart (245):
if (toStream != null && codec != Codec.pcm16)
throw Exception ('toStream can only be used with codec == Codec.pcm16');
Error I got instead (partial):
E/flutter (32427): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(ERR_UNKNOWN, ERR_UNKNOWN, startPlayer() error, null) E/flutter (32427): #0 StandardMethodCodec.decodeEnvelope package:flutter/…/services/message_codecs.dart:582 E/flutter (32427): #1 MethodChannel._invokeMethod package:flutter/…/services/platform_channel.dart:159 E/flutter (…
Why there is such ‘limit’ on the codec when using record-to-stream? Do you think there’s any way to fix/improve that by library’s side? Do you have any suggestion for this use case?
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:12
Top GitHub Comments
Yes, I agree with you : StartRecorder should return :
I am currently working on an upgrade of the Flutter Sound API. It will be Flutter Sound Version 9.0.x
With this new version, I want to implement various PCM format (mono/stereo, 8/16 bits width, little/big endian, integer/float). And the App will receive a correct List < something >
I cannot say when this new API will be released. Probably I will release a beta version during september.
I’m also trying understand why as a stream we do receive Uint8List instead of Uint16List as we are using pcm16 with 16bit depth. My first thought was maybe Uint16 is split into two Uint8, but it was not the case with combining two Uint8 values as recorded audio on playback got two times faster.