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
/** | |
Main thread (e.g. index.js) | |
**/ | |
const audioCtx = new AudioContext() | |
// Loads module script via AudioWorklet. | |
audioCtx.audioWorklet.addModule('reverb-processor.js') | |
.then(() => getLiveAudio(audioCtx)) | |
.then((liveIn) => { | |
// After the resolution of module loading, an AudioWorkletNode can be constructed. |
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
const inputSignal = readSignalFromSomewhere() | |
const outputSignal = new Array(inputSignal.length) | |
const delayInSamples = 44100 | |
const delayBuffer = new Array(delayInSamples) | |
const decay = 0.5 | |
let pointer = 0 | |
inputSignal.forEach(sample => { | |
const previousSample = delayBuffer[pointer % delayInSamples] | |
delayBuffer[pointer] = sample + previousSample * decay |
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
const getImpulseBuffer = (audioCtx, impulseUrl) => { | |
return fetch(impulseUrl) | |
.then(response => response.arrayBuffer()) | |
.then(arrayBuffer => audioCtx.decodeAudioData(arrayBuffer)) | |
} | |
const getLiveAudio = (audioCtx) => { | |
return navigator.mediaDevices.getUserMedia({audio: true}) | |
.then(stream => audioCtx.createMediaStreamSource(stream)); | |
} |
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
//in this example we assume guitar sound and impulse response are loaded into arrays somehow | |
const samplingRate = 44100 | |
// 1 second of an input sound (e.g. guitar chord) | |
const X = new Array(samplingRate * 1) | |
// 2 seconds of an impulse response (e.g echos of a clap in a room) | |
const H = new Array(samplingRate * 2) | |
//output sound (how chord would sound in this room) | |
const Y = new Array(X.length + H.length) | |
X.forEach((x, i) => { |
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
// Allows to set a parameter value for multiple nodes (of same kind) at the same time | |
function mergeParams(params){ | |
const singleParam = params[0] | |
const parameter = {}; | |
const audioNodeMethods = Object.getOwnPropertyNames(AudioParam.prototype) | |
.filter(prop => typeof singleParam[prop] === 'function') | |
//allows things like parameter.setValueAtTime(x, ctx.currentTime) | |
audioNodeMethods.forEach(method => { | |
parameter[method] = (...argums) => { |
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
class Freeverb extends CompositeAudioNode { | |
get wetGain () { | |
return this._wet.gain; | |
} | |
get dryGain () { | |
return this._dry.gain; | |
} | |
get roomSize() { | |
return mergeParams(this._combFilters.map(comb => comb.resonance)) | |
} |
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
class LowpassCombFilter extends CompositeAudioNode { | |
get resonance () { | |
return this._gain.gain; | |
} | |
get dampening () { | |
return this._lowPass.frequency; | |
} | |
get delayTime () { | |
return this._delay.delayTime; | |
} |
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
// static Low Pass Feedback Comb Filter | |
const audioCtx = new AudioContext() | |
const input = getOsc(audioCtx) | |
const combFilter = getCombFilter(audioCtx) | |
const output = audioCtx.destination | |
input | |
.connect(combFilter) | |
.connect(output) |
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
# to generate your dhparam.pem file, run in the terminal | |
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
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
#!/bin/bash | |
# Install build dependencies | |
yum install -y gcc libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-devel | |
# Get GraphicsMagick source | |
wget ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/GraphicsMagick-1.3.9.tar.gz | |
tar zxvf GraphicsMagick-1.3.9.tar.gz | |
# Configure and compile |