Halloween Hacks: Scaring small children with Huffman coding

The team over at NerdKits decided they needed to do something for Halloween. Only on Halloween is scaring small children is an admirable goal, so they demoed a way to play creepy sounds after a door has been opened.

To trigger the sound, a magnetic reed switch from an alarm system is attached to a front door. This triggers the microcontroller and with a bit of delay, some creepy audio can be played on a pair of speakers. The team decided to store all the audio data on the flash memory of their ATmega328p, but that wouldn’t allow for a very long scream. To extend the length of the wails of the damned, the NerdKits team decided to use Huffman coded audio.

Because Huffman coding relies on the most common value being assigned the shortest code, the team used a bit of Python and C magic to figure out the optimal encoding for their audio file. After the evil laugh was sufficiently compressed, the microcontroller was programmed to decode the audio and send it to a pair of speakers. The team made all the software for their project available here for your perusal.

Although this project could be thrown together in an hour with an Arduino and an MP3 shield, the NerdKits team wants to get kids to learn how things work, also an admirable goal. [Humberto] from NerdKits put a video up explaining the theory of the project. Check it out after the break.

Comments

  1. Paul says:

    Huffman encoding is great for learning bit-twiddling in C, but Fibonacci-delta compression (4 bits per sample) is a good alternative, and much simpler. Plus, it’s the only practical use of the Fibonacci sequence I know of.

    Used in Amiga 8SVX sound samples BTW.

  2. Nick Johnson says:

    Huffman Coding is far from the best for audio data. ADPCM is just as easy, and a lot more effective.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 93,810 other followers