SourceFiles.org - Use the Source, Luke
Home | Register | News | Forums | Guide | MyLinks | Bookmark

Related Sites

Latest News
  General News
  Reviews
  Press Releases
  Software
  Hardware
  Security
  Tutorials
  Off Topic


Back to files

G S T R I N G

(by Sam Tannous, stannous@employees.org)

(Note: If you want to use this application, you must first select the sound card microphone as the input device and raise recording volume. The easiest way to do this is to use a mixer (like xmixer)).

Changes

June 10, 1999 Many performance changes made. Also created

                non-GUI version called string.c so you don't
                have to have GTK installed.

March 25, 1999 Initial release of version 0.8.0

Background

This is a simple little application I decided to write to find out how hard it would be to find the frequency of a given sound (like a string plucked on a guitar).

I read directly from /dev/dsp at a sampling rate of 22050 Hz. I then filter the samples with a Hamming window to prevent aliasing, find the power spectrum of the signal, and pick out the largest value and find the frequency based a reference frequency of A (440Hz).

Right now, there is no way to calibrate the application so that some soundcards may not work exactly right. However, take a look at the source code and read below. You should be able to simply adjust "f" in the programs.

The code is fairly simple and the makefile consists of compiling only two files, gtkdatabox.c (which is a really nice little widget that allows me to draw data very quickly) and the main application, gstring.c.

I removed all the graphics and created a program called string.c. This prints the note to the ascii terminal (printf()) so you can use this without having GTK installed. You do need the FFT package installed.

System Requirements

Before you download it, you may want to verify that the following packages are installed on your system

  1. You need a sound card and a microphone. We need to be able to sample at 22050 Hz and collect 16384 samples at a time in 8 bit format (unsigned char). Almost all modern sound cards can do this. Feel free to tweek the sampling rate at sample size. We read directly from /dev/dsp and use ioctl to set various setting.
  2. For string.c (the version without a GUI), you don't need GTK! For gstring.c, you need the GIMP Toolkit, available from http://www.gtk.org. You need at least versions 1.2.0 of both gtk+ and glib. If you are running a Redhat Linux system, get the latest stable gtk+ and glib library (both the libraries and the headers (which are located in the *-devel RPMS)) from one of these mirrors http://www.gnome.org/ftpmirrors.shtml
  3. You will need at least version 2.0.1 of the FFTW libraries and headers as well. The package name looks like this "fftw-2.0.1-3.i386.rpm". You can get this here http://theory.lcs.mit.edu/~fftw/ and compile it yourself or you can get the latest RPM's from

    ftp://ftp.cc.gatech.edu/pub/linux/distributions/redhat/contrib/libc6/i386/ various RPM contrib archives.

    I used FFTW 2.1 for version 1.0.0 release so I changed #include <rfftw.h> to #include <drfftw.h> in order to pick up the correct include file. This is because of the RPM package I was using.

  4. For the non-GUI version called "string.c", you don't need GtkDatabox. For "gstring.c", will need at lease version 0.1.11.0 of the GtkDatabox widget at http://www.eudoxos.de/gtk/gtkdatabox/index.html. You will need this until this widget gets added to the main Gtk+ distributions. Grab the latest tar file, copy the two files, gtkdatabox.c and gtkdatabox.h into the gstring source directory (where you have gstring.c). If you didn't install gtkdatabox (which you don't have to), you will need to edit gtkdatabox.c and change

#include "gtk/gtkdatabox.h"
to

#include "gtkdatabox.h"

in order to use my makefile.

Installation

(here, we assume you are using string and gstring version 1.0.0. If not, change the following accordingly)

First, unpack the package like so:

tar xzvf gstring-1.0.0.tar.gz

This should uncompress and unpack the files into a directory called gstring-1.0.0.

If you only want to run the application and you happen to be using an i386 machine (with lib6, a.k.a. glibc), simply run the file "gstring-dynamic-i386" or "string-dynamic-i386"

If you want to modify the code or recompile for another machine, you can cd to gstring-1.0.0 and type "make".

Then run it by typing "gstring" or "string" for the non-GUI version. Then simply pluck the string on a guitar or piano. You may also want to play the fifth fret harmonic (or even better, the 12th fret harmonic) to get a more accurate tuning. The little arrows at the top tell you to decrease the pitch ( <--- ) or increase the pitch ( ---> ) of the string you are playing. I also show you the reference frequency and the actual frequency of the main harmonic (largest value of the power spectrum in the frequency domain). You can use a tuning fork to calibrate gstring or string. If an A440 does not really give you 440 Hz, then you probably need to change the value of "f" in the program. Run the program and use an A440 Hz tuning fork. If you don't have a tuning fork, here in the US, the off-hook dial tone on a telephone is 440 Hz (it helps to have a speaker phone). Run the program with the sound source near your microphone. The program will tell you what value 'i' is for the note. Then simply change the line where f is calculated to the following:

f = 440.0/i;

Your frequecy resolution (smallest frequecy difference we can detect), is simply f = (sampling rate)/(number of samples) "N" is the number of samples we take each time we sample. increasing this value will improve your freq resolution. but if you make it too large, it takes longer to get each sample.

"sampling_rate" is the sampling frequecy of the microphone...in Hz lowering this value will lower f and improve your resolution. But it will also limit the highest frequency you can detect... ...remember the Nyquist rate?: you must sample at twice the highest frequency in order to prevent aliasing...

I won't have time to answer any questions about sound cards or microphones. I assume you know if your microphone works and whether your sound card has a sampling rate of 22050 Hz. At some point in the future, I will have some way of changing various settings and calibrating the application. You can easily test the current settings by using a tuning fork or a telephone (in the US). I'm curious what the dial tones are in other countries (feel free to email me).

I also won't have time to answer any questions about how FFTW, GTK+, or gtkdatabox works. They all have manuals at their websites.

However, suggestions or comments are wolcome.

Sam Tannous (stannous@employees.org)


Other Sites

Discussion Groups
  Beginners
  Distributions
  Networking / Security
  Software
  PDAs

About | FAQ | Privacy | Awards | Contact
Comments to the webmaster are welcome.
Copyright 2006 Sourcefiles.org All rights reserved.