{
  "$type": "at.atmosynth.module",
  "descriptionVersion": 1,
  "moduleId": "chorus-bbd",
  "versionKey": "2",
  "name": "Bucket-brigade chorus",
  "description": "The Roland Juno-6's chorus as a module, as one was heard to play: one triangle wave moving two bucket-brigade delay lines in opposite directions, one heard on each side beside the sound that came in, so while the left copy falls behind the right one catches up and the sound spreads out between the speakers. Mode is the Juno's three buttons. II sweeps each line between 1.14 and 5.60 milliseconds about two thirds of a time a second (0.68 Hz), and I is the same sweep slower (0.405 Hz), the gentle one. The copies' pitch moves about a ninth of a semitone either way in II and about half that in I, and what the wide sweep adds is the slow swirl of their peaks and notches across the sound. I+II is a quick shallow shimmer, 9.75 times a second between 3.3 and 3.7 milliseconds, its wave rounded nearly to a sine, which is closer to a rotary speaker than a chorus. Changing Mode while a note sounds glides from one to the next rather than clicking. Mix goes from the sound alone to the two lines alone, keeping the sound about as loud as it went in; it starts at 0.6, the Juno's own balance, where each line is a little under three decibels louder than the sound beside it, which is most of how wide the Juno is. Half way the two are at one level. What makes it a bucket-brigade chorus rather than the plain one: the lines are dark, filtered either side as a bucket-brigade line has to be, so the copies are softer than the sound beside them; a line is a row of buckets handed along at a clock, so as it lengthens its clock slows and it darkens a little further, and brightens again as it shortens, with every sweep; loud chords come out of the line rounded off, where quiet ones pass untouched; and the line hisses. Hiss is how much: where it starts, as quietly as the Juno, some seventy decibels under what is played, and at the top ten times that, a faint wash that is plainly there. It hisses under whatever is played and for a second after the last of it, then lets the hiss go over a second more, so a patch that has stopped playing falls silent and an export of it ends; the next sound brings the hiss straight back. A mono sound in comes out in stereo; a stereo one keeps its two sides in the dry path, and the lines are handed the two together. It holds a few milliseconds of sound past the note that made it, so it is added shared, as an effect at the end of the chain is. Version 1 is the same chorus at the figures published for the Juno-60, its sweep narrower and quicker, its lines at the sound's own level and its hiss twenty-two decibels louder. For a chorus with every setting free — its rate, its delay, its depth, the shape of its wave — the plain chorus is beside it. This module carries code, because a bucket-brigade line's darkening follows its clock, and its clock is the number of buckets divided by the delay, which nothing else here can divide by; and because nothing else here makes the random signal its hiss is.",
  "audioInputs": [
    {
      "id": "in",
      "label": "In"
    }
  ],
  "audioOutputs": [
    {
      "id": "out",
      "label": "Out"
    }
  ],
  "midiInputs": [],
  "nodes": [
    {
      "id": "in",
      "kind": "moduleInput",
      "options": {
        "input": "in"
      }
    },
    {
      "id": "bbd",
      "kind": "dsp",
      "options": {
        "code": "// A bucket-brigade chorus, built as the Roland Juno-6's is: one triangle LFO\n// moving two delay lines of 256 buckets each, the second line's movement\n// turned upside down, so while the left copy falls behind the right one\n// catches up. Each side is what came in plus its own line, and the two lines\n// disagreeing is the width.\n//\n// The three settings are the Juno's buttons, as a Juno-6 was heard to play\n// them: II sweeps each line between 1.14 and 5.60 milliseconds at 0.68 Hz,\n// which two recordings of it agree on to a few hundredths of a hertz and a\n// twentieth of a millisecond, and I is the same sweep, slower. I was played\n// for less than a whole sweep, which put its rate between 0.39 and 0.46 Hz;\n// 0.405 is where the figures published for the Juno-60, 0.513 and 0.863, put\n// it once II is where this unit has it. I+II, a fast, shallow shimmer at 9.75\n// Hz between 3.3 and 3.7 — where the Juno's triangle comes out rounded nearly\n// to a sine, as it is here — is those published figures still, since nobody\n// has heard the Juno-6 do it yet. Moving between them glides the\n// sweep's middle, its width and its shape over a few hundredths of a second,\n// so a change while a note sounds bends it rather than clicking.\n//\n// A bucket-brigade line is a row of capacitors that hand what they hold along\n// at a clock, so its delay is the count of buckets over twice the clock, and\n// the clock is what moves: a longer delay is a slower clock. What reaches the\n// end is the sound held a clock tick at a time, and a hold loses the top by\n// how long it holds — half its power at 0.443 of the clock — so the line\n// darkens as it lengthens and brightens as it shortens, a little, twice a\n// sweep. That is one over the delay, worked out every sample, which is why\n// this is code. Around the line are the filters every such line needs, which\n// darken it for good: two poles at nine kilohertz before it, so nothing the\n// clock cannot carry gets in, and two after it, to take the steps of the hold\n// away.\n//\n// The buckets are capacitors with a limit, and the line rounds what it\n// carries as it nears it: the ladder's rational tanh, a curve half as wide\n// again as full scale, so a loud chord comes out of the line softened while a\n// quiet one passes untouched. The curve is the same either side of nothing,\n// but a wave that is not — a narrow pulse, a sawtooth a filter has rounded —\n// comes out of it a little off centre, so the line is filled through a\n// one-pole at 5 Hz that takes that lean off below any note. And the line\n// hisses: noise at its end, at a level Hiss sets, darkened by everything after\n// it, under whatever is played and for a while after it.\nimport { AtmoProcessor, Rng } from \"atmosynth:dsp\";\n\nfunction clamp(value, low, high) {\n  return value < low ? low : value > high ? high : value;\n}\n\n// Buckets in each line: the MN3009's 256.\nconst STAGES = 256;\n// How long a change of setting takes to settle, in seconds.\nconst GLIDE = 0.03;\n// The filters either side of the line, two poles each.\nconst CORNER = 9000;\n// Where a hold loses half its power, as a share of its clock.\nconst HOLD = 0.443;\n// How wide the line's curve is beside full scale.\nconst WIDTH = 1.5;\n// The hiss at the top of the knob, at the line's end before its filters: ten\n// times the Juno's, which is where the knob starts. The Juno-6 hisses some\n// seventy decibels under what is played through it, quiet enough that a\n// recording of one holds it only just over its own noise.\nconst HISS = 0.0024;\n// The hiss is let go of once nothing has come in for a while and taken up\n// again with the next sound, so a patch that has finished playing falls\n// silent — an export of it finds its end, where a hiss that never stopped\n// would ring to the end of the render — while under anything played it hisses\n// as it always did. Anything under −80 dB is nothing, which is where an\n// export takes silence to start too. The hiss stays a second past the last\n// sound, nearly two hundred times the longest the line holds anything (5.6 ms), so\n// the line's own tail is always heard out with its hiss under it, and a rest\n// of up to a second — a half note at 120 — passes with the hiss unmoved\n// rather than pumping between the notes of a phrase. Then it goes over a\n// second more, so a longer rest hears it thin away rather than stop, and it\n// comes back over a hundredth of a second, under the start of whatever\n// brought it back. Straight lines counted in samples, so the plugin's port\n// arrives at every value the program does.\nconst QUIET = 1e-4;\nconst LINGER = 1;\nconst FADE = 1;\nconst RETURN = 0.01;\n\n// The ladder's tanh, near enough: x(27 + x²) / (27 + 9x²), arriving at one at\n// three with no slope left. Arithmetic and nothing else, so the plugin works it\n// out to the same double.\nfunction soft(value) {\n  return value > 3 ? 1 : value < -3 ? -1 : (value * (27 + value * value)) / (27 + 9 * value * value);\n}\n\n// A table the constructor makes, one entry for each of the three settings.\nfunction table(first, second, third) {\n  const values = new Float64Array(3);\n  values[0] = first;\n  values[1] = second;\n  values[2] = third;\n  return values;\n}\n\nexport default class AtmosynthBbdChorus extends AtmoProcessor {\n  static spec = 1;\n  static inputs = [2];\n  static outputs = [2];\n  // Not smoothed here: a knob's move reaches these already eased.\n  static params = {\n    // Which of the three, by the Mode choice's position: I, II and I+II.\n    // Rounded, since a choice turned by a controller glides between\n    // positions on its way to one.\n    mode: { min: 0, max: 2, default: 0, rate: \"k\", smooth: 0 },\n    // From what came in alone to the two lines alone.\n    mix: { min: 0, max: 1, default: 0.6, rate: \"a\", smooth: 0 },\n    hiss: { min: 0, max: 1, default: 0.1, rate: \"k\", smooth: 0 },\n  };\n\n  constructor() {\n    super();\n    this.rng = new Rng(this.seed);\n    // Each setting's LFO rate in hertz, the middle of the sweep and how far it\n    // goes either side in seconds, and how far the wave is rounded from a\n    // triangle to a sine.\n    this.rates = table(0.405, 0.68, 9.75);\n    this.middles = table(0.00337, 0.00337, 0.0035);\n    this.depths = table(0.00223, 0.00223, 0.0002);\n    this.roundings = table(0, 0, 1);\n    // One line carries what both sides read, since both lines on the Juno are\n    // handed the same sound; each side reads it at its own delay. Longer than\n    // the longest delay by the four samples a reading between two needs.\n    this.size = Math.ceil(0.006 * sampleRate) + 4;\n    this.line = new Float64Array(this.size);\n    this.write = 0;\n    this.phase = 0;\n    // The sweep as it stands, gliding to the setting's; set outright the\n    // first time, so the chorus does not glide in from nothing.\n    this.settled = false;\n    this.middle = 0;\n    this.depth = 0;\n    this.rounding = 0;\n    // The mix the two levels below were last worked out for.\n    this.mix = 0 / 0;\n    this.dryLevel = 0;\n    this.wetLevel = 0;\n    const g = Math.tan((Math.PI * CORNER) / sampleRate);\n    this.corner = g / (1 + g);\n    this.glide = 1 / (GLIDE * sampleRate);\n    this.ceiling = 0.45 * sampleRate;\n    // The integrators: the two poles before the line, and after it on each\n    // side the hold's and the two poles of the filter after the line.\n    this.before1 = 0;\n    this.before2 = 0;\n    // The 5 Hz one-pole the rounded sound is filled into the line through,\n    // and the two samples it remembers.\n    this.pole = 1 - (2 * Math.PI * 5) / sampleRate;\n    this.lastBent = 0;\n    this.centred = 0;\n    this.hold = new Float64Array(2);\n    this.after1 = new Float64Array(2);\n    this.after2 = new Float64Array(2);\n    // How many samples nothing has come in for, counted no further than the\n    // linger, and how far open the hiss is, from shut to one. It starts shut,\n    // as if the quiet had been going on for ever: nothing has passed yet.\n    this.linger = LINGER * sampleRate;\n    this.quiet = this.linger;\n    this.open = 0;\n    this.fall = 1 / (FADE * sampleRate);\n    this.rise = 1 / (RETURN * sampleRate);\n  }\n\n  // The line read `behind` samples before the one just written, between two\n  // samples where that is not a whole number: a cubic through the four nearest,\n  // which keeps the top a straight line between two would lose.\n  read(behind) {\n    const line = this.line;\n    const size = this.size;\n    let at = this.write - behind;\n    if (at < 0) at += size;\n    const whole = Math.floor(at);\n    const fraction = at - whole;\n    const y0 = line[whole === 0 ? size - 1 : whole - 1];\n    const y1 = line[whole];\n    const y2 = line[whole + 1 >= size ? whole + 1 - size : whole + 1];\n    const y3 = line[whole + 2 >= size ? whole + 2 - size : whole + 2];\n    const c1 = 0.5 * (y2 - y0);\n    const c2 = y0 - 2.5 * y1 + 2 * y2 - 0.5 * y3;\n    const c3 = 0.5 * (y3 - y0) + 1.5 * (y1 - y2);\n    return ((c3 * fraction + c2) * fraction + c1) * fraction + y1;\n  }\n\n  process(inputs, outputs, parameters) {\n    const input = inputs[0];\n    const output = outputs[0];\n    const frames = output[0].length;\n    // In a worklet `sampleRate` is an accessor on the global scope rather than\n    // a variable, so it is read once a block.\n    const contextRate = sampleRate;\n    const mode = clamp(Math.round(parameters.mode[0]), 0, 2);\n    const rate = this.rates[mode] / contextRate;\n    const hiss = HISS * parameters.hiss[0];\n    const mixes = parameters.mix;\n    if (!this.settled) {\n      this.settled = true;\n      this.middle = this.middles[mode];\n      this.depth = this.depths[mode];\n      this.rounding = this.roundings[mode];\n    }\n    const corner = this.corner;\n\n    for (let index = 0; index < frames; index += 1) {\n      // A mono source arrives on both sides, and nothing as silence on both.\n      const left = input[0][index];\n      const right = input[1][index];\n\n      // Whether anything is coming in, and the hiss opening or shutting by it.\n      if (Math.abs(left) > QUIET || Math.abs(right) > QUIET) this.quiet = 0;\n      else if (this.quiet < this.linger) this.quiet += 1;\n      this.open =\n        this.quiet < this.linger\n          ? Math.min(1, this.open + this.rise)\n          : Math.max(0, this.open - this.fall);\n      const noise = hiss * this.open;\n\n      // Both lines are handed the two sides as one, through the two poles\n      // before them and rounded as the buckets fill, and what the rounding\n      // leaves off centre is taken off under 5 Hz.\n      let v = (0.5 * (left + right) - this.before1) * corner;\n      const once = v + this.before1;\n      this.before1 = once + v;\n      v = (once - this.before2) * corner;\n      const twice = v + this.before2;\n      this.before2 = twice + v;\n      const bent = WIDTH * soft(twice / WIDTH);\n      this.centred = bent - this.lastBent + this.pole * this.centred;\n      this.lastBent = bent;\n      this.line[this.write] = this.centred;\n\n      // The sweep glides to the setting's, and settles there exactly.\n      this.middle += (this.middles[mode] - this.middle) * this.glide;\n      this.depth += (this.depths[mode] - this.depth) * this.glide;\n      this.rounding += (this.roundings[mode] - this.rounding) * this.glide;\n      if (Math.abs(this.middles[mode] - this.middle) < 1e-12) this.middle = this.middles[mode];\n      if (Math.abs(this.depths[mode] - this.depth) < 1e-12) this.depth = this.depths[mode];\n      if (Math.abs(this.roundings[mode] - this.rounding) < 1e-9) this.rounding = this.roundings[mode];\n\n      // The triangle, from the bottom at nothing to the top half way, and the\n      // sine it is rounded towards, in step with it.\n      const phase = this.phase;\n      const triangle = phase < 0.5 ? 4 * phase - 1 : 3 - 4 * phase;\n      const rounded = this.rounding > 0 ? -Math.cos(2 * Math.PI * phase) : 0;\n      const wave = triangle + this.rounding * (rounded - triangle);\n      // Equal power: half way is the two at one level, and 0.6 the Juno's own,\n      // each line a little under three decibels over the sound beside it; as\n      // loud as what came in, at any mix, wherever the two are unlike.\n      const mix = mixes[index];\n      if (mix !== this.mix) {\n        this.mix = mix;\n        this.dryLevel = Math.cos(mix * (Math.PI / 2));\n        this.wetLevel = Math.sin(mix * (Math.PI / 2));\n      }\n\n      for (let side = 0; side < 2; side += 1) {\n        // The second line's movement upside down.\n        const delay = side === 0 ? this.middle + this.depth * wave : this.middle - this.depth * wave;\n        // The dice are rolled whether the hiss is open or not, so the noise\n        // is where it would be whichever way the quiet fell.\n        let wet = this.read(delay * contextRate) + noise * this.rng.bipolar();\n\n        // The hold, darker as the clock slows; then the two poles after it.\n        const clock = STAGES / (2 * delay);\n        const g = Math.tan((Math.PI * Math.min(HOLD * clock, this.ceiling)) / contextRate);\n        v = (wet - this.hold[side]) * (g / (1 + g));\n        wet = v + this.hold[side];\n        this.hold[side] = wet + v;\n        v = (wet - this.after1[side]) * corner;\n        wet = v + this.after1[side];\n        this.after1[side] = wet + v;\n        v = (wet - this.after2[side]) * corner;\n        wet = v + this.after2[side];\n        this.after2[side] = wet + v;\n\n        const dry = side === 0 ? left : right;\n        output[side][index] = this.dryLevel * dry + this.wetLevel * wet;\n      }\n\n      this.phase = phase + rate >= 1 ? phase + rate - 1 : phase + rate;\n      this.write = this.write + 1 >= this.size ? 0 : this.write + 1;\n    }\n    return true;\n  }\n}\n",
        "tail": true
      }
    },
    {
      "id": "out",
      "kind": "moduleOutput",
      "options": {
        "output": "out"
      }
    }
  ],
  "connections": [
    {
      "from": {
        "node": "in",
        "output": 0
      },
      "to": {
        "node": "bbd",
        "input": 0
      }
    },
    {
      "from": {
        "node": "bbd",
        "output": 0
      },
      "to": {
        "node": "out",
        "input": 0
      }
    }
  ],
  "automation": [],
  "parameters": [
    {
      "id": "mode",
      "label": "Mode",
      "values": [
        "I",
        "II",
        "I+II"
      ],
      "default": "I",
      "targets": [
        {
          "node": "bbd",
          "param": "mode"
        }
      ]
    },
    {
      "id": "mix",
      "label": "Mix (dry to wet)",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.6",
      "targets": [
        {
          "node": "bbd",
          "param": "mix"
        }
      ]
    },
    {
      "id": "hiss",
      "label": "Hiss",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.1",
      "targets": [
        {
          "node": "bbd",
          "param": "hiss"
        }
      ]
    }
  ],
  "sampleSlots": [],
  "createdAt": "2026-10-15T00:00:00.000Z"
}