1 | import { __decorate } from "tslib";
|
2 | import { FrequencyClass } from "../core/type/Frequency.js";
|
3 | import { deepMerge, optionsFromArguments } from "../core/util/Defaults.js";
|
4 | import { readOnly } from "../core/util/Interface.js";
|
5 | import { Monophonic } from "./Monophonic.js";
|
6 | import { Synth } from "./Synth.js";
|
7 | import { range, timeRange } from "../core/util/Decorator.js";
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export class MembraneSynth extends Synth {
|
22 | constructor() {
|
23 | const options = optionsFromArguments(MembraneSynth.getDefaults(), arguments);
|
24 | super(options);
|
25 | this.name = "MembraneSynth";
|
26 | |
27 |
|
28 |
|
29 | this.portamento = 0;
|
30 | this.pitchDecay = options.pitchDecay;
|
31 | this.octaves = options.octaves;
|
32 | readOnly(this, ["oscillator", "envelope"]);
|
33 | }
|
34 | static getDefaults() {
|
35 | return deepMerge(Monophonic.getDefaults(), Synth.getDefaults(), {
|
36 | envelope: {
|
37 | attack: 0.001,
|
38 | attackCurve: "exponential",
|
39 | decay: 0.4,
|
40 | release: 1.4,
|
41 | sustain: 0.01,
|
42 | },
|
43 | octaves: 10,
|
44 | oscillator: {
|
45 | type: "sine",
|
46 | },
|
47 | pitchDecay: 0.05,
|
48 | });
|
49 | }
|
50 | setNote(note, time) {
|
51 | const seconds = this.toSeconds(time);
|
52 | const hertz = this.toFrequency(note instanceof FrequencyClass ? note.toFrequency() : note);
|
53 | const maxNote = hertz * this.octaves;
|
54 | this.oscillator.frequency.setValueAtTime(maxNote, seconds);
|
55 | this.oscillator.frequency.exponentialRampToValueAtTime(hertz, seconds + this.toSeconds(this.pitchDecay));
|
56 | return this;
|
57 | }
|
58 | dispose() {
|
59 | super.dispose();
|
60 | return this;
|
61 | }
|
62 | }
|
63 | __decorate([
|
64 | range(0)
|
65 | ], MembraneSynth.prototype, "octaves", void 0);
|
66 | __decorate([
|
67 | timeRange(0)
|
68 | ], MembraneSynth.prototype, "pitchDecay", void 0);
|
69 |
|
\ | No newline at end of file |