2019-07-11 21:11:29 +00:00
|
|
|
import { ToneAudioNodeOptions } from "../core/context/ToneAudioNode";
|
|
|
|
import { SignalOperator } from "./SignalOperator";
|
|
|
|
import { WaveShaper } from "./WaveShaper";
|
|
|
|
|
|
|
|
/**
|
2019-07-25 03:17:18 +00:00
|
|
|
* AudioToGain converts an input in AudioRange [-1,1] to NormalRange [0,1].
|
|
|
|
* See {@link GainToAudio}.
|
2019-09-16 14:15:23 +00:00
|
|
|
* @category Signal
|
2019-07-11 21:11:29 +00:00
|
|
|
*/
|
|
|
|
export class AudioToGain extends SignalOperator<ToneAudioNodeOptions> {
|
|
|
|
|
2019-09-04 23:18:44 +00:00
|
|
|
readonly name: string = "AudioToGain";
|
2019-07-11 21:11:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The node which converts the audio ranges
|
|
|
|
*/
|
|
|
|
private _norm = new WaveShaper({
|
|
|
|
context: this.context,
|
|
|
|
mapping: x => (x + 1) / 2,
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The AudioRange input [-1, 1]
|
|
|
|
*/
|
|
|
|
input = this._norm;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The GainRange output [0, 1]
|
|
|
|
*/
|
|
|
|
output = this._norm;
|
|
|
|
|
|
|
|
/**
|
2019-09-14 20:39:18 +00:00
|
|
|
* clean up
|
2019-07-11 21:11:29 +00:00
|
|
|
*/
|
|
|
|
dispose(): this {
|
|
|
|
super.dispose();
|
|
|
|
this._norm.dispose();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|