mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-15 07:38:33 +00:00
use sample as an impulse response for the reverb
This commit is contained in:
parent
fd18508266
commit
755e24315e
File diff suppressed because it is too large
Load Diff
@ -7,22 +7,31 @@ if (typeof AudioContext !== 'undefined') {
|
||||
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) {
|
||||
const convolver = this.createConvolver();
|
||||
convolver.setDuration = (d, i) => {
|
||||
convolver.buffer = i !== undefined ? buffer : this.impulseResponse(d);
|
||||
convolver.duration = d;
|
||||
convolver.setDuration = (dur, imp) => {
|
||||
convolver.buffer = imp ? this.adjustLength(dur, imp) : this.impulseResponse(dur);
|
||||
return convolver;
|
||||
};
|
||||
convolver.setIR = (i) => {
|
||||
convolver.buffer = i;
|
||||
convolver.setIR = (dur, imp) => {
|
||||
convolver.buffer = imp ? this.adjustLength(dur, imp) : this.impulseResponse(dur);
|
||||
return convolver;
|
||||
};
|
||||
if (buffer !== undefined) {
|
||||
convolver.setIR(buffer);
|
||||
} else {
|
||||
convolver.setDuration(duration);
|
||||
}
|
||||
convolver.setDuration(duration, buffer);
|
||||
return convolver;
|
||||
};
|
||||
}
|
||||
|
||||
@ -122,11 +122,11 @@ function getReverb(orbit, duration = 2, ir) {
|
||||
reverbs[orbit] = reverb;
|
||||
}
|
||||
if (reverbs[orbit].duration !== duration) {
|
||||
reverbs[orbit] = reverbs[orbit].setDuration(duration);
|
||||
reverbs[orbit] = reverbs[orbit].setDuration(duration, ir);
|
||||
reverbs[orbit].duration = duration;
|
||||
}
|
||||
if (reverbs[orbit].ir !== ir) {
|
||||
reverbs[orbit] = reverbs[orbit].setIR(ir);
|
||||
reverbs[orbit] = reverbs[orbit].setIR(duration, ir);
|
||||
reverbs[orbit].ir = ir;
|
||||
}
|
||||
return reverbs[orbit];
|
||||
@ -368,9 +368,14 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
}
|
||||
// reverb
|
||||
let buffer;
|
||||
let url;
|
||||
if (ir !== undefined) {
|
||||
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);
|
||||
}
|
||||
let reverbSend;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user