Last active
March 12, 2024 12:24
-
-
Save michaelbauchert/64070e1afe3c1b940daaae8e2d633953 to your computer and use it in GitHub Desktop.
Frequency Shifter for https://www.elementary.audio/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Inspired by https://larzeitlin.github.io/RMFS/ | |
//IIR Coefficients from http://yehar.com/blog/?p=368 | |
function hilbert(part, input) { | |
function allpassIIR(coefficient, input) { | |
return el.biquad( | |
coefficient ** 2, 0, -1, | |
0, -1 * coefficient ** 2, | |
input | |
); | |
} | |
switch(part) { | |
case "real": | |
return el.z(allpassIIR(0.9987488452737, allpassIIR(0.9882295226860, allpassIIR(0.9360654322959, allpassIIR(0.6923878, input))))); | |
case "imaginary": | |
return allpassIIR(0.9952884791278, allpassIIR(0.9722909545651, allpassIIR(0.8561710882420, allpassIIR(0.4021921162426, input)))); | |
} | |
} | |
function frequencyShift(frequency, input) { | |
let phasor = el.phasor(frequency); | |
let sine = el.sin(el.mul(2.0 * Math.PI, phasor)); | |
let cosine = el.cos(el.mul(2.0 * Math.PI, phasor)); | |
return el.sub( | |
el.mul(hilbert("real", input), sine), | |
el.mul(hilbert("imaginary", input), cosine) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment