Closed dpgeorge closed 2 years ago
I noticed that after playing a sound expression, the micro:bit consumes about 2x the power at idle REPL.
Thanks Damien, this is great to start playing with SoundEffects!
I take it the WAVE_
, FX_
, and INTER_
are not get set as audio globals yet?
(Edit: I've just saw the comments on the docs PR, so we can discuss that there 👍 )
Also, playing the default SoundEffect() doesn't produce any sound and seems to crash or freeze:
>>> effect = audio.SoundEffect()
>>> audio.play(effect)
But changing the interpolation to a value other than log works
>>> effect = audio.SoundEffect()
>>> effect.interpolation = 1
>>> audio.play(effect)
>>>
So it might be related to this:
We might need to update CODAL to ensure we've got the latest fixes.
I noticed that after playing a sound expression, the micro:bit consumes about 2x the power at idle REPL.
@JohnVidler any ideas about the larger power consumption?
Also, playing the default SoundEffect() doesn't produce any sound and seems to crash or freeze:
I've now updated CODAL to v0.2.40 and this default works correctly.
I've now updated CODAL to v0.2.40
But I just noticed that the microphone LED is permanently on now and the micro:bit draws 17mA extra compared to CODAL v0.2.35.
And after playing a sound the micro:bit draws 54mA total at an idle REPL (it used to be 20mA at the REPL).
I think maybe using setSilenceLevel()
to setting the "silence level" to zero might have an effect in power consumption.
https://github.com/lancaster-university/codal-microbit-v2/blob/13a651754e668464855fc40a81dd7dcb796b58c9/source/Mixer2.cpp#L370
@JohnVidler do you have any suggestions or insight about the additional power consumption in the latest CODAL releases?
Not had any cycles to investigate the power consumption yet, but my best guess would be that the audio pipline is being turned on, and left running after the initial playback, perhaps? Or that the speaker pin is being pulled strongly high/low at the end of playback rather than going back to floating when no data is present.
In either case, consider this on my radar.
TODO:
preset
arg to constructorcopy
method_from_string
class/static method for testingI think I'd also add that we'd like __repr__
to contain positional arguments to keep the string short, and it'd be useful to have __str__
with the keyword arguments, so that users can read the values:
>>> se = SoundEffect()
>>> se
SoundEffect(500, 2500, 500, 255, 0, 3, 0, 18)
>>> print(se)
SoundEffect(freq_start=500, freq_end=2500, duration=500, vol_start=255, vol_end=0, wave=WAVE_SQUARE, fx=None, interpolation=INTER_LOG)
Quick thing I've found, setting the volume to a value n
results in n-1
being set:
>>> se = audio.SoundEffect(vol_start=150)
>>> se.vol_start
149
>>> se.vol_start = 200
>>> se.vol_start
199
>>>
Do we want to rename interpolation
to shape
?
Yes, let's rename interpolation
to shape
👍
Need to also think about the default settings for the following parameters which are not exposed by the API here:
The value of steps makes a difference for the default sound.
Quick thing I've found, setting the volume to a value
n
results inn-1
being set:
This was a rounding error converting between a range of 255 and 1023. Now fixed.
Implemented support for playing a tuple/list of SoundEffect
instances.
This is an initial implementation of the
SoundEffect
class, per #103.As a way to facilitate debugging/experimentation, the
SoundEffect
constructor can take a 72-length string as thepreset
value, which is interpreted as a CODAL sound expression string.The following example will play the GIGGLE sound (string data taken directly from CODAL source):
Output:
Limitations:
SoundEffect
objectswait=False
and another one is started then the first one will be stopped immediately