microsoft / microsoft/pxt-microbit
Tones have audible click if stringPlayable value is too long
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 804
- Forks
- 721
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 2
Description
Describe the bug
The audio in the simulator starts becoming more and more crunched and clicky if the value inside music.stringPlayable is too long (well over 8 notes).
To Reproduce
See project: https://makecode.microbit.org/S15391-85779-51473-58196
Expected behavior
Clear sound.
micro:bit version: Not hardware related.
Desktop:
- OS: Windows 11
- Browser: Firefox
- Version: 143.0.1
Additional context
I did find a workaround for the moment. I split up the notes into groups of multiple lines, with 8 notes per line. It still begins to lag if I play it in whole groups. So to fix that, I split it further at runtime by spaces.
parts[part].split('\n').forEach(bars => bars.split(' ').forEach(
note => music.play(music.stringPlayable(note, bpm),
music.PlaybackMode.UntilDone)
)
The weird tempo math in the example is due to the tool I used to convert a MIDI to notes and is unrelated to this issue. I fixed that issue by writing the notes by hand in another project.
Here is that project that doesn't crackle and runs in time: https://makecode.microbit.org/S52364-91538-71429-16712
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the linked MakeCode projects using a long value passed to music.stringPlayable, then compare it with the project that splits notes into smaller groups. Trace how long note strings are handled in the simulator and verify that extended playback produces clear, non-clicking audio without lag.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- embedded-iot, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100