# 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.

## 4 thoughts on “Halloween Hacks: Scaring Small Children With Huffman Coding”

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.

1. Do you have any links for further reading on this Fibonacci-delta compression?

2. I’m guessing from context that fibonacci-delta compression is a form of DPCM. ADPCM is only slightly harder, and gives better quality.

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

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.