Sounds of some sorts


Earlier this week, I came across this youtube video that illustrated various sorting algorithms with sound effects. Unfortunately, it was a video and not a live demo.
I picked up the baton and decided to play around with HTML5 audio and see if I could get a live demo out. Unfortunately the Audio API can only playback audio files, there is no support for generating sounds yet. I decided to pick up some audio files from the Piano and Drum beat examples. I was able to find 12 unique sound files, and associate them to each value in the sample input.
The tricky part was to keep the code for the algorithms while allowing the animations and sound effects have time delays. I wrote a couple of basic functions like greater() and swap() that were called for comparisons and swapping values in the algorithm. They also added the required animation/sound effect to a queue that played asynchronously till the queue was empty.
There you have it; the sounds of some sorting algorithms. The web page is available here.
I was also exploring the additions to the audio API that were proposed and are a part of Firefox 4. It has interesting way to not only playback audio files but also generate audio. Next step - try to see if I can have larger samples and generate sounds for them !!
Watch out this space for updates.