-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathindex.ts
More file actions
98 lines (83 loc) · 2.15 KB
/
index.ts
File metadata and controls
98 lines (83 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { $ } from '../../../../../../Class/$'
import { Functional } from '../../../../../../Class/Functional'
import { Done } from '../../../../../../Class/Functional/Done'
import { System } from '../../../../../../system'
import { AC } from '../../../../../../types/interface/AC'
import { AN } from '../../../../../../types/interface/AN'
import { ON } from '../../../../../../types/interface/ON'
import { V } from '../../../../../../types/interface/V'
import { wrapAudioNode } from '../../../../../../wrap/AudioNode'
import { wrapAudioParam } from '../../../../../../wrap/AudioParam'
import { ID_OSCILLATOR_NODE } from '../../../../../_ids'
export type I = {
node: (AN | AC) & $
opt: OscillatorOptions
}
export type O = {
node: ON & AN
frequency: V<number>
detune: V<number>
}
export default class OscillatorNode_ extends Functional<I, O> {
private _node: OscillatorNode
constructor(system: System) {
super(
{
i: ['node', 'opt'],
o: ['node', 'frequency', 'detune'],
},
{
input: {
node: {
ref: true,
},
},
output: {
node: {
ref: true,
},
frequency: {
ref: true,
},
detune: {
ref: true,
},
},
},
system,
ID_OSCILLATOR_NODE
)
}
f({ node: sourceNode, opt }: I, done: Done<O>) {
let _node: OscillatorNode
const {
api: {
window: { OscillatorNode },
},
} = this.__system
if (sourceNode.__.includes('AC')) {
_node = (sourceNode as AC).createOscillator(opt)
} else {
sourceNode = sourceNode as AN & $
const context = sourceNode.getContext()
// @ts-ignore
_node = new OscillatorNode(context, opt)
}
_node.start()
this._node = _node
const node = wrapAudioNode(_node, this.__system)
const frequency = wrapAudioParam(_node.frequency, this.__system)
const detune = wrapAudioParam(_node.detune, this.__system)
done({
node,
frequency,
detune,
})
}
d() {
if (this._node) {
this._node.stop()
this._node = undefined
}
}
}