-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add setSampleRange()
to StreamSplitter
to match Mixer2::setSampleRange()
#393
Comments
The StreamNormalizer already has the functionality for this - if you create a new Normalizer attached to the incoming mic stream from the splitter, you can alter the stream format to any other one: https://github.com/lancaster-university/codal-core/blob/master/inc/streams/StreamNormalizer.h#L71C92-L71C92
Doing it this way also gives you a per-channel gain control, for local volume changes. |
OK, thanks for that, I didn't know about Actually, it depends on the outcome of #395, how this issue here will be solved. For example it may be that |
MicroPython's use-case is still not satisfied, because switching to This is not really a problem because it's a pretty simple loop to make this range adjustment. Using a So, I'm happy to close this as "not needed". |
Technically if very specific formats and rates are needed on a channel, it is possible to chain: However, it may be possible to just set the format up on the However, that'll only work without loss if we stick to 8-bit sample ranges, (signed/unsigned), because up at the microphone we already scale the output samples to that range, anything larger will just lose information in a rescale operation. So more generally we should provide a mechanism to set the microphone properties in similar/identical ways to the mixer, ideally. Personally I think its time that the microphone driver is actually split out to be a component attached to an arbitrary ADC, then it can have any combination of parameters set, and we can multiplex the ADC into multiple virtual 'microphone's if we need very specific properties on each. This will need the driver(s) to share control of the microphone power lines, but that's not too tricky to implement. @microbit-carlos and @finneyj I'd love to hear your thoughts on this - it would mostly just involve a refactor of some portion of I don't think this would break any downstream code, but its worth us checking as well. |
Thanks @JohnVidler. Personally I'd keep it simple. There'll be a copy operation into the micropython allocated memory at some point anyway (unless we unify the heap allocators, as we do in MakeCode). So simplest just to accept a standard ManagedBuffer into the micropython side shim code and then copy there. I'm not quite sure why Damien's attempt to get an unsigned 8 bit buffer didn't work though. That sounds like it could be a bug? In which case we could just squash that bug and declare success? |
@dpgeorge Do you have some code I can take a look at for where this falls over? Then I can perhaps come up with a CODAL MWE for you? |
@JohnVidler you'll need to check out the Then look at the file // Convert signed 8-bit to unsigned 8-bit data.
for (size_t i = 0; i < n; ++i) {
pull_buf[i] += 128;
} That's a pretty simple loop. That loop could be removed if the conversion was done somewhere/somehow by CODAL. |
From the Codal Sync today, we suggest that we promote a new global variable for the system-default audio format, so that it can be updated as part of the build config, but we also have a If this is changed at runtime you might get a bit of a 'bump' from the level detector at the point of the change, but everything else should be happy with the format change. I'll create the above global config variable for the format on startup, but could you (@dpgeorge ) please let us know if there are any strange effects on any other part of the pipeline after making the change in format. |
It's currently possible to set the sample range for output streams (producing sound on the speaker) using
Mixer2::setSampleRange()
, and also in theaddChannel()
method as the third argument.We use this in MicroPython to set the sample range to 255, which, in combination with
DATASTREAM_FORMAT_8BIT_UNSIGNED
, allows samples to be in the range 0-255, with a silent/idle value of 128.But when recording sound from the microphone it doesn't seem possible to configure the sample range, and using
DATASTREAM_FORMAT_8BIT_UNSIGNED
as the format still results in samples that range -128 to 127.So I propose adding
StreamSplitter::setSampleRange()
, and/or the ability to pass in the sample range toStreamSplitter::createChannel()
when creating the channel.The text was updated successfully, but these errors were encountered: