UNPKG

tone

Version:

A Web Audio framework for making interactive music in the browser.

61 lines 1.93 kB
import { connect } from "../core/context/ToneAudioNode.js"; import { Param } from "../core/context/Param.js"; import { optionsFromArguments } from "../core/util/Defaults.js"; import { OneShotSource, } from "../source/OneShotSource.js"; /** * Wrapper around the native fire-and-forget ConstantSource. * Adds the ability to reschedule the stop method. * @category Signal */ export class ToneConstantSource extends OneShotSource { constructor() { const options = optionsFromArguments(ToneConstantSource.getDefaults(), arguments, ["offset"]); super(options); this.name = "ToneConstantSource"; /** * The signal generator */ this._source = this.context.createConstantSource(); connect(this._source, this._gainNode); this.offset = new Param({ context: this.context, convert: options.convert, param: this._source.offset, units: options.units, value: options.offset, minValue: options.minValue, maxValue: options.maxValue, }); } static getDefaults() { return Object.assign(OneShotSource.getDefaults(), { convert: true, offset: 1, units: "number", }); } /** * Start the source node at the given time * @param time When to start the source */ start(time) { const computedTime = this.toSeconds(time); this.log("start", computedTime); this._startGain(computedTime); this._source.start(computedTime); return this; } _stopSource(time) { this._source.stop(time); } dispose() { super.dispose(); if (this.state === "started") { this.stop(); } this._source.disconnect(); this.offset.dispose(); return this; } } //# sourceMappingURL=ToneConstantSource.js.map