1 | import { connect } from "../core/context/ToneAudioNode.js";
|
2 | import { Param } from "../core/context/Param.js";
|
3 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
4 | import { OneShotSource, } from "../source/OneShotSource.js";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export class ToneConstantSource extends OneShotSource {
|
11 | constructor() {
|
12 | const options = optionsFromArguments(ToneConstantSource.getDefaults(), arguments, ["offset"]);
|
13 | super(options);
|
14 | this.name = "ToneConstantSource";
|
15 | |
16 |
|
17 |
|
18 | this._source = this.context.createConstantSource();
|
19 | connect(this._source, this._gainNode);
|
20 | this.offset = new Param({
|
21 | context: this.context,
|
22 | convert: options.convert,
|
23 | param: this._source.offset,
|
24 | units: options.units,
|
25 | value: options.offset,
|
26 | minValue: options.minValue,
|
27 | maxValue: options.maxValue,
|
28 | });
|
29 | }
|
30 | static getDefaults() {
|
31 | return Object.assign(OneShotSource.getDefaults(), {
|
32 | convert: true,
|
33 | offset: 1,
|
34 | units: "number",
|
35 | });
|
36 | }
|
37 | |
38 |
|
39 |
|
40 |
|
41 | start(time) {
|
42 | const computedTime = this.toSeconds(time);
|
43 | this.log("start", computedTime);
|
44 | this._startGain(computedTime);
|
45 | this._source.start(computedTime);
|
46 | return this;
|
47 | }
|
48 | _stopSource(time) {
|
49 | this._source.stop(time);
|
50 | }
|
51 | dispose() {
|
52 | super.dispose();
|
53 | if (this.state === "started") {
|
54 | this.stop();
|
55 | }
|
56 | this._source.disconnect();
|
57 | this.offset.dispose();
|
58 | return this;
|
59 | }
|
60 | }
|
61 |
|
\ | No newline at end of file |