node-web-audio-api 0.4.0 → 0.5.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/.eslintrc +3 -0
- package/dummy.mjs +19 -0
- package/index.cjs +17 -20
- package/index.mjs +1 -1
- package/monkey-patch.js +33 -2
- 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-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 +5 -2
package/.eslintrc
ADDED
package/dummy.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AudioContext } from './index.mjs';
|
|
2
|
+
|
|
3
|
+
const audioContext = new AudioContext();
|
|
4
|
+
|
|
5
|
+
const now = audioContext.currentTime;
|
|
6
|
+
|
|
7
|
+
const gain = audioContext.createGain();
|
|
8
|
+
gain.gain.setValueAtTime(0, now);
|
|
9
|
+
gain.connect(audioContext.destination);
|
|
10
|
+
|
|
11
|
+
const src = audioContext.createOscillator();
|
|
12
|
+
src.connect(gain);
|
|
13
|
+
src.start();
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
gain.gain.setValueCurveAtTime(new Float32Array([0, 1, 0]), now + 1, 2);
|
|
17
|
+
// gain.gain.setValueCurveAtTime(new Float32Array([0, 1, 0]), now + 1, 2);
|
|
18
|
+
|
|
19
|
+
gain.gain.linear(new Float32Array([0, 1, 0]), now + 1, 2);
|
package/index.cjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
const { existsSync, readFileSync } = require('fs');
|
|
2
|
-
const { join } = require('path');
|
|
3
|
-
|
|
4
1
|
const { platform, arch } = process;
|
|
5
2
|
|
|
6
3
|
let nativeBinding = null;
|
|
@@ -13,67 +10,67 @@ switch (platform) {
|
|
|
13
10
|
try {
|
|
14
11
|
nativeBinding = require('./node-web-audio-api.win32-x64-msvc.node');
|
|
15
12
|
} catch (e) {
|
|
16
|
-
loadError = e
|
|
13
|
+
loadError = e;
|
|
17
14
|
}
|
|
18
|
-
break
|
|
15
|
+
break;
|
|
19
16
|
case 'arm64':
|
|
20
17
|
try {
|
|
21
18
|
nativeBinding = require('./node-web-audio-api.win32-arm64-msvc.node');
|
|
22
19
|
} catch (e) {
|
|
23
|
-
loadError = e
|
|
20
|
+
loadError = e;
|
|
24
21
|
}
|
|
25
|
-
break
|
|
22
|
+
break;
|
|
26
23
|
default:
|
|
27
24
|
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
28
25
|
}
|
|
29
|
-
break
|
|
26
|
+
break;
|
|
30
27
|
case 'darwin':
|
|
31
28
|
switch (arch) {
|
|
32
29
|
case 'x64':
|
|
33
30
|
try {
|
|
34
31
|
nativeBinding = require('./node-web-audio-api.darwin-x64.node');
|
|
35
32
|
} catch (e) {
|
|
36
|
-
loadError = e
|
|
33
|
+
loadError = e;
|
|
37
34
|
}
|
|
38
|
-
break
|
|
35
|
+
break;
|
|
39
36
|
case 'arm64':
|
|
40
37
|
try {
|
|
41
38
|
nativeBinding = require('./node-web-audio-api.darwin-arm64.node');
|
|
42
39
|
} catch (e) {
|
|
43
|
-
loadError = e
|
|
40
|
+
loadError = e;
|
|
44
41
|
}
|
|
45
|
-
break
|
|
42
|
+
break;
|
|
46
43
|
default:
|
|
47
44
|
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
48
45
|
}
|
|
49
|
-
break
|
|
46
|
+
break;
|
|
50
47
|
case 'linux':
|
|
51
48
|
switch (arch) {
|
|
52
49
|
case 'x64':
|
|
53
50
|
try {
|
|
54
51
|
nativeBinding = require('./node-web-audio-api.linux-x64-gnu.node');
|
|
55
52
|
} catch (e) {
|
|
56
|
-
loadError = e
|
|
53
|
+
loadError = e;
|
|
57
54
|
}
|
|
58
|
-
break
|
|
55
|
+
break;
|
|
59
56
|
case 'arm64':
|
|
60
57
|
try {
|
|
61
58
|
nativeBinding = require('./node-web-audio-api.linux-arm64-gnu.node');
|
|
62
59
|
} catch (e) {
|
|
63
|
-
loadError = e
|
|
60
|
+
loadError = e;
|
|
64
61
|
}
|
|
65
|
-
break
|
|
62
|
+
break;
|
|
66
63
|
case 'arm':
|
|
67
64
|
try {
|
|
68
65
|
nativeBinding = require('./node-web-audio-api.linux-arm-gnueabihf.node');
|
|
69
66
|
} catch (e) {
|
|
70
|
-
loadError = e
|
|
67
|
+
loadError = e;
|
|
71
68
|
}
|
|
72
|
-
break
|
|
69
|
+
break;
|
|
73
70
|
default:
|
|
74
71
|
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
75
72
|
}
|
|
76
|
-
break
|
|
73
|
+
break;
|
|
77
74
|
default:
|
|
78
75
|
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
79
76
|
}
|
package/index.mjs
CHANGED
package/monkey-patch.js
CHANGED
|
@@ -4,6 +4,21 @@ const isPlainObject = function(obj) {
|
|
|
4
4
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
+
const isPositiveInt = function(n) {
|
|
8
|
+
return Number.isSafeInteger(n) && 0 < n;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const isPositiveNumber = function(n) {
|
|
12
|
+
return Number(n) === n && 0 < n;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
class NotSupportedError extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'NotSupportedError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
const { platform, arch } = process;
|
|
8
23
|
let contextId = 0;
|
|
9
24
|
|
|
@@ -88,8 +103,24 @@ function patchAudioContext(NativeAudioContext) {
|
|
|
88
103
|
function patchOfflineAudioContext(NativeOfflineAudioContext) {
|
|
89
104
|
class OfflineAudioContext extends NativeOfflineAudioContext {
|
|
90
105
|
constructor(...args) {
|
|
106
|
+
// handle initialisation with either an options object or a sequence of parameters
|
|
107
|
+
// https://webaudio.github.io/web-audio-api/#dom-offlineaudiocontext-constructor-contextoptions-contextoptions
|
|
108
|
+
if (typeof args[0] === 'object'
|
|
109
|
+
&& 'numberOfChannels' in args[0] && 'length' in args[0] && 'sampleRate' in args[0]
|
|
110
|
+
) {
|
|
111
|
+
const { numberOfChannels, length, sampleRate } = args[0];
|
|
112
|
+
args = [numberOfChannels, length, sampleRate];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!isPositiveInt(args[0])) {
|
|
116
|
+
throw new NotSupportedError(`Unsupported value for numberOfChannels: ${args[0]}`);
|
|
117
|
+
} else if (!isPositiveInt(args[1])) {
|
|
118
|
+
throw new NotSupportedError(`Unsupported value for length: ${args[1]}`);
|
|
119
|
+
} else if (!isPositiveNumber(args[2])) {
|
|
120
|
+
throw new NotSupportedError(`Unsupported value for sampleRate: ${args[2]}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
91
123
|
super(...args);
|
|
92
|
-
console.log(args);
|
|
93
124
|
|
|
94
125
|
// not sure this is usefull, to be tested
|
|
95
126
|
const keepAwakeId = setInterval(() => {}, 10000);
|
|
@@ -141,4 +172,4 @@ module.exports.load = function(path) {
|
|
|
141
172
|
}
|
|
142
173
|
|
|
143
174
|
return { path };
|
|
144
|
-
}
|
|
175
|
+
};
|
|
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.5.0",
|
|
4
4
|
"author": "Benjamin Matuszewski",
|
|
5
5
|
"description": "Node.js bindings for web-audio-api-rs using napi-rs",
|
|
6
6
|
"exports": {
|
|
@@ -31,14 +31,17 @@
|
|
|
31
31
|
"build:debug": "npm run generate && napi build --platform",
|
|
32
32
|
"check": "cargo fmt && cargo clippy",
|
|
33
33
|
"generate": "node generator/index.mjs && cargo fmt",
|
|
34
|
+
"lint": "eslint monkey-patch.js index.cjs index.mjs && eslint examples/*.mjs",
|
|
34
35
|
"preversion": "yarn install && npm run generate",
|
|
35
36
|
"postversion": "cargo bump $npm_package_version && git commit -am \"v$npm_package_version\""
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
39
|
+
"@ircam/eslint-config": "^1.2.0",
|
|
38
40
|
"@sindresorhus/slugify": "^2.1.0",
|
|
39
|
-
"chalk": "^5.0.1",
|
|
40
41
|
"camelcase": "^6.3.0",
|
|
42
|
+
"chalk": "^5.0.1",
|
|
41
43
|
"dotenv": "^16.0.2",
|
|
44
|
+
"eslint": "^8.27.0",
|
|
42
45
|
"node-ssh": "^13.0.0",
|
|
43
46
|
"octokit": "^2.0.7",
|
|
44
47
|
"ping": "^0.4.2",
|