mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-26 19:43:12 +00:00
aaf880c925
* WIP moving tests to web-test-runner * updating thresholds * Adding file extensions * Testing integrations * linting * fixing dep * moving back to root dir * prettier all of the files * updating eslint rules to use with prettier * remove import package * moving tsignore around * removing unneeded ignores * all tests run on puppeteer, no need for testing guards * linting * import type syntax * cleaning up * Update package.json
52 lines
1,015 B
TypeScript
52 lines
1,015 B
TypeScript
import { ToneAudioNodeOptions } from "../core/context/ToneAudioNode.js";
|
|
import { SignalOperator } from "./SignalOperator.js";
|
|
import { WaveShaper } from "./WaveShaper.js";
|
|
|
|
/**
|
|
* Return the absolute value of an incoming signal.
|
|
*
|
|
* @example
|
|
* return Tone.Offline(() => {
|
|
* const abs = new Tone.Abs().toDestination();
|
|
* const signal = new Tone.Signal(1);
|
|
* signal.rampTo(-1, 0.5);
|
|
* signal.connect(abs);
|
|
* }, 0.5, 1);
|
|
* @category Signal
|
|
*/
|
|
export class Abs extends SignalOperator<ToneAudioNodeOptions> {
|
|
readonly name: string = "Abs";
|
|
|
|
/**
|
|
* The node which converts the audio ranges
|
|
*/
|
|
private _abs = new WaveShaper({
|
|
context: this.context,
|
|
mapping: (val) => {
|
|
if (Math.abs(val) < 0.001) {
|
|
return 0;
|
|
} else {
|
|
return Math.abs(val);
|
|
}
|
|
},
|
|
});
|
|
|
|
/**
|
|
* The AudioRange input [-1, 1]
|
|
*/
|
|
input = this._abs;
|
|
|
|
/**
|
|
* The output range [0, 1]
|
|
*/
|
|
output = this._abs;
|
|
|
|
/**
|
|
* clean up
|
|
*/
|
|
dispose(): this {
|
|
super.dispose();
|
|
this._abs.dispose();
|
|
return this;
|
|
}
|
|
}
|