Kunquat audio rendering is based around a state machine and three factors: initialisation set used to initialise the machine, audio rate used to control resolution of the execution, and a stream of commands that is used to request audio from and to interact with the state machine.
The state machine is initialised with a set of key/value pairs that define available audio units (i.e. instrument and effects) and a connection graph that connects the instruments through various effects to a stereo output. The initialisation data may also contain an album of songs described as note data that can be used to control the audio units without human intervention.
In addition to providing an initialisation set, the user needs to select an audio rate. The audio rate affects the resolution at which the audio rendering and event processing are done. A higher audio rate produces a more accurate estimation of the sound described by the parameters and make it possible to interact with the state machine more tightly. Specifying a lower audio rate reduces the amount of computation required.
Once the state machine has been initialised, the operation proceeds by feeding commands to the state machine. The two possible commands are “mix” and “fire”. Mix will cause Kunquat to produce one sample of audio together with event information of any events that happened during the rendering of the sample. Fire is used to feed external events into the system and it returns with the set of events that were created as an immediate reaction to the fired event.
string - string type
float - floating point number type
state - a rendering state
key = string
value = string
kv_pair = (key, value)
initialization_set = [kv_pair]
event_name = string
event_parameter = Maybe string
event = (event_name, event_parameter)
events = [event]
sample = (float, float)
initial_state :: initialisation_set -> state
mix :: state -> ( state, events, sample )
fire :: state -> event -> ( state, events )
The events launched by the state machine contain one or zero parameters. Launching an event has an effect inside the state machine, but the generated events are also delivered as return values to fire and mix commands.
Triggers are used for launching events in an automated fashion. A trigger consists of an event name and an expression. Processing a trigger includes evaluating the expression and launching an event with the value of the expression as a parameter.
Channels are numbers used for addressing audio unit controls. At any given time a channel has one or zero selected note outputs and one or zero active audio units. Some channel events affect the audio unit either directly or through the selected note output.
Environment is a variable space that can be used to parameterise parts of the automated playback.
Mixing graph connects instruments through effects into master output.
Control graph is used to connect instrument note inputs to global note outputs. When a note output is selected on a channel, the notes will then be forwarded to the connected audio units.
Kunquat composition defines a global random seed that is used to initialise random number generators for various contexts at the start of playback.
The events are categorised based on their scope and intended use.
Some parameters in the playback state can be controlled with slides. Such parameters include note force and pitch, among others. Most slides are specified with a slide target event (denoted by forward slash ‘/’ in the event name) and a slide length event (denoted by forward slash and equals sign ‘/=’ in the event name). Oscillation parameter changes are always performed with slides (with slide length of 0 by default), even though their slide target events are not named with the forward slash.
The slide target event starts the slide progress from the current parameter value to the target value. The slide is initialised with the length specified by the latest corresponding slide length event, or length 0 if no length has been specified. However, it is also possible to specify the slide length after the slide target in the same trigger row. If a slide length is updated while the slide is in progress, the remaining part of the slide will have the length specified by the new slide length event.
All slides are linear in the scale in which they are documented. For example, when a force value is slid from 0 to -6 dBFS, the active force will be -3 dBFS exactly halfway through the slide. Note, however, that tempo adjustments affect the speeds of all slides, since the slide lengths are specified in timestamps.
Several events (stream, environment variable and device events) control values that are specified with a name setting event (e.g. ‘.s’ modifies a stream whose name is specified with ‘.sn’). For these event pairs, triggers support syntactic sugar of the form [.s:foo x] that is equivalent to triggers [.sn ‘foo’] [.s x].
Control events are used for controlling generic playback-related behaviour. They are mostly intended to be used by editors and, to certain extent, interactive compositions. Most control events may cause infinite loops in compositions; therefore, control events specified in triggers are ignored by default.
Stop reading pattern data
Stop the playback cursor. Active notes and effects will continue to be processed. New events can only be fired through the external interface. This event has no effect if the playback is already paused.
Continue reading pattern data
Resume playback cursor movement. This event has no effect unless the playback is paused.
Read triggers from pattern instance x in a continuous loop
Jump to the beginning of pattern instance x and play that pattern instance in an infinite loop. This is mostly intended to be used by editors.
Set unconditional jump target pattern instance x
Set target pattern instance for event cg. This event does not cause jumping by itself.
Set unconditional jump target row x
Set target row of timestamp x for event cg. This event does not cause jumping by itself.
Jump to location specified by events c.gp and c.gr. If the target pattern instance has not been specified, the first pattern instance of the first song will be used. If the target row has not been specified, timestamp 0 will be used.
Enable infinite playback mode
By default, control events specified by triggers are ignored. This event will enable the processing of such triggers. Note that, being a control event itself, this event must be fired through the external interface to have an effect. Additionally, playback will jump to the beginning of the specified song if the end is reached. This event has no effect if the infinite playback mode is already enabled.
Disable infinite playback mode
Disable control events caused by triggers and stop playback when the end of the specified song is reached. Note that this effect will not disable pattern playback mode. This event has no effect if the infinite playback mode is already disabled.
Select environment variable x
Set variable named x for storing a value.
Set value x of selected environment variable
Set value x of an environment variable. The variable name specified with the last c.evn event in the current channel is used. This event has no effect if the type of x is not compatible with the target environment variable.
# Do nothing with string value x
calln Do nothing with string value x
call Do nothing with any value x
Master events control various playback parameters that affect the whole composition.
Pattern delay by timestamp x
Suspend playback cursor for duration specified by timestamp x.
Set jump counter x
Set jump counter used by the jump event mj. Valid range for x is [0, 32767].
Set jump target pattern instance x
Set target pattern instance for the jump event mj.
Set jump target row x
Set target row of timestamp x for the jump event mj.
Jump fixed number of times
Jump to location specified by events m.jp and m.jr a number of times specified by event m.jc.
When the jump event is processed normally, the current playback cursor position (pattern instance, row timestamp, channel number and trigger row offset) is marked as a jump position with the given jump counter. If a playback cursor location is marked as a jump position, the possible corresponding mj trigger is ignored and the jump position is processed. If the jump counter of a jump position is positive, the counter is decremented by 1 and the jump is performed. If the counter is zero, the jump position information will be removed.
Set tempo to x
Set tempo to x beats per minute.
Slide tempo to x
Slide tempo to x beats per minute. Note that Kunquat implementations are expressly allowed to perform tempo slides in a lower resolution than implied by the audio rate, in order to simplify implementation of the sequencer.
Set tempo slide length to x
Set tempo slide length specified by timestamp x. The length of the slide is interpreted in relation to the logical composition time. For instance, if a tempo slide of length 3 begins at row timestamp 2, the slide is always finished at timestamp 5, regardless of initial and final tempo values.
Set global volume to x dBFS
Slide global volume to x dBFS
Set global volume slide length to timestamp x
Set active retuner to x
Set fixed pitch of the active retuner to x
Set tuning centre of the active retuner to x
Set active retuner pitch offset to x cents
Apply initial settings of retuner x to the active retuner
Reset active retuner
Channel events control various parameters of a channel and notes that are active in the channel.
Set active audio unit control x
Note on with pitch x
Start a new note with pitch of x cents. This event has no effect if the selected audio unit does not support voice control.
Hit with index x
Start a new note with hit index x. This event has no effect if the selected audio unit does not support voice control.
Release an active note or hit. This event has no effect if there is no foreground note in the channel. The released note or hit can no longer be controlled directly through events.
Set force to x
Set force of the currently active note to x + s dBFS, where s is the global note force shift (-30 by default).
Slide force to x
Slide force from current force to x + s dBFS, where s is the global note force shift (-30 by default). The slide is performed using slide length specified by /=f.
Set force slide length to x
Use timestamp x as the length of the force slide started by the /f event.
Set tremolo speed target to x
Set tremolo speed target to x cycles per second. By default, the new speed takes full effect immediately; use the t/=s event for controlling the smoothness of the transition. Setting zero as the new speed target restores the original force level.
Set tremolo depth target to x
Set tremolo depth target to ±x dB. By default, the new depth takes full effect immediately; use the t/=d event for controlling the smoothness of the transition. Valid range for x is [0, 24].
Set tremolo speed slide length to x
Use timestamp x as the length of the tremolo speed slide.
Set tremolo depth slide length to x
Use timestamp x as the length of the tremolo depth slide.
Turn on force carrying
Enable carrying of force effects (fixed force, slide and tremolo) from one note to the next. This needs to be applied before the first note that should inherit the force controls of the previous note.
Turn off force carrying
Disable carrying of force effects between notes.
Slide pitch to x
Slide pitch to x cents from current pitch, using slide length specified by the /=p event.
Set pitch slide length to x
Use timestamp x as the length of the pitch slide started by the /p event.
Set vibrato speed target to x
Set vibrato speed target to x cycles per second.
Set vibrato depth target to x
Set vibrato depth target to x * 5 cents. The depth is the maximum deviation, e.g. a depth of 240 has peaks at one octave above and below the centre pitch.
Set vibrato speed slide length to x
Use timestamp x as the length of the vibrato speed slide.
Set vibrato depth slide length to x
Use timestamp x as the length of the vibrato depth slide.
Turn on pitch carrying
Enable carrying of pitch effects (pitch slide and vibrato) from one note to the next. This needs to be applied before the first note that should inherit the pitch controls of the previous note.
Turn off pitch carrying
Disable carrying of pitch effects between notes.
Set an arpeggio note of pitch x
Set a new entry of x cents in the arpeggio pitch list. The list initially contains the original pitch parameter of the current note, and each .arpn event adds a new note to the end of the list.
Set current arpeggio note index to x
Set the destination list index used by the next .arpn event to x.
Set arpeggio speed to x
Set arpeggio speed to x notes per beat.
Clear arpeggio note settings
Restore the arpeggio pitch list to the initial value, i.e. a single-element list with the original pitch parameter.
Turn arpeggio on
Turn arpeggio on using the current arpeggio pitch list. If the arpeggio is already in progress, this event has no effect.
Turn arpeggio off
Turn arpeggio off. This event restores the pitch that would be active if the arpeggio was never activated in the first place. If the arpeggio is already off, this event has no effect.
Select channel stream x
Set value of a channel stream to x
Slide channel stream to x
Set slide length of channel stream to x
Set oscillation speed of channel stream to x
Set oscillation depth of channel stream to x
Set oscillation speed slide length of channel stream to x
Set oscillation depth slide length of channel stream to x
Turn on channel stream carrying
Turn off channel stream carrying
Set channel expression to x
Set expression applied to all notes in the channel from the current timestamp onwards (including any notes previously started on the same row). Setting the expression to empty string disables channel expression, and setting no value applies the channel default expression setting.
Set note expression to x
Set expression applied to a note just started. This only affects notes that haven’t rendered audio yet. Setting the expression to empty string disables note expression, and setting no value applies the instrument default expression setting.
Turn on note expression carrying
Turn off note expression carrying
Set channel device event name to x
Fire channel device event with argument x
Audio unit events control parameters that apply to an audio unit as a whole. The target audio unit is selected with the channel event .a — the channel in which the audio unit events are fired does not affect the end result in any other way.
Turn on audio unit bypass
Disable internal processing of the audio unit and send signals from its input ports directly to the corresponding output ports.
Turn off audio unit bypass
Set value of audio unit stream to x
Slide audio unit stream to x
Set slide length of audio unit stream to x
Set oscillation speed of audio unit stream to x
Set oscillation depth of audio unit stream to x
Set oscillation speed slide length of audio unit stream to x
Set oscillation depth slide length of audio unit stream to x
Fire audio unit device event with argument x
Set instrument sustain value to x
Set sustain to a normalised value between 0 and 1. 0 disables sustain completely, 1 applies full sustain. Sustain slows down the processing of note release envelopes. If a force release envelope is not enabled, values ≥ 0.5 disable cutting of a released note.
Query events are used to request information from the rendering engine.
qlocation Force generation of events Atrack, Asystem and Arow
qvoices Force generation of event Avoices
qf Force generation of event Af.
Auto events fired with the fire command are ignored. The rendering engine creates auto events to report updates in the playback status.
Atrack Do nothing with the current track number x.
Asystem Do nothing with the current system number x.
Arow Do nothing with the current pattern location timestamp x.
Avoices Do nothing with the current active voice count x.
Af Do nothing with the current actual force x of an active note.
The save feature in Kunquat Tracker stores initialization sets in zip files. Such saved files are called Kunquat modules. The keys of the initialization set are presented as file paths in the zip file and the values are stored as contents of the corresponding files. In addition to the values required for playback, the tracker extends the initialization set with some metadata. See Appendix B for description of the metadata.
Appendix B: Metadata and Interface Data
kqtc00/au_00/m_name.json contains the name of the audio unit
It is often desirable to specify limitations for rendering software. While implementing Kunquat, we have specified such limits for the amount of polyphony, the amount of active jump counters, the amount of nested ifs, the resolution of tempo slides, and the number of unconditional jumps performed without rendering audio between the jumps.
Appendix D: Editing Behaviour
Editors may wish to change the initialization set during rendering. This may cause the rendered sound to differ from the specified outcome during editing. In many cases this could be reasonable trade-off as working with an editor is largely about modifying the initialization set.