A node for clipping signals to a range
Signals in web audio are not clipped to -1, 1 until the very end i.e. when the output from the audio context's destination is sent to the sound card. You might want to clip them before that happens, so this module is for you!
You can use it for things such as:
- distorting sounds (the demo)
- creating more complex sounds out of simpler sounds
Create an audio context.
var audioContext = ;
Require the code somehow:
var Clipper = ;
Then create instances by passing the context to the function:
var clipper = ;
And it's ready to be used!
// Just clip var oscillator = audioContext.createOscillator(); var gain = audioContext.createGain(); gain.gain.setValueAtTime(5, audioContext.currentTime); oscillator.connect(gain); gain.connect(clipper); clipper.connect(audioContext.destination);
// To clip out 25% of peak values set a different curve clipper.setCurve([ -0.5, -0.5, 0, 0.5, 0.5 ]);
npm install first to have all the dependencies (i.e. the oscilloscope component) installed.
index.html. Code is in
** YOU NEED SUPPORT FOR WEB COMPONENTS IN YOUR BROWSER BECAUSE WE'RE NOT SHIMMING ANYTHING IN **
Firefox: go to
dom.webcomponents.enabled and set it to true.
Chrome: maybe nothing to do?