-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeesser.js
More file actions
40 lines (36 loc) · 1.41 KB
/
deesser.js
File metadata and controls
40 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { envelope } from './envelope.js'
import { bandpass, biquad, biquadState } from './biquad.js'
import { compressorGain } from './compressor.js'
import { writer, concat, db2lin, lin2db } from './util.js'
// De-esser: bandpass sidechain (sibilance band) drives a compressor whose gain
// reduction is applied either to the full band (classic) or only to the HF shelf
// (split mode — requires external high-shelf if user wants stricter separation).
export default function deesser(data, opts) {
if (!(data instanceof Float32Array)) return writer(deesserStream(data))
let s = deesserStream(opts)
return concat(s.write(data), s.flush())
}
export function deesserStream(opts = {}) {
let sr = opts.sampleRate || 44100
let freq = opts.freq ?? 6500
let q = opts.q ?? 2
let threshold = opts.threshold ?? -20
let ratio = opts.ratio ?? 4
let knee = opts.knee ?? 6
let bp = bandpass(sr, freq, q)
let state = biquadState()
let env = envelope({ sampleRate: sr, attack: opts.attack ?? 1, release: opts.release ?? 40, detector: opts.detector })
return {
write(chunk) {
let out = new Float32Array(chunk.length)
for (let i = 0; i < chunk.length; i++) {
let x = chunk[i]
let side = biquad(bp, state, x)
let rDb = compressorGain(lin2db(env(side)), threshold, ratio, knee)
out[i] = x * db2lin(rDb)
}
return out
},
flush() { return new Float32Array(0) }
}
}