Hello,
I am using Microblocks to code the micro:bits with my middle school students. I have discovered how to import and play ringtones using the ringtones library. There is a WAV library also in Microblocks but I cannot figure out how to import a WAV file into Microblocks.
I think it would make micro:bit projects much more compelling if different sounds could be played.
I would greatly appreciate any help here.
bkahn,
Playing WAV files in MicroBlocks requires a board with a DAC chip; micro:bit does not have a DAC chip. DAC support can be verified by looking at the tech specs of the board. Adafruit boards: ItsyBitsy MO, Trinket MO, Gemma MO come to mind; also M5Stack, and others.
Then to load a file easily, it needs to be able to support a flash file system. In that case, one can enable menu command under Settings/show advanced. This will make the file put and get commands become visible. Use the file put command to copy a WAV file onto the board flash file system.
Once all this is done, you can use the WAV library to play the file by specifying the full file name, eg: zoop.wav.
A few things to keep in mind:
There are other ways to load files onto boards with flash file systems. But the method mentioned is the easiest way.
Speaker pins supported under the WAV play function is 25 and 26. If the board you are using has a different speaker pin number, you might have to change the pin number in the block.
WAV files come in different internal formats. The particular version play is looking for is RIFF. You can easily see this if you open the file in ie Notepad++:
I made an audio playback "proof of concept" project.
Raw samples are played trough analog output (PWM@27, buzzer) of micro:bit v2 when button A is pressed.
There is also a Snap! "loader" project.
Sound samples from the Snap! project are prepared (downsampled normalized, scaled) and transmitted to Microblocks VM with broadcast over USB connection (I'm not aware of any other method to set large binary object for microbit projects). SmallVM serial protocol
Yeees... It's a shame, but for the simplicity, there is no flow control of any kind ;(
At least playback delay control and reset buffer should be implemented e.g. by broadcasting of the short packet.
Snap! project, with the "ratio" set to 10, prepares data ~@5kHz sample rate (so a delay of 200 mikrosec is applied during playback). To ensure simple, flawless data transfer, bytes are further scaled to <128.
I was testing some, naive, downsampling/low pass algorithms - average over the range and every (1/ratio)th sample, but can't choose the better one.