
VertexArt – successful implementation of a pure Free Pascal FLAC encoder and WAV export in my procedural music editor.
# Procedural Music Editor in Free Pascal – Sound DnB (9)
program dnb9;
{$mode objfpc}{$H+}
{$APPTYPE CONSOLE}
uses
SysUtils,
Classes, // only for file writing and reading
Math,
glfw3, gl33,
SterilTypes, SterilMath,
SterilWindow,
FrameLimiter,
RenderTypes, RenderQueue, RenderState, ShaderCore, SimpleRenderEngine,
MiniGUI,
AL,
FlacWriter,
SynthUnit;
I'm building a procedural music editor in Free Pascal (Object Pascal). It's a sequencer + synthesizer, currently mono 44.1 kHz for easier development. It produces loops and exports them. The codebase for the export side is a single unit, `FlacWriter.pas`. It's not object-oriented – just a record and functions that take `var` parameters. This fits the DOD style of the rest of the project.
---
## Sound List – Sound DnB 9
The program contains **30 generated sounds**, organized into **5 pages**. Each sound is an independent procedure inside `SynthUnit.pas`. There are no samples, no external files, everything is synthesized at runtime.
---
## 1. DRUMS (10 sounds)
**KICK** – Deep, punchy kick. Pitch envelope from 45 Hz to 180 Hz, with a click on the attack. 40 Hz decay, 6 Hz amplitude envelope.
**SNARE** – Classic snare. 190 Hz tone plus noise. 25 Hz tone decay, 18 Hz noise decay.
**HIHAT** – Closed hi-hat. HP-filtered noise, fast 60 Hz decay.
**OPEN** – Open hi-hat. Same as above, but with a longer release, 7 Hz decay.
**CLAP** – Clap. Four bursts (0 / 8 / 16 / 24 ms) plus a tail.
**RIM** – Rimshot. 800 Hz plus noise. 180 Hz decay, 400 Hz noise.
**TOM** – Tom. Pitch envelope from 80 Hz to 200 Hz. 15 Hz pitch, 8 Hz amplitude.
**RIDE** – Ride cymbal. Four sine waves (6.5 / 7.8 / 9.2 / 11 kHz) plus noise.
**CRASH** – Crash cymbal. Wide spectrum plus shimmer. 12 and 9 kHz shimmer, 1.2 Hz decay.
**SHAKER** – Shaker. HP-filtered noise, 80 Hz decay.
---
## 2. BASS (6 sounds)
**SUB** – Pure sine at 55 Hz. Sidechained. Suited to every deep style.
**REESE** – Two detuned saws (1.01×), SVF LP cutoff with LFO. DnB, dubstep.
**808** – Pitch envelope from 40 Hz to 80 Hz, soft saturation. Trap, hip-hop, DnB.
**FMBS** – FM bass at a 2:1 ratio, index 3.0. Bass house, techno.
**WOBBLE** – LFO-filtered saw at 8 Hz, cutoff between 150 Hz and 950 Hz. Dubstep, DnB.
**ACID** – 303-style saw plus resonant SVF, Q = 3.5, cutoff envelope. Techno, acid house.
---
## 3. SYNTHETIC SOUNDS (8 sounds)
**PAD** – Three detuned saws (±0.5%), 2500 Hz LP. Ambient, trance.
**STAB** – Four detuned saws, fast release. Dub techno, DnB.
**HOOVER** – Pitch-down saw from 1.0 to 0.5, with saturation. Rave, hardstyle.
**PLUCK** – Clean sine, 10 Hz decay. Minimal, dub techno.
**BELL** – FM bell, 1.4 ratio, index 3.0. Ambient, Nanosphere.
**SUPERSAW** – Seven detuned saws (±1.8%), 5000 Hz LP. Trance, EDM, modern DnB.
**EPIANO** – FM Rhodes, with an index that decays from 2.5 to 0. House, lo-fi, jazz.
**CHORD** – Three notes at once (root + third + fifth). House, dub techno.
---
## 4. FX (5 sounds)
**RISER** – HP-filtered noise with a rising envelope. Used before transitions.
**DOWN** – LP-filtered noise with a falling envelope. Used after drops.
**IMPACT** – 40 Hz sine plus a noise burst. Used before drops.
**RVCYM** – Reversed cymbal with a rising envelope. DnB, ambient.
**SUBDROP** – Sub sweeping from 120 Hz down to 25 Hz, plus noise. Used before drops.
---
## 5. AMBIENT (1 sound)
**DRONE** – Two detuned sines (1.0025×), 0.08 Hz LFO. Nanosphere, ambient, dub techno.
---
## Parameters
Every sound receives three parameters on playback.
The **velocity** ranges from 0 to 9, which maps to a volume between 0.0 and 1.0. It can be set independently on each step.
The **length** ranges from 1 to 16 steps. It controls the duration of the sound, again per step.
The **frequency** applies to the melodic sounds only, and is computed as `MELODY[i mod 8] × multiplier`.
The **MELODY** is an eight-note scale, ranging from A1 at 55 Hz up to D3 at 146.83 Hz. Every melodic sound multiplies this scale by a fixed factor:
**Pad** ×2, so 110 Hz when `MELODY[0]` = 55 Hz.
**Stab**, **Hoover**, **Pluck**, **Supersaw**, **EPiano** and **Chord** ×4, so 220 Hz.
**Bell** ×8, so 440 Hz.
**Sub**, **Reese**, **FMBass**, **Wobble** and **Acid** stay fixed at 55 Hz and do not follow the scale.
**Drone** ×1, so 55 Hz.
---
## Pages and Content
The **DRUMS** page holds 10 sounds: Kick, Snare, Hihat, Open, Clap, Rim, Tom, Ride, Crash, Shaker.
The **BASS** page holds 6 sounds: Sub, Reese, 808, FMBS, Wobble, Acid.
The **SYNTH** page holds 8 sounds: Pad, Stab, Hoover, Pluck, Bell, Supersaw, EPiano, Chord.
The **FX** page holds 5 sounds: Riser, Down, Impact, RevCymbal, SubDrop.
The **AMBIENT** page holds 1 sound: Drone.
The grid displays 8 rows at a time; the rest is reachable with the mouse wheel.
---
## Effects on the Sounds
The sounds go through the master FX chain dry. There, in order:
First, the **sidechain** acts, but only on the bass sounds (Sub, Reese, 808, FMBS, Wobble, Acid).
Then comes the **drive**, which is oversampled tanh plus a DC blocker.
Next, the **master EQ** with three bands: low shelf at 200 Hz, peak at 3 kHz, high shelf at 6 kHz.
After that, the **reverb**, which is Schroeder-based, with adjustable size, decay and damp.
Then the **compressor** with threshold, ratio, attack, release and makeup parameters.
Then the **limiter**, using the ceiling value.
Finally, the **out gain**, the **peak normalize** stage, and the **16-bit conversion**.