|  |  | @@ -0,0 +1,81 @@ | 
		
	
		
			
			|  |  |  | import { Filter } from "./Filter"; | 
		
	
		
			
			|  |  |  | import { context, exposedNumber } from "../audio"; | 
		
	
		
			
			|  |  |  | import Reverb from "soundbank-reverb"; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | export class ReverbFilter extends Filter { | 
		
	
		
			
			|  |  |  | private reverb: any; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | @exposedNumber({ | 
		
	
		
			
			|  |  |  | name: "Reverb Time", | 
		
	
		
			
			|  |  |  | min: 0.1, | 
		
	
		
			
			|  |  |  | max: 5, | 
		
	
		
			
			|  |  |  | format: (value: number) => | 
		
	
		
			
			|  |  |  | Math.pow(2, value).toLocaleString(undefined, { | 
		
	
		
			
			|  |  |  | maximumFractionDigits: 1, | 
		
	
		
			
			|  |  |  | }) + "s", | 
		
	
		
			
			|  |  |  | map: (value: number) => Math.log(value) / Math.log(2), | 
		
	
		
			
			|  |  |  | unmap: (value: number) => Math.pow(2, value), | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | public time = 1; | 
		
	
		
			
			|  |  |  | private oldTime = -1; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | @exposedNumber({ | 
		
	
		
			
			|  |  |  | name: "Decay Rate", | 
		
	
		
			
			|  |  |  | min: 0.1, | 
		
	
		
			
			|  |  |  | max: 5, | 
		
	
		
			
			|  |  |  | format: (value: number) => | 
		
	
		
			
			|  |  |  | Math.pow(2, value).toLocaleString(undefined, { | 
		
	
		
			
			|  |  |  | maximumFractionDigits: 1, | 
		
	
		
			
			|  |  |  | }), | 
		
	
		
			
			|  |  |  | map: (value: number) => Math.log(value) / Math.log(2), | 
		
	
		
			
			|  |  |  | unmap: (value: number) => Math.pow(2, value), | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | public decay = 1; | 
		
	
		
			
			|  |  |  | private oldDecay = -1; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | @exposedNumber({ | 
		
	
		
			
			|  |  |  | name: "Dry Mix", | 
		
	
		
			
			|  |  |  | min: 0, | 
		
	
		
			
			|  |  |  | max: 1, | 
		
	
		
			
			|  |  |  | format: (value: number) => | 
		
	
		
			
			|  |  |  | (value * 100).toLocaleString(undefined, { | 
		
	
		
			
			|  |  |  | maximumFractionDigits: 0, | 
		
	
		
			
			|  |  |  | }) + "%", | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | public dry = 1; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | @exposedNumber({ | 
		
	
		
			
			|  |  |  | name: "Wet Mix", | 
		
	
		
			
			|  |  |  | min: 0, | 
		
	
		
			
			|  |  |  | max: 1, | 
		
	
		
			
			|  |  |  | format: (value: number) => | 
		
	
		
			
			|  |  |  | (value * 100).toLocaleString(undefined, { | 
		
	
		
			
			|  |  |  | maximumFractionDigits: 0, | 
		
	
		
			
			|  |  |  | }) + "%", | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | public wet = 0.5; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | constructor() { | 
		
	
		
			
			|  |  |  | super("Reverb Filter"); | 
		
	
		
			
			|  |  |  | this.reverb = Reverb(context); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | this.reverb.time = 1; | 
		
	
		
			
			|  |  |  | this.input.connect(this.reverb); | 
		
	
		
			
			|  |  |  | this.reverb.connect(this.output); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | public tick(dt: number): void { | 
		
	
		
			
			|  |  |  | super.tick(dt); | 
		
	
		
			
			|  |  |  | if (this.oldTime != this.time) { | 
		
	
		
			
			|  |  |  | this.reverb.time = this.time; | 
		
	
		
			
			|  |  |  | this.oldTime = this.time; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | if (this.oldDecay != this.decay) { | 
		
	
		
			
			|  |  |  | this.reverb.decay = this.decay; | 
		
	
		
			
			|  |  |  | this.oldDecay = this.decay; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | this.reverb.dry.setTargetAtTime(this.dry, context.currentTime, 0.3); | 
		
	
		
			
			|  |  |  | this.reverb.wet.setTargetAtTime(this.wet, context.currentTime, 0.3); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } |