Project

General

Profile

sac2midi

sac2midi sonifies SAC files into a MIDI file for musical display

SYNOPSIS

sac2midi [-f name] [-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.

First, store several background observations in the bg/ subfolder, then run sac2midi -S to characterize them, redirecting the results into a sonfig file.

sac2midi -S bg/*.SAC > bg/sonfig.txt

Next, store several live observations in the obs/ subfolder, then run sac2midi -s to sonify them into a new midi file in the current directory. Sac2midi writes the name of the new midi file to stdout.

sac2midi -s obs/*.SAC < bg/sonfig.txt

You may edit sonfig.txt to adjust the sonification configuration, if you like.

OPTIONS

-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.

-s

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

-v

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

-M

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

-Q

Quiet. Suppress output to stderr and stdout.

-S

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

-T

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.</p>

-V

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

-?

Usage. Print a help message to stderr.

sac1 [sac2...]

A list of seismic analysis code files to sonify.

DISCUSSION

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.

EXAMPLES

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.

sac2midi -S calculates background noise statistics from all the SAC files in the bg/ subfolder and writes a sonfig file to stdout

sac2midi -S bg/*.SAC > sonfig.txt

sac2midi -s reads a sonfig file from stdin to control the sonification, reads all the SAC files in the obs/ subfolder, and writes a new midi file in the current folder.

sac2midi -s obs/*.SAC < sonfig.txt

sac2midi -s reads a sonfig file from stdin to control the sonification, reads all the SAC files in the observed/ subfolder, and writes a new midi file in the midi subfolder.

sac2midi -f midi/ -s obs/*.SAC < sonfig.txt

If you don't want to store the sonfig file, you can just pipe it through.

sac2midi -S bg/*.SAC | sac2midi -f midi/ -s obs/*.SAC

In the default terse mode (-T) sac2midi writes the name of the newly created midi file to stdout.

sac2midi -T -s obs/*.SAC < sonfig.txt > midifilename.txt

SONFIG FILE FORMAT

The sonfig file format is tab-separated ASCII text with columns:

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)
SumCount - Sum of background samples (Floating)
SumCountSquared - 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 Maximum (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)

MATH

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);
}

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 gmail.com 
Mill Creek, WA 98012