use sample as an impulse response for the reverb
This commit is contained in:
parent
fd18508266
commit
755e24315e
3 changed files with 1221 additions and 1205 deletions
|
|
@ -980,6 +980,7 @@ const generic_params = [
|
||||||
* s("bd sd").room(.8).roomsize("<0 1 2 4 8>")
|
* s("bd sd").room(.8).roomsize("<0 1 2 4 8>")
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: find out why :
|
// TODO: find out why :
|
||||||
// s("bd sd").room(.8).roomsize("<0 .2 .4 .6 .8 [1,0]>").osc()
|
// s("bd sd").room(.8).roomsize("<0 .2 .4 .6 .8 [1,0]>").osc()
|
||||||
// .. does not work. Is it because room is only one effect?
|
// .. does not work. Is it because room is only one effect?
|
||||||
|
|
@ -995,10 +996,11 @@ const generic_params = [
|
||||||
* @name iresponse
|
* @name iresponse
|
||||||
* @param {string | Pattern} Sets the impulse response
|
* @param {string | Pattern} Sets the impulse response
|
||||||
* @example
|
* @example
|
||||||
* s("bd sd").room(.8).ir("<ir0 ir1>")
|
* s("bd sd").room(.8).ir("<shaker_large:0 shaker_large:2>")
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
[['ir', 'i'], 'iresponse'],
|
[['ir', 'i'], 'iresponse'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wave shaping distortion. CAUTION: it might get loud
|
* Wave shaping distortion. CAUTION: it might get loud
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -7,22 +7,31 @@ if (typeof AudioContext !== 'undefined') {
|
||||||
return impulse;
|
return impulse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AudioContext.prototype.adjustLength = function (duration, buffer) {
|
||||||
|
const newLength = buffer.sampleRate * duration;
|
||||||
|
const newBuffer = this.createBuffer(buffer.numberOfChannels, buffer.length, buffer.sampleRate);
|
||||||
|
for (let channel = 0; channel < buffer.numberOfChannels; channel++) {
|
||||||
|
let oldData = buffer.getChannelData(channel);
|
||||||
|
let newData = newBuffer.getChannelData(channel);
|
||||||
|
|
||||||
|
for (let i = 0; i < newLength; i++) {
|
||||||
|
newData[i] = oldData[i] || 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
AudioContext.prototype.createReverb = function (duration, buffer) {
|
AudioContext.prototype.createReverb = function (duration, buffer) {
|
||||||
const convolver = this.createConvolver();
|
const convolver = this.createConvolver();
|
||||||
convolver.setDuration = (d, i) => {
|
convolver.setDuration = (dur, imp) => {
|
||||||
convolver.buffer = i !== undefined ? buffer : this.impulseResponse(d);
|
convolver.buffer = imp ? this.adjustLength(dur, imp) : this.impulseResponse(dur);
|
||||||
convolver.duration = d;
|
|
||||||
return convolver;
|
return convolver;
|
||||||
};
|
};
|
||||||
convolver.setIR = (i) => {
|
convolver.setIR = (dur, imp) => {
|
||||||
convolver.buffer = i;
|
convolver.buffer = imp ? this.adjustLength(dur, imp) : this.impulseResponse(dur);
|
||||||
return convolver;
|
return convolver;
|
||||||
};
|
};
|
||||||
if (buffer !== undefined) {
|
convolver.setDuration(duration, buffer);
|
||||||
convolver.setIR(buffer);
|
|
||||||
} else {
|
|
||||||
convolver.setDuration(duration);
|
|
||||||
}
|
|
||||||
return convolver;
|
return convolver;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,11 +122,11 @@ function getReverb(orbit, duration = 2, ir) {
|
||||||
reverbs[orbit] = reverb;
|
reverbs[orbit] = reverb;
|
||||||
}
|
}
|
||||||
if (reverbs[orbit].duration !== duration) {
|
if (reverbs[orbit].duration !== duration) {
|
||||||
reverbs[orbit] = reverbs[orbit].setDuration(duration);
|
reverbs[orbit] = reverbs[orbit].setDuration(duration, ir);
|
||||||
reverbs[orbit].duration = duration;
|
reverbs[orbit].duration = duration;
|
||||||
}
|
}
|
||||||
if (reverbs[orbit].ir !== ir) {
|
if (reverbs[orbit].ir !== ir) {
|
||||||
reverbs[orbit] = reverbs[orbit].setIR(ir);
|
reverbs[orbit] = reverbs[orbit].setIR(duration, ir);
|
||||||
reverbs[orbit].ir = ir;
|
reverbs[orbit].ir = ir;
|
||||||
}
|
}
|
||||||
return reverbs[orbit];
|
return reverbs[orbit];
|
||||||
|
|
@ -368,9 +368,14 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||||
}
|
}
|
||||||
// reverb
|
// reverb
|
||||||
let buffer;
|
let buffer;
|
||||||
|
let url;
|
||||||
if (ir !== undefined) {
|
if (ir !== undefined) {
|
||||||
let sample = getSound(ir);
|
let sample = getSound(ir);
|
||||||
let url = sample.data.samples[i % sample.data.samples.length];
|
if (Array.isArray(sample)) {
|
||||||
|
url = sample.data.samples[i % sample.data.samples.length];
|
||||||
|
} else if (typeof sample === 'object') {
|
||||||
|
url = Object.values(sample.data.samples)[i & Object.values(sample.data.samples).length];
|
||||||
|
}
|
||||||
buffer = await loadBuffer(url, ac, ir, 0);
|
buffer = await loadBuffer(url, ac, ir, 0);
|
||||||
}
|
}
|
||||||
let reverbSend;
|
let reverbSend;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue