Poor Man's Theremin

January 28th, 2003 by Don Marti in

Here's how you can play music with your wireless network card.
Your rating: None

If you're interested in gaining some experience playing the theremin but don't want to spend a lot of money or build the kit, try the “Poor Man's Theremin” (PMT), written by Seth David Schoen.

The PMT turns a laptop computer with an 802.11b card into a theremin-like instrument, using the signal strength reported by the card to control the pitch of a note. To try it, first compile this C program, called ttone, using the command cc -o ttone -lm ttone.c.

Listing 1: ttone.c
#include <math.h>
#include <linux/kd.h>
const int A = 440;
const float r = 1.05946;
int pitch(int base, int observed){
    return (int) A * pow(r, (observed-base));
    }
int main(int argc, char *argv[]){
    int base, observed;
    if (strcmp("off", argv[1])){
        base = atoi(argv[1]);
        observed = atoi(argv[2]);
        ioctl(0, KIOCSOUND, 1190000 / pitch(base, observed) );
    } else {
        ioctl(0, KIOCSOUND, 0);
    };
}

Put the ttone executable in a directory that's in your PATH.

Now run the following shell script, called pmt.sh, and move into range of an 802.11b access point. You can change the pitch by moving closer to or further away from the access point or by moving your hand over the 802.11b antenna in a theremin-player-like manner.

Listing 2: pmt.sh
#!/bin/sh
# Poor Man's Theremin
m=100
oldQ=foo
[ $1 ] && m=$1
while :
do
Q=$(iwconfig 2</dev/null | grep Link.Quality | cut -d: -f2 | cut -d/ -f1)
if [ $oldQ != $Q ]
then
    ./ttone $m $Q
    fi
    oldQ=$Q
    done

The Poor Man's Theremin does not have the volume control of a proper theremin, and the pitch changes in discrete steps instead of continuously. Implementing these features is left as an exercise for the reader.

Don Marti is editor in chief of Linux Journal.

__________________________


Special Magazine Offer -- 2 Free Trial Issues!
Receive 2 free trial issues of Linux Journal as well as instant online access to current and past issues. There's NO RISK and NO OBLIGATION to buy. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Sorry, offer available in the US only. International orders, click here.

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Featured Videos

The October 9, 2008 edition of Linux Journal Live! Associate Editor, Shawn Powers, and Kyle Rankin, "Hack and /" columnist and author of Knoppix Hacks, Linux Multimedia Hacks, Knoppix Pocket Reference and others, discuss Linux distributions.

The October 2, 2008 edition of Linux Journal Live! Associate Editor, Shawn Powers, and Steven Evatt, Online Development manager for The Houston Chronicle discuss surviving disaster with Linux.

From the Magazine

November 2008, #175

There aren't many numbers that put the US national debt to shame, but here's one: 1,100,000,000,000,000. What's that? That's how many floating-point operations per second the Roadrunner supercomputer at Las Alamos can perform. That's about 100 FLOPS per dollar of US debt (unfortunately, the debt is winning the second derivative race). Read the article about Roadrunner in this month's High Performance Computing issue of LJ.

Along with that, find out how to program the Cell processor and how to use CUDA with your NVIDIA GPU. Also in this issue: Mr HandS (aka Kyle Rankin) gives us a few tips on using Compiz, Chef Marcel shows you how to get blogging off your plate quicker, Mick Bauer talks about Samba security, Dan Sawyer interviews Cory Doctrow and Doc talks about how information technology can affect democracy and fix the national debt (just kidding about that last part). That and more for your reading pleasure in this month's Linux Journal.

Read this issue