One thing I really missed in the first few years of being at grad school was the feeling of working on something useful. Of course, I was working on my own research, but I couldn’t escape the thought that I was working my way into an ivory tower. So, in order maintain my ability as a developer (and in doing so, hold on to whatever shreds of sanity I could grasp), I turned to freelancing.
It wasn’t easy at the start. In fact, despite reaching completion, the first project was a bit of a disaster (perhaps I’ll talk about that another time). Eventually, however, I found my niche and got to work on some really interesting projects, one of which is the topic of this entry.
The client wanted a library that detected the tones in a DTMF signal. The name may mean nothing to you, but if you’ve ever used an old-school touch-type telephone, you’ve heard these tones. They are the sounds the phone makes when you press any of the keys. If the other side of your telephone conversation happens to be a machine, then it can listen to the tones and determine which keys you’re pressing.
If you still don’t have any idea about what a DTMF tone is, endulge your ears in this:
Needless to say, this technology has been around for decades, but for whatever reason unknown to me, the client wanted their own library written from scratch. As a starting point for my work, I found a solid open-source DTMF library on sourceforge. It worked extremely well (according to the author, whom I contacted in person later, the library had been deployed to many automatic telephone exchanges) but suffered from a show-stopping problem for the client: it only worked for audio signals sampled at a single frequency (8 KHz). I took it upon myself to go through and understand the source code of the library as much as possible before setting out to implement my own. Unfortunately, the code wasn’t particularly easy to understand in places and there were very few comments. Magic numbers were all over the place without any explanation of their origin or significance.
I did my best to understand the library through eyeballing the code and running it over some sample input, reading relevant literature, etc. but in the end I had to contact the author (who happened to speak Russian) for some explanation. Luckily, I promptly received a reply and was able to fill the holes in my understanding.
I can’t share the final result with you because the client owns the source code, but I did put up the original library with my comments on github. There is a slightly interesting demo that illustrates the frequencies detected in a particular waveform.