Tone.js/Tone/component/analysis/DCMeter.ts
Yotam Mann d9a7520eb6 feat: Analyser can handle multiple channels
Can pass in `channels` into constructor which runs a separate analysis on each channel and returns the results as a Float32Array[].
2019-12-15 16:42:50 -05:00

39 lines
998 B
TypeScript

import { optionsFromArguments } from "../../core/util/Defaults";
import { MeterBase, MeterBaseOptions } from "./MeterBase";
export type DCMeterOptions = MeterBaseOptions;
/**
* DCMeter gets the raw value of the input signal at the current time.
*
* @example
* import { DCMeter, UserMedia } from "tone";
* const meter = new DCMeter();
* const mic = new UserMedia();
* mic.open();
* // connect mic to the meter
* mic.connect(meter);
* // the current level of the mic
* const level = meter.getValue();
* @category Component
*/
export class DCMeter extends MeterBase<DCMeterOptions> {
readonly name: string = "DCMeter";
constructor(options?: Partial<DCMeterOptions>);
constructor() {
super(optionsFromArguments(DCMeter.getDefaults(), arguments));
this._analyser.type = "waveform";
this._analyser.size = 256;
}
/**
* Get the signal value of the incoming signal
*/
getValue(): number {
const value = this._analyser.getValue() as Float32Array;
return value[0];
}
}