Tone.js/Tone/signal/AudioToGain.ts

43 lines
822 B
TypeScript
Raw Normal View History

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-07-11 21:11:29 +00:00
*
2019-07-25 03:17:18 +00:00
* @example
* var a2g = new AudioToGain();
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;
}
}