SPB Git

Repository Public

instruments.md 8.7 KB 289 lines markdown

1<!--2ORIX Sonata3File: Documentation/manual/instruments.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Instruments89Every track is played by an instrument. An instrument is an **engine** — a synthesis method10implemented in the runtime — with values for its parameters. Sonata has 16 engines and the11standard library names 83 instruments built on them.1213## Standard instruments1415Use one by naming it as the type of a track:1617```sonata18composition "A Small Ensemble" {19    tempo 84bpm20    instrument flute: Flute {21        play A5 duration 1/222        play G5 duration 1/223    }24    instrument guitar: NylonGuitar {25        arpeggio(chord(A2, minor) + chord(A3, minor), step: 1/8)26        arpeggio(chord(G2, major) + chord(G3, major), step: 1/8)27    }28    instrument bass: DoubleBass {29        play A1 duration 1/130    }31}32```3334The families: pianos, plucked strings, bowed strings, flutes, clarinets, brass, organs,35basses, synthesizers, FM instruments, drums and cymbals, mallets and bells, and voices. The36complete list with the sound of each is in37[Standard instruments](reference/std-instruments.md), and the **Library** space lets you38browse and hear them.3940## What the engines are4142| Engine | Method |43|---|---|44| `piano` | modal synthesis of inharmonic strings struck by a hammer, with a soundboard |45| `plucked_string` | waveguide string (extended Karplus–Strong) with a body resonator |46| `bowed_string` | waveguide string driven by a bow-friction model |47| `flute`, `clarinet`, `brass` | waveguide tubes with a jet, reed or lip excitation |48| `organ` | additive synthesis with nine drawbars |49| `bass` | electric (waveguide string, pickup) or synthesizer bass |50| `synth` | subtractive: two oscillators, filter, envelopes, LFO |51| `fm` | four-operator frequency modulation |52| `kick`, `snare`, `hihat` | drum synthesis |53| `modal_percussion` | banks of damped modes: bars, bells, tubes, glass |54| `voice` | formant synthesis of sung vowels |55| `patch` | a signal graph you write yourself |5657These are *models*: approximations chosen to be musically useful, not exact simulations of58physical instruments. Each engine states its method and its limits in the59[engine reference](reference/instruments.md) and in `Documentation/acoustics/`. In60particular, the flute and brass engines are driven at the pitch of the note rather than61finding it by themselves, so they do not overblow.6263## Defining an instrument6465An instrument definition chooses an engine with `model` and sets parameters. It is written at66the top level of a file.6768```sonata69instrument WarmKeys {70    model fm71    preset epiano72    feedback 0.173    envelope adsr(attack: 4ms, decay: 1.2s, sustain: 0.3, release: 400ms)74}7576composition "A Defined Instrument" {77    instrument keys: WarmKeys {78        chord [C3, G3, E4, B4] duration 1/179    }80}81```8283* `model m` selects the engine.84* `preset p` starts from one of the engine's presets.85* `name value` sets a parameter. Lines apply in order, so a parameter written after `preset`86  overrides the preset.87* Parameters with a dot in their name can be written directly — `envelope.attack 4ms` — or88  grouped as a **slot**: `envelope adsr(attack: 4ms, …)` chooses the kind `adsr` and sets its89  members.9091Every name, unit and range is checked against the engine's parameter table. A time needs a92unit, a ratio must be between 0 and 1, an unknown parameter is refused with a suggestion:9394```sonata,error=S202395instrument Wrong {96    model plucked_string97    dampening 0.0298}99100composition "Unknown Parameter" {101    instrument a: Wrong {102        play C4103    }104}105```106107## Deriving an instrument108109`instrument B: A { }` starts from another instrument and changes some parameters. The engine110cannot be changed by a derived instrument.111112```sonata113instrument DarkGrand: GrandPiano {114    brightness 0.2115    hammer.hardness 0.3116}117118instrument SlowStrings: ConcertStrings {119    envelope adsr(attack: 600ms, decay: 200ms, sustain: 0.9, release: 1.5s)120    vibrato.depth 10cents121}122123composition "Derived Instruments" {124    tempo 60bpm125    instrument piano: DarkGrand {126        chord [D2, A2, F3] duration 1/1127    }128    instrument strings: SlowStrings {129        gain -6dB130        chord [D4, F4, A4] duration 1/1131    }132}133```134135## A physical-model instrument136137The plucked-string engine exposes the parts of its model: where the string is plucked, how138much it is damped, and a body made of resonant modes.139140```sonata141instrument CrystalHarp {142    model plucked_string143    damping 0.015144    excitation pluck(position: 0.35)145    resonance modal(frequencies: [440Hz, 880Hz, 1320Hz])146    envelope adsr(attack: 5ms, decay: 300ms, sustain: 0.6, release: 2s)147}148149composition "Crystal Harp" {150    tempo 72bpm151    instrument harp: CrystalHarp {152        for n in [A3, E4, A4, C#5, E5] {153            play n duration 1/4154        }155    }156}157```158159The pluck position works as on a real string: plucking at a fraction `p` of the length160removes the harmonics that have a node there (every third harmonic at `p = 1/3`). For an161ideal string the fundamental is `f = (1 / 2L) · √(T / μ)`; the engine does not ask for length,162tension and mass, it tunes its delay line to the frequency of the note and lets you shape the163losses and the excitation.164165A mallet instrument can be given its own set of modes:166167```sonata168instrument Plate {169    model modal_percussion170    // Mode frequencies as ratios of the fundamental.171    partials [1, 2.3, 3.9, 5.6, 7.7]172    decay 1.8173    hardness 0.7174}175176composition "Custom Modes" {177    instrument plate: Plate {178        play C4 duration 1/2179        play G4 duration 1/2180    }181}182```183184## Patch graphs185186With `model patch` you build the instrument yourself as a signal graph. The graph describes187one voice; the runtime plays as many voices as there are simultaneous notes.188189```sonata190instrument SoftSaw {191    model patch192    graph {193        node osc = saw(freq: note.freq) + saw(freq: note.freq * 1.006) * 0.7194        node env = adsr(attack: 20ms, decay: 300ms, sustain: 0.7, release: 500ms)195        node tone = lowpass(in: osc, cutoff: 600Hz + env * 2500, q: 1.2)196        out tone * env * note.velocity * 0.4197    }198}199200composition "A Patch" {201    tempo 90bpm202    instrument pad: SoftSaw {203        chord [C3, G3, E4] duration 1/1204    }205}206```207208* `node name = expression` names a signal. `out expression` is the output of the voice; a209  graph has exactly one.210* A call such as `saw(…)` or `lowpass(…)` creates a node. Ports are given by name; a port211  left out takes its default. All node kinds and their ports are in212  [Patch nodes](reference/patch-nodes.md).213* `note.freq`, `note.pitch`, `note.velocity`, `note.gate` and `note.time` are the inputs of214  the note being played.215* `+`, `-` and `*` between signals mix and modulate them. Next to a signal, a value with a216  unit is its number in the base unit: hertz, seconds, semitones, decibels.217* The envelope multiplied into the output decides when a voice ends: when it reaches zero218  after the note is released.219220A node can only read nodes defined above it, with one exception that makes feedback possible:221the `in` port of a `delay` may read a node defined later.222223```sonata224instrument Pluck {225    model patch226    release 1.5s227    graph {228        node burst = noise() * adsr(attack: 0ms, decay: 4ms, sustain: 0, release: 4ms)229        // A string tuned to A3: a delay of one period of 220 Hz (4.545 ms), fed back230        // through a gentle low-pass.231        node string = delay(in: looped, time: 4.545ms)232        node looped = burst + lowpass(in: string, cutoff: 3000Hz) * 0.985233        out looped * adsr(attack: 0ms, decay: 1.5s, sustain: 0, release: 300ms)234    }235}236237composition "Feedback Through a Delay" {238    instrument pluck: Pluck {239        play A3 duration 1/1240    }241}242```243244A loop that does not pass through a delay has no meaning — a sample cannot depend on itself —245and is refused:246247```sonata,error=G5002248instrument Loop {249    model patch250    graph {251        node a = lowpass(in: b, cutoff: 500Hz)252        node b = a * 0.5253        out b254    }255}256257composition "Not Causal" {258    instrument x: Loop {259        play C4260    }261}262```263264The example `Examples/patch_drum_machine.sonata` builds a kick, a snare and a hi-hat this way,265and `Examples/subtractive_patch.sonata` a filtered lead and a modal bell.266267## Parameters that move268269Parameters marked *automatable* in the reference can change during the piece, with270`automate instrument.NAME`:271272```sonata273composition "A Moving Filter" {274    tempo 120bpm275    instrument pad: SynthPad {276        gain -8dB277        automate instrument.filter.cutoff {278            0bars: 300Hz279            2bars: 5000Hz exp280        }281        chord [D3, A3, F4] duration 2bars282    }283}284```285286More in [Mixing](mixing.md#automation). The **Instrument Lab** space287([Instrument Lab](instrument-lab.md)) edits these parameters with sliders, plays the result288from a keyboard and writes the definition for you.289
Files main
Menu

Theme