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.
[youtube=http://www.youtube.com/watch?v=mE-kCSjbauw&w=470]
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.
Do you have any links for further reading on this Fibonacci-delta compression?
I’m guessing from context that fibonacci-delta compression is a form of DPCM. ADPCM is only slightly harder, and gives better quality.
Huffman Coding is far from the best for audio data. ADPCM is just as easy, and a lot more effective.