A simple spectrogram

Emily 7ab27c6ac3 Remove binary compiled file that sneaked in 1 year ago
.gitignore 7ab27c6ac3 Remove binary compiled file that sneaked in 1 year ago
Makefile 60db65bc59 Rename project Simple Spectrogram, or sspect 1 year ago
README.md 852e1678c0 Make sure the code-segment in markdown won't be highlighted wrongly 1 year ago
agpl.md 11ea6220bc License the project properly 1 year ago
sspect.cpp 11ea6220bc License the project properly 1 year ago



Simple real-time audio spectrogram in OpenGL

This is a simple audio spectrogram primarily intended as a visualization tool for transgender vocal training, but can be of course used for other purposes.


The spectrogram uses OpenGL, GLUT and ALSA for display and sound input. The large main window shows a scrolling real-time spectrogram with time on the horizontal axis, frequency on the vertical axis, and the color intensity shows the amplitude (i.e. energy) of that particular frequency at that particular time. Higher pitched sounds will produce curves higher up in the display, and lower pitched ones will show lower. In addition there are two smaller graphs on the bottom of the screen. The left-side one shows the real-time spectrum of the sound, in other words a vertical slice of the main plot if you will. The right-side graph shows the instantanous signal, i.e. the time-varying sound pressure in the current timing window used to calculate the spectrum.


The spectrogram is started from the command line and the various arguments are as follows:

sspect  [-f] [-v] [-d <device_number>] [-sf <scroll_factor>] [-w <windowtype>] [-t twowinsize]

Command line arguments:
device_number = 0,1,... the ALSA input device number (default 0)
windowtype =    0 (no window) (will be crappy)
                1 (Hann)
                2 (Gaussian trunc at +-4sigma) (default, recommended)
scroll_factor = 1,2,...   How many vSyncs (@ 60Hz) to wait per scroll pixel
                  (default 1)
twowinsize = 11,12,...,16  is the power of 2 giving FFT win_size N (default 13)
        (Note: this controls the vertical frequency resolution and range)

Keys & mouse:   arrows or middle button drag - brightness/contrast
       		i - step through colormaps (B/W, inverse B/W, color)
                q or Esc - quit
                [ and ] - control horizontal scroll factor (rate)

In addition to the command line arguments, various settings can be changed in real-time as the spectrogram runs. See Keys & mouse above. In addition left-clicking on a point on the main graph will draw a horizontal line above which the current frequency and musical note will be shown. Left-clicking does the same, but also displays a harmonic series of notes. This is interesting for understanding vocal formants.


This depends on OpenGL, GLUT and ALSA, so is intended to run on a GNU/Linux system. On Debian-based systems it requires the packages freeglut3, freeglut3-dev, libfftw3-dev, libasound2 and libasound2-dev. Similar packages are provided on other GNU/Linux distributions, but their names might be slightly different.

In addition to the above you should have a C++ compiler and make. Under Debian-based systems these are provided by the package build-essential. Then build it with a simple make. Run it with ./sspect.

Credits and other people's code

The large effort of writing the core of the spectrogram is due to Alex Barnett (author of glSpect) who based his code somewhat on glScope by Luke Campagnola. This current code has had some default settings changed, added a few frequency lines for voice practice, and also added the option to choose the sound input device on the command line. In addition there's a lot of code and documentation cleaning up.

Anthony Agnone forked glSpect in August 2016, and his version is called audio_visualization.


Alex and Luke licensed their work with the following sentence

Distributed under a completely free license; this means you can do
absolutely anything you want with this code.

So the part of this code that's their work is under the above extremely permissive license. The rest is licensed under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See agpl.md for the full terms.