sac2midi sonifies SAC files into a MIDI file for musical display


sac2midi [-f file] [-s] [-v] [-M] [-Q] [-S] [-T] [-V] [-?] sac1 [sac2 ...]

sac2midi accepts one or more sac files and produces a single output MIDI file with music that represents the seismic waveforms.

sac2midi -S calculates background noise statistics and writes a sonfig file to stdout

sac2midi -s reads a sonfig file from stdin, to control the sonification


-f name

Use the indicated name as the name of the midi output file instead of the default file name.

If the last character is a path separator, the name indicates the path to a folder where the output file is stored.

By default, the MIDI file name is calculated from the network, station, location, component, year, julian date, hour, minute, and second of the lexically first component of the chronologically earliest SAC file.


READ a sonfig file from stdin. The format is ASCII text in tab-separated columns. See also: -S, and the below format discussion


Display version information, to stderr. (Overrides -Q.)


MIDI usage. Print a help message to stderr about MIDI.


Quiet. Suppress output to stderr and stdout.


WRITE a sonfig file to stdout, and suppress Midi file creation. The input sac files should represent nominal background activity.


Terse. No output is sent to stderr. The midi file name is written to stdout, except that the -S option may cause a sonfig file to be written to stdout instead.


Verbose. Send either the midi file name or the sonfig to stdout, and send a lot of extra information to stderr.


Usage. Print a help message to stderr.

sac1 [sac2...]

A list of seismic analysis code files to sonify.


Sac2midi measures maximum wave amplitude on very short time scales for musical display without time lapse.

The sonification is modeled after the Richter scale, but is not the same as the Richter scale.

The pitch and duration of each note represent the log, base 10, of the maximum amplitude of the input waveform, for the duration of previously played note (or rest).

Musical rests represent insignificant amplitudes. Rest durations may vary, and are quantized to the next beat or measure.

Notes with the same pitch and half the duration represent 10 times larger amplitude. That is, an eighth note represents 10 times larger wave amplitude than a quarter note.

Different seismometers are represented as different musical instruments. Up to 15 distinct MIDI channels are available. MIDI channel 10 is reserved for future use to add percussion to the sonification.

Note velocity varies. Overflow values are played very quietly. Long rests cause a decrescendo. Otherwise the musical phrase begins at a nominal velocity with a gradual crescendo.

All input waveforms are sonified to a single MIDI track, 4/4 time, 24 midi clocks per quarter note, 120 beats per second, so that midi clocks occur at 48Hz. Time is not compressed.

Input SAC files are sorted by (network.station.location.component) and by time. Gaps are filled by silence.

SAC files with the same network, station, location, and component are sorted chronologically. Gaps in the data are treated as if they were filled with silence.

SAC files with the same network, station, location, sample rate, timeframe, and have three components that differ only by the letters X, Y, and Z in the same lexical position in their component name are treated as three components of the same waveform. (NOT IMPLEMENTED YET)

SAC files that differ in these respects are sonified on separate MIDI channels. In other words, each seismometer plays on a different instrument.


First, create a SAC file for each seismic channel that represents background activity, a time interval when nothing special is going on.

Run sac2midi -S on the background observations, redirecting stdout into a "sonfig" file. The output will be in ASCII tab-separated format.

Now gather live observations from any of these seismic stations into SAC files. Run sac2midi -s sonfig.txt against those sac files, to create the midi file. The new midi file's name will appear at stdout. Play the MIDI file to listen to the sonification.


The sonfig file format consists of records stored in variant rows of tab-separated lines of ASCII text.

The first character in the line defines the remaining columns in that row. All rows that begin with a digit [0-9] are reserved for formatted data. Everything else is a comment.

sonvar - Sonification row variant record number (unsigned integer)

Row format when sonfig starts with any character that is not a digit: "Comment"

The row ends at a line terminator, and its contents are ignored.

Row format when sonfig=1: "Titles"

All columns are tab-separated ASCII, and correspond to column titles for rows that follow.

Row format when sonfig=2: "Component"

net - Network name (ASCII)
sta - Station name (ASCII)
loc - Location name (ASCII)
cmp - Component name (ASCII)
rate - Sample Rate (1/delta) Hz. (Floating)
N - Number of background samples (Floating)
SumCounts - Sum of background samples (Floating)
SumCountsSquared - Sum of squares of background samples (Floating)
Min - Minimum background sample (Floating)
Max - Maximum background sample (Floating)
Mean - Mean (Floating) (0.0)
Gain - Gain (Floating) (1.0)
Base - Base of logarithm (Floating) (10.0)
Shift - Applied Shift (Floating) (0.0)
Floor - Applied Quiet Floor (Floating) (3.0)
Clip - Applied Clipping (Floating) (32765.0)
VMin - Minimum melodic velocity (0 to 127) (20)
VNom - Nominal melodic velocity (0 to 127) (90)
VMax - Maximum melodic velocity (0 to 127) (120)
VDrumNom - Nominal Drum velocity (0 to 127) (100)
Patch - General Midi 1 Patch number (0 to 128), (0: use a default patch)
DrumKey - Channel 10 keyed percussion note number, (0 to 128, 0: no drum)
Instrument - General Midi 1 Patch name (ASCII, advisory only)
DrumName - Channel 10 percussion drum name (ASCII, advisory only)


for (all samples s during the time interval spanning the previous note or rest) {
m = max(m, abs((s-mean)*gain));
r = (log(m)/log(base)) + shift;
if (r <= quiet) {
Rest for a quantized duration of time;
} else {
Play a selected note as a function of (r);

  • Homepage:
  • Category: Conversion Program
  • Language: C / C++
  • Keywords:

    SAC, ASCII, BINARY, WAV, wave, MIDI, midi, .mid, .midi, earthquake, audio, music, musical, sound, sonic, acoustic, audification, sonification, Richter

  • Citation:

    by Rick DeWitt, (c) 2004, 2015
    dewitt.rick at
    Mill Creek, WA 98012

Issue tracking

open closed Total
Bug 6 0 6
Feature 1 0 1
Support 0 0 0

View all issues


Manager: Rick DeWitt