For fun I recently created an application for the iPhone - iStethoscope which
basically turns the device into a stethoscope, allowing you to listen to your own heartbeat
(or other quiet sounds nearby). I've linked it to The Undercover Scientist book,
using the little scientist cartoon as a friendly way to show (hopefully interesting) facts
related to sound and hearts.
For those interested, here's a little detail about how it works. The program takes audio
from the microphone, buffers it for a very short amount of time and then plays it. Playing is
continuous as new audio is received, so all processing has to be performed on-the-fly as
the data is copied from input to output buffers. Inevitably a small delay results from this
buffering process. Several types of processing happens - a low-pass filter is applied to
remove hiss, a high-pass filter is applied to remove rumble, a heartrate monitor listens and
attempts to count repetitive noises separated by quiet, and an automatic volume control
listens for excessively loud sounds. If a loud noise is detected, the filter parameters are
adjusted to reduce the volume. These adjustments are then slowly returned to normal when
only quieter sounds are detected. The different modes correspond to different filter settings
and different gain settings for the volume control. "Heartbeat" uses a heavy low-pass filter
to let low thuds through but remove most higher- pitched sounds and reduce crackle of
microphone against skin. "Conversation" uses low and high pass filters to let through middle
frequencies like those transmitted by telephones. "Clear Sound" uses minimal filtering to let
most of the sound through unchanged. The heartrate monitor is active in "Mute" and
"Heartbeat" modes. Because it cannot use extreme filtering to make it work better (that
would make it sound awful when listening) it does get a little confused if there is any crackle
or noise. It only displays the pulserate when it is reasonably sure it's right, so you have to
position the microphone carefully to make it work.
Simultaneously to all this on-line processing, the controls are monitored and now and
again the little undercover scientist is animated in a separate concurrent thread. It's all
optimized to work with as little delay as the processor can handle. But if a different program
or operating system process decides to use the processor or audio, this can screw up the
audio buffering and cause minor audio glitches. (If that happens the program should be
restarted to reset the buffering.) The best way to improve speed and avoid problems like this
would be to do all processing in the iPhone audio Digital Signal Processor instead of in
software; unfortunately the API does not permit this.
The application is now freely available on iTunes, just search for "istethoscope" in the
AppStore. Please leave feedback if you download it!
For details about version 1.1 click here.
For details about version 2.0 click here.
The website for the