Skip to content

Commit

Permalink
Add limiter to TechnoSnare
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukau committed Aug 25, 2023
1 parent d042a02 commit 4b223d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 18 additions & 0 deletions TechnoSnare/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function randomize() {
if (key === "dcHighpassHz") continue;
if (key === "toneSlope") continue;
if (key === "adaptiveFilterMix") continue;
if (key === "limiterEnable") continue;
if (key === "bodyHighpassHz") continue;
if (key === "noiseCombRandom") continue;
if (Array.isArray(param[key])) {
Expand Down Expand Up @@ -47,6 +48,7 @@ function randomize() {
continue;
}
if (key === "adaptiveFilterMix") continue;
if (key === "limiterEnable") continue;
if (key === "bodyAttackSeconds") {
param[key].dsp = util.exponentialMap(Math.random(), 1e-5, 1e-3);
continue;
Expand Down Expand Up @@ -124,6 +126,7 @@ function randomize() {
continue;
}
if (key === "adaptiveFilterMix") continue;
if (key === "limiterEnable") continue;
if (key === "bodyAttackSeconds") {
const value = util.exponentialMap(Math.random(), 1e-5, 1e-3);
param[key].dsp = value;
Expand Down Expand Up @@ -305,6 +308,9 @@ const scales = {
seed: new parameter.IntScale(0, 2 ** 32),
mix: new parameter.LinearScale(0, 1),

limiterThreshold: new parameter.DecibelScale(-60, 20, false),
limiterAttackSeconds: new parameter.DecibelScale(-100, -40, false),

attackSeconds: new parameter.DecibelScale(-80, -20, true),
envelopeCurve: new parameter.DecibelScale(-20, 60, true),
pitchDecaySeconds: new parameter.DecibelScale(-40, 40, true),
Expand Down Expand Up @@ -336,6 +342,10 @@ const param = {
seed: new parameter.Parameter(0, scales.seed),
bodyNoiseMix: new parameter.Parameter(0.5, scales.mix),

limiterEnable: new parameter.Parameter(0, scales.boolean),
limiterThreshold: new parameter.Parameter(1, scales.limiterThreshold, false),
limiterAttackSeconds: new parameter.Parameter(0.001, scales.limiterAttackSeconds, true),

bodyAttackSeconds: new parameter.Parameter(600 / 48000, scales.attackSeconds, true),
bodyEnvelopeCurve: new parameter.Parameter(100, scales.envelopeCurve, true),
bodyPitchDecaySeconds:
Expand Down Expand Up @@ -415,6 +425,7 @@ const togglebuttonQuickSave = new widget.ToggleButton(

const detailRender = widget.details(divLeft, "Render");
const detailMisc = widget.details(divLeft, "Misc.");
const detailLimiter = widget.details(divRightA, "Limiter");
const detailBody = widget.details(divRightA, "Body");
const detailNoise = widget.details(divRightB, "Noise");
const detailHightone = widget.details(divRightB, "Hightone");
Expand All @@ -440,6 +451,13 @@ const ui = {
adaptiveFilterMix: new widget.NumberInput(
detailMisc, "Adaptive Filter Mix", param.adaptiveFilterMix, render),

limiterEnable: new widget.ToggleButtonLine(
detailLimiter, ["Off", "On"], param.limiterEnable, render),
limiterThreshold: new widget.NumberInput(
detailLimiter, "Threshold [dB]", param.limiterThreshold, render),
limiterAttackSeconds: new widget.NumberInput(
detailLimiter, "Attack [s]", param.limiterAttackSeconds, render),

bodyAttackSeconds:
new widget.NumberInput(detailBody, "Attack [s]", param.bodyAttackSeconds, render),
bodyEnvelopeCurve:
Expand Down
9 changes: 6 additions & 3 deletions TechnoSnare/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import {AdaptiveFilterLMS} from "../common/dsp/adaptivefilter.js"
import {SingleSideBandAmplitudeModulator} from "../common/dsp/analyticsignalfilter.js"
import * as delay from "../common/dsp/delay.js";
import {ExpPolyEnvelope} from "../common/dsp/envelope.js";
import {Limiter} from "../common/dsp/limiter.js"
import {downSampleIIR, SosFilter} from "../common/dsp/multirate.js";
import {AP1, HP1, LP1} from "../common/dsp/onepole.js"
import {SlopeFilter} from "../common/dsp/slopefilter.js";
import {normalizedCutoffToOnePoleKp} from "../common/dsp/smoother.js";
import {sosMatchedBandpass} from "../common/dsp/sos.js"
import {SVF} from "../common/dsp/svf.js";
import {
clamp,
dbToAmp,
exponentialMap,
lerp,
normalDistributionMap,
Expand Down Expand Up @@ -186,7 +185,9 @@ function process(upRate, pv, dsp) {
if (pv.dcHighpassHz > 0) sig = dsp.dcHighpass.hp(sig);
if (pv.toneSlope < 1) sig = dsp.slopeFilter.process(sig);
const error = dsp.adaptiveFilter.process(sig, sig);
return lerp(sig - error, error, pv.adaptiveFilterMix);
sig = lerp(sig - error, error, pv.adaptiveFilterMix);
if (pv.limiterEnable === 1) sig = dsp.limiter.process(sig);
return sig;
}

onmessage = async (event) => {
Expand Down Expand Up @@ -247,6 +248,8 @@ onmessage = async (event) => {
dsp.slopeFilter = new SlopeFilter(Math.floor(Math.log2(24000 / 1000)));
dsp.slopeFilter.setCutoff(upRate, 1000, pv.toneSlope, true);
dsp.adaptiveFilter = new AdaptiveFilterLMS(256, 0.1);
dsp.limiter = new Limiter(
Math.floor(upRate * pv.limiterAttackSeconds), 0, 0, pv.limiterThreshold);

// Process.
let sound = new Array(Math.floor(upRate * pv.renderDuration)).fill(0);
Expand Down

0 comments on commit 4b223d7

Please sign in to comment.