Unlike most of the projects I've written about here, this project was actually for class credit. I'm in a course called Engineers and Orchestra, where we have been studying the physics of sound and oscillation, and using these principles to build physical instruments. I was curious about how sound is represented on a computer, so for one of the open-ended projects, I set off learning a lot about digital audio. The first step was to learn the insides of a .wav file -- I challenged myself to write a song into a valid .wav file from scratch, starting from only bytes. My next project for the class was to write an audio editor!
The GUI isn't very good, but I have most of the important features covered: Adding Silence, Cut, Append File, Mix File, Modulate, Make Louder, Make Softer. It loads and saves standard wav files (16 bit or 8bit), so it is actually practical for editing things you have recorded.
I wrote everything without referencing the code of any other audio editor like Audacity. The unexpected benefit is that when I got something wrong, I sometimes stumbled upon an interesting-sounding other audio effect. (See for example my Alien Voice effect). In the GUI, you can use the following effects: Reverse, Octave up/down, Change pitch (the most challenging to think of how to write), Vibrato, Flanger, Echo, Reverb, Chorus, and Alien Voice (which modulates the samples with a sine wave).
I added code to synthesize sounds. Sine, triangle, square, and sawtooth waves aren't that great by themselves, so I tried combinations of them to get the most interesting voices. The way to make a sine wave sound better is to quietly mix in frequencies at that are slightly different. Surprisingly, the subtle beat frequencies make it sound more expressive and musical. I worked a long time to create an electric organ-like instrument out of sine waves, and finally came up with something.
Some examples generated by my program:
Electric Organ
Retro
Red Noise
Vibrato
Reverb
I put all of the pieces together: I had an audio editor that can modify and arbitrarily change the pitches of sounds.
Does this still qualify as a half hour hack, given that I did it for a course? Well, it's certainly not polished code. This is not a joke, it is actually in the source:
Maybe a bit longer than PEP-8's recommended maximum line length of 80 characters :)
I've posted the source at GitHub, released under the GPLv3.
Next post: Typing Non-Latin Letters