node-web-audio-api 0.18.0 → 0.19.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 +7 -0
- package/TODOS.md +140 -12
- package/index.mjs +10 -5
- package/js/AnalyserNode.js +262 -48
- package/js/AudioBuffer.js +244 -0
- package/js/AudioBufferSourceNode.js +265 -41
- package/js/AudioContext.js +271 -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 +105 -0
- package/js/BaseAudioContext.js +419 -0
- package/js/BiquadFilterNode.js +221 -29
- package/js/ChannelMergerNode.js +96 -22
- package/js/ChannelSplitterNode.js +96 -22
- package/js/ConstantSourceNode.js +92 -26
- package/js/ConvolverNode.js +161 -29
- package/js/DelayNode.js +115 -21
- package/js/DynamicsCompressorNode.js +198 -27
- package/js/GainNode.js +107 -21
- package/js/IIRFilterNode.js +139 -23
- package/js/MediaStreamAudioSourceNode.js +83 -24
- package/js/OfflineAudioContext.js +182 -34
- package/js/OscillatorNode.js +195 -32
- package/js/PannerNode.js +461 -56
- package/js/PeriodicWave.js +67 -3
- package/js/StereoPannerNode.js +107 -21
- package/js/WaveShaperNode.js +147 -29
- package/js/lib/cast.js +19 -0
- package/js/lib/errors.js +10 -55
- package/js/lib/events.js +20 -0
- package/js/lib/symbols.js +5 -0
- package/js/lib/utils.js +12 -12
- package/js/monkey-patch.js +32 -30
- 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
package/js/monkey-patch.js
CHANGED
|
@@ -18,48 +18,53 @@
|
|
|
18
18
|
// -------------------------------------------------------------------------- //
|
|
19
19
|
|
|
20
20
|
module.exports = function monkeyPatch(nativeBinding) {
|
|
21
|
+
let jsExport = {};
|
|
21
22
|
// --------------------------------------------------------------------------
|
|
22
23
|
// Monkey Patch Web Audio API
|
|
23
24
|
// --------------------------------------------------------------------------
|
|
25
|
+
jsExport.BaseAudioContext = require('./BaseAudioContext.js')(jsExport, nativeBinding);
|
|
26
|
+
jsExport.AudioContext = require('./AudioContext.js')(jsExport, nativeBinding);
|
|
27
|
+
jsExport.OfflineAudioContext = require('./OfflineAudioContext.js')(jsExport, nativeBinding);
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
jsExport.AnalyserNode = require('./AnalyserNode.js')(jsExport, nativeBinding);
|
|
30
|
+
jsExport.AudioBufferSourceNode = require('./AudioBufferSourceNode.js')(jsExport, nativeBinding);
|
|
31
|
+
jsExport.BiquadFilterNode = require('./BiquadFilterNode.js')(jsExport, nativeBinding);
|
|
32
|
+
jsExport.ChannelMergerNode = require('./ChannelMergerNode.js')(jsExport, nativeBinding);
|
|
33
|
+
jsExport.ChannelSplitterNode = require('./ChannelSplitterNode.js')(jsExport, nativeBinding);
|
|
34
|
+
jsExport.ConstantSourceNode = require('./ConstantSourceNode.js')(jsExport, nativeBinding);
|
|
35
|
+
jsExport.ConvolverNode = require('./ConvolverNode.js')(jsExport, nativeBinding);
|
|
36
|
+
jsExport.DelayNode = require('./DelayNode.js')(jsExport, nativeBinding);
|
|
37
|
+
jsExport.DynamicsCompressorNode = require('./DynamicsCompressorNode.js')(jsExport, nativeBinding);
|
|
38
|
+
jsExport.GainNode = require('./GainNode.js')(jsExport, nativeBinding);
|
|
39
|
+
jsExport.IIRFilterNode = require('./IIRFilterNode.js')(jsExport, nativeBinding);
|
|
40
|
+
jsExport.MediaStreamAudioSourceNode = require('./MediaStreamAudioSourceNode.js')(jsExport, nativeBinding);
|
|
41
|
+
jsExport.OscillatorNode = require('./OscillatorNode.js')(jsExport, nativeBinding);
|
|
42
|
+
jsExport.PannerNode = require('./PannerNode.js')(jsExport, nativeBinding);
|
|
43
|
+
jsExport.StereoPannerNode = require('./StereoPannerNode.js')(jsExport, nativeBinding);
|
|
44
|
+
jsExport.WaveShaperNode = require('./WaveShaperNode.js')(jsExport, nativeBinding);
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
jsExport.AudioNode = require('./AudioNode.js');
|
|
47
|
+
jsExport.AudioScheduledSourceNode = require('./AudioScheduledSourceNode.js');
|
|
48
|
+
jsExport.AudioParam = require('./AudioParam.js');
|
|
49
|
+
jsExport.AudioDestinationNode = require('./AudioDestinationNode.js');
|
|
50
|
+
jsExport.AudioListener = require('./AudioListener.js');
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// find a way to make the constructor private
|
|
49
|
-
nativeBinding.AudioParam = require('./AudioParam.js').AudioParam;
|
|
50
|
-
nativeBinding.AudioDestinationNode = require('./AudioDestinationNode.js').AudioDestinationNode;
|
|
52
|
+
jsExport.PeriodicWave = require('./PeriodicWave.js')(jsExport, nativeBinding);
|
|
53
|
+
jsExport.AudioBuffer = require('./AudioBuffer.js')(jsExport, nativeBinding);
|
|
51
54
|
|
|
52
55
|
// --------------------------------------------------------------------------
|
|
53
56
|
// Promisify MediaDevices API
|
|
54
57
|
// --------------------------------------------------------------------------
|
|
58
|
+
jsExport.mediaDevices = {};
|
|
59
|
+
|
|
55
60
|
const enumerateDevicesSync = nativeBinding.mediaDevices.enumerateDevices;
|
|
56
|
-
|
|
61
|
+
jsExport.mediaDevices.enumerateDevices = async function enumerateDevices() {
|
|
57
62
|
const list = enumerateDevicesSync();
|
|
58
63
|
return Promise.resolve(list);
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
const getUserMediaSync = nativeBinding.mediaDevices.getUserMedia;
|
|
62
|
-
|
|
67
|
+
jsExport.mediaDevices.getUserMedia = async function getUserMedia(options) {
|
|
63
68
|
if (options === undefined) {
|
|
64
69
|
throw new TypeError('Failed to execute "getUserMedia" on "MediaDevices": audio must be requested');
|
|
65
70
|
}
|
|
@@ -68,8 +73,5 @@ module.exports = function monkeyPatch(nativeBinding) {
|
|
|
68
73
|
return Promise.resolve(stream);
|
|
69
74
|
};
|
|
70
75
|
|
|
71
|
-
return
|
|
76
|
+
return jsExport;
|
|
72
77
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-web-audio-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"author": "Benjamin Matuszewski",
|
|
5
5
|
"description": "Node.js bindings for web-audio-api-rs using napi-rs",
|
|
6
6
|
"exports": {
|
|
@@ -44,13 +44,14 @@
|
|
|
44
44
|
"lint": "npx eslint index.cjs index.mjs && npx eslint js/*.js && npx eslint examples/*.mjs",
|
|
45
45
|
"preversion": "yarn install && npm run generate",
|
|
46
46
|
"postversion": "cargo bump $npm_package_version && git commit -am \"v$npm_package_version\" && node .scripts/check-changelog.mjs",
|
|
47
|
-
"test": "mocha",
|
|
47
|
+
"test": "mocha tests",
|
|
48
48
|
"wpt": "npm run build && node ./.scripts/wpt-harness.mjs",
|
|
49
49
|
"wpt:only": "node ./.scripts/wpt-harness.mjs"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@ircam/eslint-config": "^1.3.0",
|
|
53
53
|
"@ircam/sc-gettime": "^1.0.0",
|
|
54
|
+
"@ircam/sc-utils": "^1.3.3",
|
|
54
55
|
"@sindresorhus/slugify": "^2.1.1",
|
|
55
56
|
"camelcase": "^7.0.1",
|
|
56
57
|
"chai": "^4.3.7",
|
|
@@ -58,7 +59,8 @@
|
|
|
58
59
|
"cli-table": "^0.3.11",
|
|
59
60
|
"commander": "^11.1.0",
|
|
60
61
|
"dotenv": "^16.0.3",
|
|
61
|
-
"eslint": "^8.
|
|
62
|
+
"eslint": "^8.57.0",
|
|
63
|
+
"js-beautify": "^1.15.1",
|
|
62
64
|
"mocha": "^10.2.0",
|
|
63
65
|
"node-ssh": "^13.0.0",
|
|
64
66
|
"octokit": "^2.0.11",
|
|
@@ -70,6 +72,7 @@
|
|
|
70
72
|
},
|
|
71
73
|
"dependencies": {
|
|
72
74
|
"@napi-rs/cli": "^2.14.3",
|
|
73
|
-
"@node-rs/helper": "^1.3.3"
|
|
75
|
+
"@node-rs/helper": "^1.3.3",
|
|
76
|
+
"webidl-conversions": "^7.0.0"
|
|
74
77
|
}
|
|
75
78
|
}
|
package/run-wpt.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
create file run-wpt.sh and chmod +x run-wpt.sh:
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
#!/bin/bash
|
|
5
|
+
echo $1
|
|
6
|
+
echo ~~~~~~~~~~~~~~~~~
|
|
7
|
+
node ./.scripts/wpt-harness.mjs --filter "$1" 2>&1 | grep -A 3 RESULTS
|
|
8
|
+
echo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
dissect the full suite per directory:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
ls wpt/webaudio/the-audio-api | xargs -I {} ./run-wpt.sh {}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
check the specific file results in a dir:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
ls wpt/webaudio/the-audio-api/the-oscillatornode-interface | xargs -I {} ./run-wpt.sh {}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
ls wpt/webaudio/the-audio-api/the-audiocontext-interface | xargs -I {} ./run-wpt.sh {}
|
|
24
|
+
|
|
25
|
+
processing-model
|
|
26
|
+
|
|
27
|
+
ls wpt/webaudio/the-audio-api/processing-model | xargs -I {} ./run-wpt.sh {}
|
package/run-wpt.sh
ADDED
package/js/AudioNode.mixin.js
DELETED
|
@@ -1,132 +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 { throwSanitizedError } = require('./lib/errors.js');
|
|
21
|
-
|
|
22
|
-
const { AudioParam, kNativeAudioParam } = require('./AudioParam.js');
|
|
23
|
-
const { AudioDestinationNode, kNativeAudioDestinationNode } = require('./AudioDestinationNode.js');
|
|
24
|
-
|
|
25
|
-
module.exports = (superclass) => {
|
|
26
|
-
class AudioNode extends superclass {
|
|
27
|
-
/* eslint-disable constructor-super */
|
|
28
|
-
constructor(...args) {
|
|
29
|
-
try {
|
|
30
|
-
super(...args);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
throwSanitizedError(err);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/* eslint-enable constructor-super */
|
|
36
|
-
|
|
37
|
-
// getters
|
|
38
|
-
|
|
39
|
-
get context() {
|
|
40
|
-
return super.context;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get numberOfInputs() {
|
|
44
|
-
return super.numberOfInputs;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get numberOfOutputs() {
|
|
48
|
-
return super.numberOfOutputs;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get channelCount() {
|
|
52
|
-
return super.channelCount;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get channelCountMode() {
|
|
56
|
-
return super.channelCountMode;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get channelInterpretation() {
|
|
60
|
-
return super.channelInterpretation;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// setters
|
|
64
|
-
|
|
65
|
-
set channelCount(value) {
|
|
66
|
-
try {
|
|
67
|
-
super.channelCount = value;
|
|
68
|
-
} catch (err) {
|
|
69
|
-
throwSanitizedError(err);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
set channelCountMode(value) {
|
|
74
|
-
try {
|
|
75
|
-
super.channelCountMode = value;
|
|
76
|
-
} catch (err) {
|
|
77
|
-
throwSanitizedError(err);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
set channelInterpretation(value) {
|
|
82
|
-
try {
|
|
83
|
-
super.channelInterpretation = value;
|
|
84
|
-
} catch (err) {
|
|
85
|
-
throwSanitizedError(err);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// methods - connect / disconnect
|
|
90
|
-
|
|
91
|
-
connect(...args) {
|
|
92
|
-
// unwrap raw audio params from facade
|
|
93
|
-
if (args[0] instanceof AudioParam) {
|
|
94
|
-
args[0] = args[0][kNativeAudioParam];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// unwrap raw audio destination from facade
|
|
98
|
-
if (args[0] instanceof AudioDestinationNode) {
|
|
99
|
-
args[0] = args[0][kNativeAudioDestinationNode];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
return super.connect(...args);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
throwSanitizedError(err);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
disconnect(...args) {
|
|
110
|
-
// unwrap raw audio params from facade
|
|
111
|
-
if (args[0] instanceof AudioParam) {
|
|
112
|
-
args[0] = args[0][kNativeAudioParam];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// unwrap raw audio destination from facade
|
|
116
|
-
if (args[0] instanceof AudioDestinationNode) {
|
|
117
|
-
args[0] = args[0][kNativeAudioDestinationNode];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
return super.disconnect(...args);
|
|
122
|
-
} catch (err) {
|
|
123
|
-
throwSanitizedError(err);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return AudioNode;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
|
|
@@ -1,67 +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 { throwSanitizedError } = require('./lib/errors.js');
|
|
21
|
-
|
|
22
|
-
module.exports = (superclass) => {
|
|
23
|
-
class AudioScheduledSourceNode extends superclass {
|
|
24
|
-
constructor(...args) {
|
|
25
|
-
super(...args);
|
|
26
|
-
}
|
|
27
|
-
// getters
|
|
28
|
-
|
|
29
|
-
get onended() {
|
|
30
|
-
return super.onended;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// setters
|
|
34
|
-
|
|
35
|
-
set onended(value) {
|
|
36
|
-
try {
|
|
37
|
-
super.onended = value;
|
|
38
|
-
} catch (err) {
|
|
39
|
-
throwSanitizedError(err);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// methods - start / stop
|
|
44
|
-
|
|
45
|
-
start(...args) {
|
|
46
|
-
try {
|
|
47
|
-
return super.start(...args);
|
|
48
|
-
} catch (err) {
|
|
49
|
-
throwSanitizedError(err);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
stop(...args) {
|
|
54
|
-
try {
|
|
55
|
-
return super.stop(...args);
|
|
56
|
-
} catch (err) {
|
|
57
|
-
throwSanitizedError(err);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return AudioScheduledSourceNode;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
@@ -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
|
-
};
|