lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
41 stars 50 forks source link

How to warm up the `uBit.audio.levelSPL` to avoid delays when calling `uBit.audio.levelSPL->getValue()` #361

Closed microbit-carlos closed 11 months ago

microbit-carlos commented 11 months ago

The current behaviour of uBit.audio.levelSPL->getValue() is to block until the has been enough buffers collected to provide correct data. This is good, but it also means the first call to this method can take up to 80 ms to return.

We'd like to reduce this as part of factory tests, so I wanted to check what is the CODAL-recommended way to warm up the pipeline.

uBit.audio.enable() only set up the audio output, and while uBit.audio.activateMic() enables the microphone, it doesn't look like it warms up the levelSPL buffers. Adding any delay between uBit.audio.activateMic() and uBit.audio.levelSPL->getValue() doesn't reduce the time it takes for uBit.audio.levelSPL->getValue() to return. So, basically:

uBit.audio.levelSPL->activateForEvents(true) seems to work, but I am not sure if this is the best, or preferred, way to do it.

@JohnVidler any thoughts?

microbit-carlos commented 11 months ago

Discussed with @JohnVidler and the current method would be uBit.audio.levelSPL->activateForEvents(true) as it is not worth adding an user API for this specific feature.