node-web-audio-api 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/TODOS.md +134 -12
- package/index.mjs +17 -6
- package/js/AnalyserNode.js +259 -48
- package/js/AudioBuffer.js +243 -0
- package/js/AudioBufferSourceNode.js +259 -41
- package/js/AudioContext.js +294 -28
- package/js/AudioDestinationNode.js +42 -100
- package/js/AudioListener.js +219 -0
- package/js/AudioNode.js +323 -0
- package/js/AudioParam.js +252 -39
- package/js/AudioScheduledSourceNode.js +120 -0
- package/js/BaseAudioContext.js +434 -0
- package/js/BiquadFilterNode.js +218 -29
- package/js/ChannelMergerNode.js +93 -22
- package/js/ChannelSplitterNode.js +93 -22
- package/js/ConstantSourceNode.js +86 -26
- package/js/ConvolverNode.js +158 -29
- package/js/DelayNode.js +112 -21
- package/js/DynamicsCompressorNode.js +195 -27
- package/js/Events.js +84 -0
- package/js/GainNode.js +104 -21
- package/js/IIRFilterNode.js +136 -23
- package/js/MediaStreamAudioSourceNode.js +80 -24
- package/js/OfflineAudioContext.js +198 -35
- package/js/OscillatorNode.js +189 -32
- package/js/PannerNode.js +458 -56
- package/js/PeriodicWave.js +67 -3
- package/js/ScriptProcessorNode.js +179 -0
- package/js/StereoPannerNode.js +104 -21
- package/js/WaveShaperNode.js +144 -29
- package/js/lib/cast.js +19 -0
- package/js/lib/errors.js +10 -55
- package/js/lib/events.js +10 -0
- package/js/lib/symbols.js +20 -0
- package/js/lib/utils.js +12 -12
- package/js/monkey-patch.js +40 -31
- package/node-web-audio-api.darwin-arm64.node +0 -0
- package/node-web-audio-api.darwin-x64.node +0 -0
- package/node-web-audio-api.linux-arm-gnueabihf.node +0 -0
- package/node-web-audio-api.linux-arm64-gnu.node +0 -0
- package/node-web-audio-api.linux-x64-gnu.node +0 -0
- package/node-web-audio-api.win32-arm64-msvc.node +0 -0
- package/node-web-audio-api.win32-x64-msvc.node +0 -0
- package/package.json +7 -4
- package/run-wpt.md +27 -0
- package/run-wpt.sh +5 -0
- package/js/AudioNode.mixin.js +0 -132
- package/js/AudioScheduledSourceNode.mixin.js +0 -67
- package/js/BaseAudioContext.mixin.js +0 -154
- package/js/EventTarget.mixin.js +0 -60
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
// -------------------------------------------------------------------------- //
|
|
2
|
-
// -------------------------------------------------------------------------- //
|
|
3
|
-
// //
|
|
4
|
-
// //
|
|
5
|
-
// //
|
|
6
|
-
// ██╗ ██╗ █████╗ ██████╗ ███╗ ██╗██╗███╗ ██╗ ██████╗ //
|
|
7
|
-
// ██║ ██║██╔══██╗██╔══██╗████╗ ██║██║████╗ ██║██╔════╝ //
|
|
8
|
-
// ██║ █╗ ██║███████║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║ ███╗ //
|
|
9
|
-
// ██║███╗██║██╔══██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║ ██║ //
|
|
10
|
-
// ╚███╔███╔╝██║ ██║██║ ██║██║ ╚████║██║██║ ╚████║╚██████╔╝ //
|
|
11
|
-
// ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ //
|
|
12
|
-
// //
|
|
13
|
-
// //
|
|
14
|
-
// - This file has been generated --------------------------- //
|
|
15
|
-
// //
|
|
16
|
-
// //
|
|
17
|
-
// -------------------------------------------------------------------------- //
|
|
18
|
-
// -------------------------------------------------------------------------- //
|
|
19
|
-
|
|
20
|
-
const { AudioDestinationNode } = require('./AudioDestinationNode.js');
|
|
21
|
-
const { isFunction } = require('./lib/utils.js');
|
|
22
|
-
|
|
23
|
-
module.exports = (superclass, bindings) => {
|
|
24
|
-
const {
|
|
25
|
-
AnalyserNode,
|
|
26
|
-
AudioBufferSourceNode,
|
|
27
|
-
BiquadFilterNode,
|
|
28
|
-
ChannelMergerNode,
|
|
29
|
-
ChannelSplitterNode,
|
|
30
|
-
ConstantSourceNode,
|
|
31
|
-
ConvolverNode,
|
|
32
|
-
DelayNode,
|
|
33
|
-
DynamicsCompressorNode,
|
|
34
|
-
GainNode,
|
|
35
|
-
IIRFilterNode,
|
|
36
|
-
MediaStreamAudioSourceNode,
|
|
37
|
-
OscillatorNode,
|
|
38
|
-
PannerNode,
|
|
39
|
-
StereoPannerNode,
|
|
40
|
-
WaveShaperNode,
|
|
41
|
-
PeriodicWave,
|
|
42
|
-
} = bindings;
|
|
43
|
-
|
|
44
|
-
class BaseAudioContext extends superclass {
|
|
45
|
-
constructor(...args) {
|
|
46
|
-
super(...args);
|
|
47
|
-
|
|
48
|
-
this.destination = new AudioDestinationNode(this.destination);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// This is not exactly what the spec says, but if we reject the promise
|
|
52
|
-
// when decodeErrorCallback is present the program will crash in an
|
|
53
|
-
// unexpected manner
|
|
54
|
-
// cf. https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-decodeaudiodata
|
|
55
|
-
decodeAudioData(audioData, decodeSuccessCallback, decodeErrorCallback) {
|
|
56
|
-
if (!(audioData instanceof ArrayBuffer)) {
|
|
57
|
-
throw new TypeError('Failed to execute "decodeAudioData": parameter 1 is not of type "ArrayBuffer"');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const audioBuffer = super.decodeAudioData(audioData);
|
|
62
|
-
|
|
63
|
-
if (isFunction(decodeSuccessCallback)) {
|
|
64
|
-
decodeSuccessCallback(audioBuffer);
|
|
65
|
-
} else {
|
|
66
|
-
return Promise.resolve(audioBuffer);
|
|
67
|
-
}
|
|
68
|
-
} catch (err) {
|
|
69
|
-
if (isFunction(decodeErrorCallback)) {
|
|
70
|
-
decodeErrorCallback(err);
|
|
71
|
-
} else {
|
|
72
|
-
return Promise.reject(err);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
createPeriodicWave(real, imag) {
|
|
78
|
-
return new PeriodicWave(this, { real, imag });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// --------------------------------------------------------------------
|
|
82
|
-
// Factory Methods (use the patched AudioNodes)
|
|
83
|
-
// --------------------------------------------------------------------
|
|
84
|
-
createAnalyser() {
|
|
85
|
-
return new AnalyserNode(this);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
createBufferSource() {
|
|
89
|
-
return new AudioBufferSourceNode(this);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
createBiquadFilter() {
|
|
93
|
-
return new BiquadFilterNode(this);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
createChannelMerger(numberOfInputs) {
|
|
97
|
-
const options = { numberOfInputs };
|
|
98
|
-
return new ChannelMergerNode(this, options);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
createChannelSplitter(numberOfOutputs) {
|
|
102
|
-
const options = { numberOfOutputs };
|
|
103
|
-
return new ChannelSplitterNode(this, options);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
createConstantSource() {
|
|
107
|
-
return new ConstantSourceNode(this);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
createConvolver() {
|
|
111
|
-
return new ConvolverNode(this);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
createDelay(maxDelayTime) {
|
|
115
|
-
const options = { maxDelayTime };
|
|
116
|
-
return new DelayNode(this, options);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
createDynamicsCompressor() {
|
|
120
|
-
return new DynamicsCompressorNode(this);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
createGain() {
|
|
124
|
-
return new GainNode(this);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
createIIRFilter(feedforward, feedback) {
|
|
128
|
-
const options = { feedforward, feedback };
|
|
129
|
-
return new IIRFilterNode(this, options);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
createOscillator() {
|
|
134
|
-
return new OscillatorNode(this);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
createPanner() {
|
|
138
|
-
return new PannerNode(this);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
createStereoPanner() {
|
|
142
|
-
return new StereoPannerNode(this);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
createWaveShaper() {
|
|
146
|
-
return new WaveShaperNode(this);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return BaseAudioContext;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
|
package/js/EventTarget.mixin.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const { isFunction } = require('./lib/utils.js');
|
|
2
|
-
|
|
3
|
-
const kEventListeners = Symbol('node-web-audio-api:event-listeners');
|
|
4
|
-
const kDispatchEvent = Symbol.for('node-web-audio-api:napi-dispatch-event');
|
|
5
|
-
|
|
6
|
-
module.exports = (superclass, eventTypes = []) => class EventTarget extends superclass {
|
|
7
|
-
[kEventListeners] = new Map();
|
|
8
|
-
|
|
9
|
-
constructor(...args) {
|
|
10
|
-
super(...args);
|
|
11
|
-
|
|
12
|
-
eventTypes.forEach((eventType) => {
|
|
13
|
-
this[`on${eventType}`] = null;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// we need to bind because calling [kDispatchEvent] from rust loose `this`
|
|
17
|
-
this[kDispatchEvent] = this[kDispatchEvent].bind(this);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// instance might
|
|
21
|
-
addEventListener(eventType, callback) {
|
|
22
|
-
if (!this[kEventListeners].has(eventType)) {
|
|
23
|
-
this[kEventListeners].set(eventType, new Set());
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const callbacks = this[kEventListeners].get(eventType);
|
|
27
|
-
callbacks.add(callback);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
removeEventListener(eventType, callback) {
|
|
31
|
-
// this is valid event eventType, otherwaise just ignore
|
|
32
|
-
if (this[kEventListeners].has(eventType)) {
|
|
33
|
-
const callbacks = this[kEventListeners].get(eventType);
|
|
34
|
-
callbacks.delete(callback);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
dispatchEvent(event) {
|
|
39
|
-
if (isFunction(this[`on${event.type}`])) {
|
|
40
|
-
this[`on${event.type}`](event);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (this[kEventListeners].has(event.type)) {
|
|
44
|
-
const callbacks = this[kEventListeners].get(event.type);
|
|
45
|
-
callbacks.forEach(callback => callback(event));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// called from rust
|
|
50
|
-
[kDispatchEvent](err, eventType) {
|
|
51
|
-
const event = new Event(eventType);
|
|
52
|
-
// cannot override, this would need to derive EventTarget
|
|
53
|
-
// cf. https://www.nearform.com/blog/node-js-and-the-struggles-of-being-an-eventtarget/
|
|
54
|
-
// event.target = this;
|
|
55
|
-
// event.currentTarget = this;
|
|
56
|
-
// event.srcElement = this;
|
|
57
|
-
|
|
58
|
-
this.dispatchEvent(event);
|
|
59
|
-
}
|
|
60
|
-
};
|