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:
This takes ~80ms: uBit.audio.activateMic(); uBit.audio.levelSPL->getValue()
This takes ~580ms: uBit.audio.activateMic(); uBit.sleep(500); uBit.audio.levelSPL->getValue()
uBit.audio.levelSPL->activateForEvents(true) seems to work, but I am not sure if this is the best, or preferred, way to do it.
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.
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 whileuBit.audio.activateMic()
enables the microphone, it doesn't look like it warms up thelevelSPL
buffers. Adding any delay betweenuBit.audio.activateMic()
anduBit.audio.levelSPL->getValue()
doesn't reduce the time it takes foruBit.audio.levelSPL->getValue()
to return. So, basically:uBit.audio.activateMic(); uBit.audio.levelSPL->getValue()
uBit.audio.activateMic(); uBit.sleep(500); uBit.audio.levelSPL->getValue()
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?