{
 "lyplug": 1,
 "manifest": {
  "format": 1,
  "name": "Soft Saw",
  "author": "Lyreto",
  "version": "1.0.0",
  "kind": "instrument",
  "description": "A minimal instrument: a sawtooth through a gentle low-pass with an attack/release envelope.",
  "params": [
   {
    "id": "cutoff",
    "name": "Cutoff",
    "min": 100,
    "max": 12000,
    "default": 2400,
    "unit": "Hz",
    "log": true
   },
   {
    "id": "attack",
    "name": "Attack",
    "min": 1,
    "max": 1000,
    "default": 5,
    "unit": "ms",
    "log": true
   },
   {
    "id": "release",
    "name": "Release",
    "min": 10,
    "max": 3000,
    "default": 250,
    "unit": "ms",
    "log": true
   },
   {
    "id": "level",
    "name": "Level",
    "min": 0,
    "max": 1,
    "default": 0.6
   }
  ],
  "ui": {
   "layout": [
    [
     "cutoff",
     "attack",
     "release",
     "level"
    ]
   ],
   "accent": "#f0b232"
  }
 },
 "code": "// Soft Saw: one voice per note. process() returns false when the note has faded out.\nplugin({\n  voice(host, note, velocity) {\n    const freq = 440 * Math.pow(2, (note - 69) / 12);\n    const inc = freq / host.sampleRate;\n    let phase = 0, env = 0, low = 0, released = false;\n    return {\n      process(output, p, frames) {\n        const up = 1 / Math.max(1, p.attack * 0.001 * host.sampleRate);\n        const down = Math.exp(-1 / Math.max(1, p.release * 0.001 * host.sampleRate));\n        const k = 1 - Math.exp(-2 * Math.PI * p.cutoff / host.sampleRate);\n        const L = output[0], R = output[1];\n        for (let n = 0; n < frames; n++) {\n          env = released ? env * down : Math.min(1, env + up);\n          phase += inc; if (phase >= 1) phase -= 1;\n          low += (2 * phase - 1 - low) * k;\n          const s = low * env * velocity * p.level * 0.5;\n          L[n] += s; R[n] += s;\n        }\n        return !released || env > 0.0001;\n      },\n      release() { released = true; }\n    };\n  }\n});\n"
}