-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #717 from vasilymilovidov/reverb
Add support for using samples as impulse response buffers for the reverb
- Loading branch information
Showing
5 changed files
with
97 additions
and
44 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,47 @@ | ||
import reverbGen from './reverbGen.mjs'; | ||
|
||
if (typeof AudioContext !== 'undefined') { | ||
AudioContext.prototype.createReverb = function (duration, fade, lp, dim) { | ||
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, fade, lp, dim, ir) { | ||
const convolver = this.createConvolver(); | ||
convolver.generate = (d = 2, fade = 0.1, lp = 15000, dim = 1000) => { | ||
reverbGen.generateReverb( | ||
{ | ||
audioContext: this, | ||
numChannels: 2, | ||
decayTime: d, | ||
fadeInTime: fade, | ||
lpFreqStart: lp, | ||
lpFreqEnd: dim, | ||
}, | ||
(buffer) => { | ||
convolver.buffer = buffer; | ||
}, | ||
); | ||
convolver.generate = (d = 2, fade = 0.1, lp = 15000, dim = 1000, ir) => { | ||
convolver.duration = d; | ||
convolver.fade = fade; | ||
convolver.lp = lp; | ||
convolver.dim = dim; | ||
convolver.ir = ir; | ||
if (ir) { | ||
convolver.buffer = this.adjustLength(d, ir); | ||
} else { | ||
reverbGen.generateReverb( | ||
{ | ||
audioContext: this, | ||
numChannels: 2, | ||
decayTime: d, | ||
fadeInTime: fade, | ||
lpFreqStart: lp, | ||
lpFreqEnd: dim, | ||
}, | ||
(buffer) => { | ||
convolver.buffer = buffer; | ||
}, | ||
); | ||
} | ||
}; | ||
convolver.generate(duration, fade, lp, dim); | ||
convolver.generate(duration, fade, lp, dim, ir); | ||
return convolver; | ||
}; | ||
} |
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
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
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