lancaster-university / codal-microbit-v2

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

The value of LEVEL_DETECTOR_SPL_8BIT_000_POINT (32) will never be reached #449

Open microbit-carlos opened 1 month ago

microbit-carlos commented 1 month ago

Because the LevelDetectorSPL minVal is set to 52: https://github.com/lancaster-university/codal-microbit-v2/blob/bd446c49f5501584e2cef3b5f53ebb826928e47b/source/MicroBitAudio.cpp#L82

And LevelDetectorSPL will clamp the lower end of the level value to minVal: https://github.com/lancaster-university/codal-core/blob/509086cc8590465041b15493ab52b56e7071c110/source/streams/LevelDetectorSPL.cpp#L142-L147

microbit-carlos commented 1 month ago

PR created in codal-core:

MakeCode and MicroPython already use this value, so it shouldn't have an impact there

microbit-carlos commented 1 month ago

Previous discussion:

When LEVEL_DETECTOR_SPL_8BIT_000_POINT was introduced it was set to 35.0, but the default value for LevelDetectorSPL.minVal was already set to 52.0, so with the default values LevelDetectorSPL.getLevel() would have never return a value below 52 dB:

However, at that time, the uBit.audio.levelSPL constructor in codal-microbit-v2 was setting minVal to 0, it was only changed to 52.0 a year later, so until then uBit.audio.levelSPL->getValue() could return values lower than 52.0, and that explains why earlier measurements could detect 35-40ish dB: https://github.com/lancaster-university/codal-microbit-v2/commit/02a85fa86a00ac204cbd2a4caacd5a964e1cf26e