{
 "lyplug": 1,
 "manifest": {
  "format": 1,
  "name": "Bitcrusher",
  "author": "Lyreto",
  "version": "1.0.0",
  "kind": "effect",
  "description": "Lo-fi: fewer bits and a lower sample rate. The built-in Bitcrusher, as a Lyreto plugin.",
  "params": [
   {
    "id": "bits",
    "name": "Bits",
    "min": 1,
    "max": 16,
    "default": 8,
    "step": 1
   },
   {
    "id": "down",
    "name": "Downsample",
    "min": 1,
    "max": 40,
    "default": 4,
    "step": 1,
    "unit": "x"
   }
  ],
  "ui": {
   "accent": "#e85d75"
  }
 },
 "code": "// Bitcrusher: rounds each sample to 2^(bits-1) levels and holds it for \"down\" samples.\nplugin({\n  create(host) {\n    const hold = [0, 0], left = [0, 0];\n    return {\n      process(input, output, p, frames) {\n        const lv = Math.pow(2, Math.max(1, Math.min(16, p.bits)) - 1);\n        const dn = Math.max(1, Math.round(p.down));\n        for (let c = 0; c < output.length; c++) {\n          const i = input[c], o = output[c];\n          let h = hold[c], m = left[c];\n          for (let n = 0; n < frames; n++) {\n            if (m <= 0) { h = Math.round(i[n] * lv) / lv; m = dn; }\n            m--; o[n] = h;\n          }\n          hold[c] = h; left[c] = m;\n        }\n      }\n    };\n  }\n});\n"
}