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
File diff suppressed because it is too large
Load diff
|
|
@ -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