Synth

From Esolang
Jump to navigation Jump to search

Synth is an esoteric programming language created by User:Avethenoul as a digital synthesizer. It was largely inspired by Befunge.

Overview

Like Befunge, Synth uses single-byte commands and a stack. In fact, most of the commands are direct translations. Unlike Befunge, a large part of any Synth program is track data, and all output is in audio form (accomplished by piping its output to aplay).

All data is of the "unsigned char" type. As a result of this, there are up to 255 tracks, each with up to 255 notes, and the program is up to 255 commands long. Output is done via unsigned 8-bit integers, sampled at 8000Hz. The first part of the program is track data, with each track ending in a newline. The first line starting with a colon (:) denotes the start of the program data, and a dollar sign ($) denotes its end. The remainder of the file is ignored.

Note values are encoded as ascii, with the 49th ascii code (1) corresponding to the 49th piano key (middle A, 440Hz), and the remainder tuned in equal temperament. One exception is the space character (ascii value 32), which denotes a pause. The below table serves as a handy lookup:

       !"#$%&'
 ()*+, -./0123
 45678 9:;<=>?
 @ABCD EFGHIJK
 LMOPQ RSTUVWX
||_|_|||_|_|_||
|_|_|_|_|_|_|_|

Commands

Cmd Description
0123456789abcdef all of these push their value (as read in hexadecimal) on the stack.
` pops a and b, pushes a+b*64. Iow it combines two nibbles into a byte.
: duplicates the uppermost value
/ swaps the uppermost values
! inverts the uppermost value (pops a, pushes 255-a)
* pops the uppermost values and pushes their product (divided by 256 to renormalize it)
- pops a and b, returns b-a
+ pops a, then pops that many values and pushes their average. This functions as a mixer.
~_%^ pops the uppermost value and generates a sine/square/sawtooth/triangle wave with that tone. See Overview for an explanation on how wave frequency is encoded.
t takes two values, returns a note. The uppermost value tells it play speed (in eigths of a second), the second uppermost value tells it which track to read the value from.
z takes the uppermost value, returns a sawtooth wave over that many notes (iow period length is measured in eigths of a second, like above). This, combined with the inverter and product, can be used to make basic envelopes.

Examples

Gran Vals, aka the Nokia Jingle:

DB::<<A?6688?=5588            
   = 
:01t~16t~6z!*2+$

The last note is played on a separate track, to allow use of z for a fade effect.

External resources