/ Analogpixel / project

Ba Dum Tish Machine

May 10, 2020

You know, the sound the drummer makes when someone tells a bad joke? It’s hack week at work, and my co-workers love to tell bad puns, so I’m making a little Ba-Dum-Tish machine to activate when they tell a bad pun.

I have have a few options for how to play the sound, but I wanted to experiment with the “simplest” which for me means, a single arduino that is able to just play the sound. I have some backups which include a board designed to play wav files when triggered, but if all goes to plan, i’ll be able to just use a stock arduino to do this.

Playing the audio

to play the audio, i’m using the PCM audio library. initially I tried to just use delay statements but that just ended up in static coming out of the speaker (I might look into this again later, as it could have just been me using the incorrect timing for 8k audio.)

Converting the audio

Converting the audio is pretty easy. Once you get some 8k mono audio (about 2 seconds) you take the wave file which is a bunch of points in time at different values, and then convert those values to the range the arduino understands which is between 0 and 255. So you get the min and max values from the wav file, and then use a translate function to translate all those points into the range of 0 to 255.

Once you get all those values, you create an array and store it in the Arduino’s program memory (variable memory isn’t big enough for this.)

img img img img img img img img img img img img img

All the code and files can be found on Github