In this post about The Fast Fourier Transform, I described how simple it was to create a filter to remove unwanted sound from a WAV file. In order to do that, I needed some code to read and write a WAV file. Then I used the FFT to convert to the frequency domain, do a simple convolution (which in this case was trivial: multiply by 1 or 0 if the frequency was outside/inside the desired range), then do an inverse FFT.
The format of a WAV file is fairly simple. There is a header with some waveform information and then the raw data, typically in Pulse Code Modulated form. PCM is just a digitized representation of the waveform, like an amplitude vs time graph. The number of bits per sample indicates the number of discrete levels of amplitude, also known as the dynamic range
I remembered that Sound Recorder allows you to do primitive editing of WAV files, and it also has a feature to mix WAV files together. I used these features to record my voice and mix it with a 2048 hz sine wave to make a “noisy” sample input wave form. The goal was to write code to filter out the “noise”. Creating a sine wave WAV file is easy: just modify the code that writes the WAV file to output a sine wave.
Making your voice sound like the chipmunks is simple: just change the sampling frequency
You can do tricks like
(I was trying to find the built in microphone on my Toshiba Portege M200, but couldn’t find it in the documentation or the interactive tour. So I started trusty old Windows Sound Recorder (sndrec32.exe) and blew on some of the candidate holes I could find. Sure enough, there are a couple tiny holes at the bottom (when in non-tablet mode) of the screen )
Experiment with changing the filter parameters: frequency (nMid) and range (nRange).
Also, experiment with changing the FFT code itself: change a “+” to a “-“ to hear the result!
Here is a link to the source code
Here is a link to the sample FoxRocks.Wav file (It will open in whatever app is associated with the WAV file extension on your machine: Windows Media Player, for example. Just choose “File->Save As” to save it locally. Or you can right click on the link and choose File->Save Target as)