Tone.js/Tone/signal/GainToAudio.ts

41 lines
801 B
TypeScript
Raw Normal View History

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