{
  "$type": "at.atmosynth.module",
  "descriptionVersion": 1,
  "moduleId": "909-kick",
  "versionKey": "1",
  "name": "909 Kick",
  "description": "The bass drum of the 909, played by any note: a deep thud whose pitch is thrown up by the strike and falls back, a body that dies away, and a click on the front of it. Every key plays the same kick. Tune is where the pitch comes to rest, in hertz. Sweep is how far above that a hit starts, in semitones, and Sweep time how long it takes to fall nine tenths of the way: it falls as the circuit's does, fast at the top and slowly at the bottom. Click is the attack, a pulse and a burst of noise. Hold keeps the body at full before it starts to fall, which the hardware cannot do: at nothing it is the hardware's decay, and held with a short tail it is the flat, heavy kick that ends on a cut. Tail is how long the body then takes to fall sixty decibels. Fatness pushes the core past its swing, so the round wave fills out towards a square, louder for the same peak. How hard a note is struck is the accent: struck hardest, the knobs are as set, and softer is quieter, with less click and less fatness. It is one kick at a time, as the hardware is: a hit cuts the one still ringing, whichever key struck either, fading it out under itself in two milliseconds. That holds where the block is shared, as it is when it is added; built for each note instead, each hit is a copy of its own and is not cut this way. This module carries code: a hit starts its wave over from nothing, as the hardware's does, while the hit it cut fades out, and an oscillator in the vocabulary can neither be started over nor sound two hits at once.",
  "audioInputs": [],
  "audioOutputs": [
    {
      "id": "out",
      "label": "Out"
    }
  ],
  "midiInputs": [
    {
      "id": "midi",
      "label": "Note"
    }
  ],
  "nodes": [
    {
      "id": "kick",
      "kind": "dsp",
      "options": {
        "code": "// The bass drum of the 909: a triangle core bent into a sine, its pitch thrown\n// up by the strike and falling back, a body that holds and then dies away, and\n// a click on the front of it.\n//\n// **The core** is a triangle, as the circuit's is: an integrator ramping up and\n// down between two thresholds. The circuit bends it towards a sine with a\n// shaper, and here the bend is a sine of the triangle, `sin(π/2 × triangle)`,\n// which is a sine exactly while the triangle stays inside its swing. Fatness\n// pushes the triangle past the swing before the bend, so its tops are flattened\n// where the sine is already flat: the wave fills out towards a square, louder\n// for the same peak and with odd harmonics on it, and the corners land where\n// the slope is nothing, so it stays clean at a kick's pitch.\n//\n// **The sweep** is the circuit's: a capacitor charged by the strike and\n// discharging into the oscillator's frequency control, which is linear in hertz.\n// So the pitch falls towards Tune exponentially in hertz, not in semitones, fast\n// at the top and slowly at the bottom, and that is the shape of the thud. Sweep\n// is how far above Tune it starts, in semitones; Sweep time is how long it takes\n// to fall nine tenths of the way.\n//\n// **The body** stays at full for Hold and then falls sixty decibels in Tail. The\n// hardware has no Hold, and at nothing this is its decay exactly; a held body\n// with a short tail is the flat, heavy kick that ends on a cut.\n//\n// **The click** is the circuit's attack: a pulse from the trigger and a burst\n// of noise, together through a band from 400 Hz to 6 kHz, gone in a few\n// milliseconds. Click is how loud it is.\n//\n// **Accent** is how hard the note was struck. Full is the knobs as they are set;\n// softer is quieter, with less click and less of Fatness, as the hardware's\n// accent is all three.\n//\n// **One kick at a time.** The hardware has one voice, and a hit restarts it\n// wherever the last one had got to. Here a hit starts afresh in the other of two\n// slots and the one still ringing fades out under it over two milliseconds, so\n// the tail is cut as the hardware cuts it without a click of its own. Played as\n// a shared block, every note reaching it is a hit on that one voice, whatever\n// key struck it; a copy built for each note hears only its own.\n//\n// **The gate** is a constant the module's automation steps up at the note and\n// down after it, there only to hold a copy built for one note open for as long\n// as its hit can last, a Hold and a Tail at their longest, after the key is up.\n// The program reads nothing from it.\nimport { AtmoProcessor, Rng, fill } from \"atmosynth:dsp\";\n\nconst HALF_PI = Math.PI / 2;\nconst TWO_PI = 2 * Math.PI;\n/**\n * A fall of sixty decibels and a fall to a tenth, as natural logarithms:\n * `Math.log(1000)` and `Math.log(10)`, written out, since a top-level constant\n * cannot call a logarithm.\n */\nconst SIXTY_DB = 6.907755278982137;\nconst TENTH = 2.302585092994046;\n/**\n * How far past the swing the triangle is pushed at Fatness one, struck hard:\n * sixteen times, near enough a square. Fatness is squared on its way there, so\n * the first part of the knob is a sine growing a third harmonic and the rest is\n * the fill towards the square; on a straight line the knob was a square from a\n * fifth of the way up.\n */\nconst DRIVE_MOST = 15;\n/** The level of the softest note, as a share of the hardest's. */\nconst SOFTEST = 0.35;\n/** How long a hit cut by the next takes to fall silent, in seconds. */\nconst CROSS = 0.002;\n/** Below this, a hit is over. */\nconst SILENT = 0.00001;\n/** How fast the click's pulse and its noise die, in seconds to a third. */\nconst PULSE_FALL = 0.0006;\nconst NOISE_FALL = 0.0025;\n/** The click's band, in hertz. */\nconst CLICK_LOW = 400;\nconst CLICK_HIGH = 6000;\n/** The click's pulse and noise, as shares of it, and its level at Click one. */\nconst PULSE_SHARE = 1;\nconst NOISE_SHARE = 0.5;\nconst CLICK_GAIN = 0.9;\n\nexport default class AtmosynthKick909 extends AtmoProcessor {\n  static spec = 1;\n  static inputs = [];\n  static outputs = [1];\n  // Not smoothed here: a knob's move reaches these already eased.\n  static params = {\n    // Where the pitch comes to rest, in hertz.\n    tune: { min: 20, max: 200, default: 55, rate: \"k\", smooth: 0 },\n    // How far above it a hit starts, in semitones.\n    sweep: { min: 0, max: 48, default: 24, rate: \"k\", smooth: 0 },\n    // How long the pitch takes to fall nine tenths of the way, in milliseconds.\n    sweepTime: { min: 1, max: 1000, default: 50, rate: \"k\", smooth: 0 },\n    click: { min: 0, max: 1, default: 0.5, rate: \"k\", smooth: 0 },\n    // How long the body stays at full, in milliseconds.\n    hold: { min: 0, max: 5000, default: 0, rate: \"k\", smooth: 0 },\n    // How long it then takes to fall sixty decibels, in milliseconds.\n    tail: { min: 1, max: 10000, default: 450, rate: \"k\", smooth: 0 },\n    fatness: { min: 0, max: 1, default: 0.15, rate: \"k\", smooth: 0 },\n    level: { min: 0, max: 1, default: 0.8, rate: \"k\", smooth: 0 },\n    gate: { min: 0, max: 1, default: 0, rate: \"k\", smooth: 0 },\n  };\n\n  constructor() {\n    super();\n    this.rng = new Rng(this.seed);\n    // Each of the two slots: whether it sounds, where its core is in its\n    // cycle, how far its sweep has still to fall (one at the strike), its\n    // body's level, how many frames since it was struck, how hard, and the\n    // gain it fades by once a newer hit has cut it, and whether it is fading.\n    this.live = new Float64Array(2);\n    this.phase = new Float64Array(2);\n    this.bend = new Float64Array(2);\n    this.body = new Float64Array(2);\n    this.age = new Float64Array(2);\n    this.strength = new Float64Array(2);\n    this.fade = new Float64Array(2);\n    this.fading = new Float64Array(2);\n    this.newest = 0;\n    // The click, which is only ever the newest hit's.\n    this.clicking = false;\n    this.pulse = 0;\n    this.noise = 0;\n    this.clickStrength = 0;\n    this.low = 0;\n    this.high = 0;\n    this.pulseFall = Math.exp(-1 / (PULSE_FALL * sampleRate));\n    this.noiseFall = Math.exp(-1 / (NOISE_FALL * sampleRate));\n    this.lowCoefficient = 1 - Math.exp((-TWO_PI * CLICK_LOW) / sampleRate);\n    this.highCoefficient = 1 - Math.exp((-TWO_PI * CLICK_HIGH) / sampleRate);\n    this.fadeStep = 1 / (CROSS * sampleRate);\n  }\n\n  noteOn(note, velocity) {\n    const previous = this.newest;\n    const next = 1 - previous;\n    if (this.live[previous] !== 0) this.fading[previous] = 1;\n    // The other slot may still be fading from the hit before: it is let go.\n    this.live[next] = 1;\n    this.phase[next] = 0;\n    this.bend[next] = 1;\n    this.body[next] = 1;\n    this.age[next] = 0;\n    this.strength[next] = velocity;\n    this.fade[next] = 1;\n    this.fading[next] = 0;\n    this.newest = next;\n    this.clicking = true;\n    this.pulse = 1;\n    this.noise = 1;\n    this.clickStrength = velocity;\n  }\n\n  process(inputs, outputs, parameters) {\n    const out = outputs[0][0];\n    const frames = out.length;\n    if (this.live[0] === 0 && this.live[1] === 0 && !this.clicking) {\n      fill(out, 0);\n      return true;\n    }\n    const tune = parameters.tune[0];\n    const swing = tune * Math.pow(2, parameters.sweep[0] / 12) - tune;\n    const fall = Math.exp(-TENTH / ((parameters.sweepTime[0] / 1000) * sampleRate));\n    const holdFrames = (parameters.hold[0] / 1000) * sampleRate;\n    const decay = Math.exp(-SIXTY_DB / ((parameters.tail[0] / 1000) * sampleRate));\n    const fatness = parameters.fatness[0];\n    const level = parameters.level[0];\n    const click = parameters.click[0] * CLICK_GAIN * level;\n    const fadeStep = this.fadeStep;\n    fill(out, 0);\n    for (let slot = 0; slot < 2; slot += 1) {\n      if (this.live[slot] === 0) continue;\n      const strength = this.strength[slot];\n      const drive = 1 + DRIVE_MOST * fatness * fatness * (0.5 + 0.5 * strength);\n      const gain = level * (SOFTEST + (1 - SOFTEST) * strength);\n      const fading = this.fading[slot] !== 0;\n      let phase = this.phase[slot];\n      let bend = this.bend[slot];\n      let body = this.body[slot];\n      let age = this.age[slot];\n      let fade = this.fade[slot];\n      let live = true;\n      for (let index = 0; index < frames; index += 1) {\n        const frequency = tune + swing * bend;\n        // The triangle: up from nothing to the top in the first quarter, down\n        // to the bottom by the third, and back up to nothing.\n        let triangle = 4 * phase;\n        if (phase >= 0.75) triangle = 4 * phase - 4;\n        else if (phase >= 0.25) triangle = 2 - 4 * phase;\n        let pushed = drive * triangle;\n        if (pushed > 1) pushed = 1;\n        else if (pushed < -1) pushed = -1;\n        out[index] += gain * body * fade * Math.sin(HALF_PI * pushed);\n        phase += frequency / sampleRate;\n        if (phase >= 1) phase -= 1;\n        bend *= fall;\n        age += 1;\n        if (age > holdFrames) body *= decay;\n        if (fading) {\n          fade -= fadeStep;\n          if (fade <= 0) {\n            live = false;\n            break;\n          }\n        }\n        if (body < SILENT) {\n          live = false;\n          break;\n        }\n      }\n      this.phase[slot] = phase;\n      this.bend[slot] = bend;\n      this.body[slot] = body;\n      this.age[slot] = age;\n      this.fade[slot] = fade;\n      this.live[slot] = live ? 1 : 0;\n    }\n    if (this.clicking) {\n      const gain = click * this.clickStrength;\n      for (let index = 0; index < frames; index += 1) {\n        const raw = PULSE_SHARE * this.pulse + NOISE_SHARE * this.noise * this.rng.bipolar();\n        this.pulse *= this.pulseFall;\n        this.noise *= this.noiseFall;\n        this.high += this.highCoefficient * (raw - this.high);\n        this.low += this.lowCoefficient * (this.high - this.low);\n        out[index] += gain * (this.high - this.low);\n      }\n      if (this.noise < SILENT) this.clicking = false;\n    }\n    return true;\n  }\n}\n",
        "tail": true
      }
    },
    {
      "id": "gate",
      "kind": "constantSource",
      "options": {}
    },
    {
      "id": "out",
      "kind": "moduleOutput",
      "options": {
        "output": "out"
      }
    }
  ],
  "connections": [
    {
      "from": {
        "node": "kick",
        "output": 0
      },
      "to": {
        "node": "out",
        "input": 0
      }
    },
    {
      "from": {
        "node": "gate",
        "output": 0
      },
      "to": {
        "node": "kick",
        "param": "gate"
      }
    }
  ],
  "automation": [
    {
      "id": "gate",
      "label": "Gate",
      "target": {
        "node": "gate",
        "param": "offset"
      },
      "breakpoints": [
        {
          "time": 0,
          "value": "1",
          "curve": "step"
        },
        {
          "time": 0,
          "value": "0",
          "curve": "step"
        },
        {
          "time": 3000,
          "value": "0",
          "curve": "step"
        }
      ],
      "sustainAt": 0
    }
  ],
  "parameters": [
    {
      "id": "tune",
      "label": "Tune (Hz)",
      "range": {
        "min": "30",
        "max": "120"
      },
      "default": "55",
      "targets": [
        {
          "node": "kick",
          "param": "tune"
        }
      ],
      "scale": "log"
    },
    {
      "id": "sweep",
      "label": "Sweep (semitones)",
      "range": {
        "min": "0",
        "max": "36"
      },
      "default": "24",
      "targets": [
        {
          "node": "kick",
          "param": "sweep"
        }
      ]
    },
    {
      "id": "sweepTime",
      "label": "Sweep time (ms)",
      "range": {
        "min": "5",
        "max": "300"
      },
      "default": "50",
      "targets": [
        {
          "node": "kick",
          "param": "sweepTime"
        }
      ],
      "scale": "log"
    },
    {
      "id": "click",
      "label": "Click",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.5",
      "targets": [
        {
          "node": "kick",
          "param": "click"
        }
      ]
    },
    {
      "id": "hold",
      "label": "Hold (ms)",
      "range": {
        "min": "0",
        "max": "1000"
      },
      "default": "0",
      "targets": [
        {
          "node": "kick",
          "param": "hold"
        }
      ]
    },
    {
      "id": "tail",
      "label": "Tail (ms to silence)",
      "range": {
        "min": "10",
        "max": "2000"
      },
      "default": "450",
      "targets": [
        {
          "node": "kick",
          "param": "tail"
        }
      ],
      "scale": "log"
    },
    {
      "id": "fatness",
      "label": "Fatness",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.15",
      "targets": [
        {
          "node": "kick",
          "param": "fatness"
        }
      ]
    },
    {
      "id": "level",
      "label": "Level",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.8",
      "targets": [
        {
          "node": "kick",
          "param": "level"
        }
      ]
    }
  ],
  "sampleSlots": [],
  "createdAt": "2026-11-13T00:00:00.000Z"
}