2010–2022

mel - generate sound fragments from plain text

**mel** [[[*wavefile* ...] *infile*] *outfile*[**/**]]

Interpret ASCII input in *infile* as audio and save it to *outfile* in the WAVE format, optionally using samples provided in *wavefile*s. The syntax for *infile* is given below. Filenames default to **/dev/stdin** or **/dev/stdout**. The dash (**-**) is a shorthand for the default value. Try **stdin** if **/dev/stdin** is not available. If *outfile* is followed by a slash (**/**)**,** application-specific metadata is omitted.

*infile* shall contain words *w* (sequences of lowercase letters **a** to **z** and hashes **#**), numbers *n* (sequences of digits **0** to **9**, decimal points **.**, and a dividing colon **:**), and commands (other single ASCII characters). Commands are followed by words and/or numbers as arguments, as listed below. The input is processed linearly, whereby unexpected characters, including whitespace, act as separators and are otherwise ignored. Reference values imply initial values, and initial values imply current values.

**~***w*[*n*]Choose wave sample of shape

*w*and duration*n*in seconds. This is the building block for sound at arbitrary frequency and amplitude. Predefined values for*w*are listed below. The corresponding spectra are shown by the command**harmonics***w*. If*w*reads**#**, the first channel of the*n*th*wavefile*given on the command line is loaded instead.*n*defaults to**1**. The preset value is a**circular**wave that lasts**1**second.**harmonic**sin(x) for x in (0, 2π]

**power**sin³(x) for x in (0, 2π]

**major**sin⁵(x) for x in (0, 2π]

**constant**sgn(sin(x)) for x in (0, 2π]

**linear**2/π arcsin(sin(x)) for x in (0, 2π]

**quadratic**sgn(x) (2|x| - x²) for x in (-2, 2]

**circular**sgn(x) sqrt(2|x| - x²) for x in (-2, 2]

**cubic**3/2 sqrt(3) (x³ - x) for x in (-1, 1]

**water**3/2 sqrt(3) (x³ - x) + 1/2 for x in (0, 1]

**random**White noise if followed by

**@**without argument.

**S***w*[*n*]Choose attack envelope. Arguments as above. Predefined values for

*w*are listed below. The preset value is a**circular**envelope that lasts**0.1**seconds.**harmonic**sin(x) for x in (0, π/2)

**smooth**sin²(x) for x in (0, π/2)

**power**sin³(x) for x in (0, π/2)

**major**sin⁵(x) for x in (0, π/2)

**linear**x for x in (0, 1)

**quadratic**1 - x² for x in (-1, 0)

**circular**sqrt(1 - x²) for x in (-1, 0)

**cubic**3x² - 2x² for x in (0, 1)

**Z***w*[*n*]Choose release envelope. Arguments as above.

**N***w*[*n*]Choose attack and release envelope at once. Arguments as above.

*****Start/end a comment.

**$***n*Set a sample rate of

*n*samples per second. The preset value is**44100**samples per second. This setting holds globally and is ignored after first note played.**O***n*Set number of channels to

*n*. Allowed values are**1**(mono) and**2**(stereo). If absent, the number of channels is determined automatically.**|***n*Set duration of a beat to

*n*seconds. The preset value is**0.5**seconds.**T***w*Choose tuning from the below options. The preset value is

**equal**.**equal**Equal temperament.

**pyth**Pythagorean tuning. All notes are reached combining fifths and octaves.

**just**Just intonation. All notes are reached combining thirds, -1 to 2 fifths from keynote, and octaves.

**close**Five-limit tuning closest to twelve-tone equal temperament.

**H***n*Divide one octave into

*n*halftones/steps of equal frequency ratio. The preset value is**12**halftones (twelve-tone equal temperament).**@**[*n*]Set reference frequency and concert pitch

**A4**to*n*Hz.*n*defaults to the inverse length of the current wave sample. This allows for playing this sample at its original speed. The preset value is**440**Hz.**&***n*Set reference amplitude sqrt(L² + R²) to

*n*arb. units. The preset value is**1**arb. unit.**%***n*Set reference amplitude ratio R:L between right and left channel to

*n*. The preset value is**1**.**C D E F G A B**[*w*][*n*[*n'*]]Set reference frequency via note name.

*w*marks accidentals and can be**#**,**x**,**b**,**bb**, and so on. To raise and lower the frequency by a diatonic (septimal) [eleven] {Pythagorean} comma 81:80 (64:63) [33:32] {531441:524288}, use**u**and**v**(**s**and**z**) [**i**and**j**] {**p**and**d**}, respectively. Please note that the note name already implies a certain number of diatonic commas for the tunings**just**and**close**.*n*is the octave number and defaults to**4**. If omitted, also set the keynote. The preset keynote is**C**.*n'*is an optional microtonal accidental as used in the Functional Just System (FJS) by misotanni (*https://misotanni.github.io/fjs*). Here, compound accidentals must be written as a product and otonal and utonal accidentals are separated by a colon (**:**).**A4**is the concert pitch.**R**Set reference frequency, amplitude, and amplitude ratio to current values. E.g., as a prefix to

**-**or**+**, this allows for relative frequency shifts.**'**[*n*]Play sound for a duration of

*n*beats.*n*defaults to**1**.**"**[*n*]Pause for a duration of

*n*beats.*n*defaults to**1**.**`**[*n*]Rewind by

*n*beats.*n*defaults to**1**. (Negative pause.)**Q***n*Set initial frequency to

*n*times the reference frequency.**V U**[*w*]*n*Set initial frequency to

*n*chromatic steps below/above the reference. You can use the same commas*w*as with note names. The 12-tone scale is made of the -5 to 6th fifths from the keynote.**- +***n*Set initial frequency to

*n*halftones below/above the reference.**\ /***n*Continuously lower/raise current frequency by

*n*halftones during the next play period (**'**).**_ ^***n*Continuously lower/raise current frequency by

*n*halftones per beat from now on.**? !***n*Set initial amplitude to

*n*dB below/above the reference.**< >***n*Continuously lower/raise current amplitude by

*n*dB during the next play period (**'**).**, ;***n*Continuously lower/raise current amplitude by

*n*dB per beat from now on.**[ ]***n*Set initial amplitude ratio to

*n*dB below/above the reference.**( )***n*Continuously lower/raise current amplitude ratio by

*n*dB during the next play period (**'**).**{ }***n*Continuously lower/raise current amplitude ratio by

*n*dB per beat from now on.**=**Introduce discontinuity. (Play the same note again.)

**P**[*n*]Set phase, i.e., the time integral of the frequency, to

*n*. It is only defined modulo one.**M**[*n*]Set

*n*th time mark.*n*must be an integer between**0**and**99**and defaults to**0**.**W**[*n*]Wind back to

*n*th time mark, if set.*n*defaults to**0**.**Y***n**n'*[*n"*]Yank sound between

*n*th and*n'*th time mark and insert it*n"*times, if marks have been set.*n"*defaults to**1**.**I**[*n*]Set

*n*th text mark.*n*must be an integer between**0**and**99**and defaults to**0**.**J**[*n*[*n'*]]Jump back to

*n*th text mark, if set. This works*n'*times in a row.*n*and*n'*default to**0**and**1**, respectively.**K L**[*n*...]Skip/only consider subsequent command if the number of the current iteration matches any of the integers

*n*...**X***w*[...]Do something special.

**status**Print current time, frequency, amplitude, balance, and phase.

**report**Print note counts (since last report) to standard error stream. Only notes defined via the commands

**C D E F G A B**and**U V**are counted. This is useful to, e.g., to determine the keynote of a piece of music.**detune***n*Randomly detune reference frequency and concert pitch

**A4**, by up to*n*halftones. In combination with text and time marks, this is useful to generate non-white noise.**delete***n**n'*Delete sound between

*n*th and*n'*th time mark, if marks have been set.**reverse***n**n'*Reverse sound between

*n*th and*n'*th time mark, if marks have been set.**vibrato***n**n'**m**m'*Apply vibrato to sound between

*n*th and*n'*th time mark, if marks have been set. The sample is periodically delayed (and advanced) with an amplitude of*m*seconds and a frequency of*m'*per sample length, using the current wave sample.**flanger***n**n'**m**m'*Apply flanger to sound between

*n*th and*n'*th time mark, if marks have been set. The sample is periodically delayed (and advanced) with an amplitude of*m*seconds and a frequency of*m'*per sample length, using the current wave sample, and superimposed with itself.