Close
0%
0%

Daft Punk Word Clock

An homage to the legendary electronic duo done as a one-day New Years hack

Similar projects worth following
Once I realized that there were only ever 18 unique words in the song "Harder Faster Better Stronger", turning it into a word clock style display seemed like a fun idea. As a first attempt, I made a prototype using an Adafruit PyBadge development board that I had hanging around from Hackaday Supercon 2019.


Inspiration

I started with the Adafruit PyBadge. This is a 120 MHz ATSAMD51 based board that can be easily reflashed using a variety of UF2 images. I put on the latest stable CircuitPython, 7.0, and updated the .mpy files in the filesystem with the latest compatible version. I'd previously used this to make a personal badge for our last big in-person meeting at my employer, so I had to archive away all the files from that to make a clean slate. I'd also made a case for it from a Thingiverse project earlier in 2021 after getting my 3D printer, so that stayed in place.

Audio Playback

The first thing I needed to get working was the MP3 playback. The original MP3 file for the song was about 7MB, far larger than the 2MB flash storage on the device. However, it also had way too much data for the little speaker on the PyBadge to render, so I loaded it into Audacity, mixed it down to mono, then output it as a low-bitrate VBR MP3 file. This reduced the size to 1.2MB. Later, I would take it further to a 32 Kbps CBR MP3 (880K) as part of optimization.

To play back the audio, CircuitPython has a audiomp3 module that hooks into its playback system. Upon trying it, I found that the volume was extremely loud, I had to setup an audiomixer instance and route it through there for level control. The MP3 decoder has a nice property called rms_level where you can get a recently decoded sample's volume level, and seeing that lead to using the front NeoPixels as a VU meter.

Word Clock

To get the actual word clock working too a lot of manual effort. I found lyrics, separated out all the words onto their own lines, converted to lower case, sorted them, ran a unique filter to remove the duplicates, then went through and looked for any weirdness. In the end, the song has only 19 unique words, with two of those variations that can share space in the clock. I tried for a 8x8 layout, but there wasn't enough room, so with some reorganization, I got the 12 x 7 matrix.

To figure out the cue timing, I went back to Audacity. The tool has a nice feature called a label track, and you can quickly add a label with text for any timestamp in the song. After a couple of hours of scrubbing and tagging, I had a fully marked up song, and the label export provided me with a text file that I was able to massage into a Python data structure. Of course, being Daft Punk, there are parts where the lyrics are so manipulated that I just had to put my hands in the air and give up until something became intelligible again.

In the Python code, I made a WordCloud class that embedded all the cues, the position of each word in the grid, and the grid data itself. The grid is implemented using displayio and adafruit_display_text, using the built-in font, which happens to be 6x12 monospaced. I originally had it all scaled x2, which filled the screen nicely, but I it also caused performance problems, so I ended up unscaled and centered.

The timing is done with a list of cues, each with a timestamp and a list of words to highlight. A lack of words means do no highlights, so I had to add those cues for sections of the song with no lyrics. The code uses the first cue as a trigger to turn off the VU meter and show the word clock.

Performance

Once I got everything together, I hit some real issues that keep this from going to the next level. My demo video cuts off at a certain point on purpose, as after that, the text highlights get more and more synchronized from the music. Increasing the buffer size in the mixer helped a little, but I suspect that the MP3 playback system is running a little slow. I've seen similar issues with presenting closed captions to match video content in my day job. It would be really nice if either the MP3 decoder could provide a position property, indicating how far into the file had been played. With that, I could keep in sync even if playback was a little slow.

Update 1

Good news! I made a patch to CircuitPython, and now audio sync works great....

Read more »

Daft Punk Pybadge (CP 7.2.0.zip

Updated code that uses decoded_samples attribute for audiomp3 added in CircuitPython 7.2

x-zip-compressed - 36.08 MB - 01/03/2022 at 02:21

Download

Daft Punk Pybadge.zip

Python code and asserts to reproduce on your own PyBadge

x-zip-compressed - 36.08 MB - 01/01/2022 at 17:48

Download

  • 1 × Adafruit Pybadge

  • A bug fix for decoded_samples

    Ben Combee01/03/2022 at 02:26 0 comments

    While recording a new video with my sync fix, I noticed a problem that I'd introduced. The decoded_samples count didn't reset to 0 when the file was replayed. This resulted in all of the word clock entries getting replayed almost immediately when the song started. It was a simple fix, and a new pull request was made.

  • Audio sync fixed!

    Ben Combee01/02/2022 at 17:35 0 comments

    I dug into the CircuitPython code a bit yesterday and came up with a pull request for the audiomp3 code. This adds a decoded_samples property that can be used to understand how much of the MP3 file has been played. After plugging that into the word clock code, using it instead of the elapsed monoclock time, sync was perfect for the whole song.  I could even run the double scaled word clock, which looks great on the PyBadge's small screen. There's a little glitchiness during the more complex part of the song, but it's minor and doesn't make it all go sideways. I also took this opportunity to re-enable the VU meter during the wordless parts of the song, which makes it more visually interesting.

    This morning, the PR was accepted, so I think this may be in the next 7.2.0 alpha 2 CircuitPython release. I'm going ahead and updating my project ZIP file with the new source.

View all 2 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates