@node-3d/webaudio 6.0.2 → 6.0.3
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/README.md +15 -1
- package/dist/audio-buffer.d.ts +6 -4
- package/dist/base-audio-context.d.ts +1 -1
- package/dist/index.js +15 -2
- package/dist/native.d.ts +7 -9
- package/install.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,8 +24,22 @@ Import any class you like from the module and then follow the
|
|
|
24
24
|
import { AudioContext } from '@node-3d/webaudio'; // usually this is enough
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
Create a silent PCM buffer using the Web Audio arguments, then write samples:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
const context = new AudioContext();
|
|
31
|
+
const buffer = context.createBuffer(1, context.sampleRate, context.sampleRate);
|
|
32
|
+
const samples = buffer.getChannelData(0);
|
|
33
|
+
samples[0] = 0.5;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`new AudioBuffer({ length, sampleRate, numberOfChannels? })` is also supported.
|
|
37
|
+
`createBuffer()` requires all three arguments. Invalid buffer dimensions and
|
|
38
|
+
sample rates throw `NotSupportedError`; an invalid channel index throws
|
|
39
|
+
`IndexSizeError`.
|
|
40
|
+
|
|
27
41
|
**This module is WORK IN PROGRESS.**
|
|
28
|
-
|
|
42
|
+
Unimplemented or noncompliant Web Audio behavior remains work to fix.
|
|
29
43
|
|
|
30
44
|
Currently exported classes:
|
|
31
45
|
|
package/dist/audio-buffer.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type { TAudioBufferOptions, TBaseAudioContext, TNativeExternal } from './native.js';
|
|
3
|
+
declare const AudioBuffer: import("./native.js").TNativeEs5Constructor<[options: Readonly<{
|
|
4
|
+
length: number;
|
|
4
5
|
numberOfChannels?: number;
|
|
5
|
-
sampleRate
|
|
6
|
-
}> |
|
|
6
|
+
sampleRate: number;
|
|
7
|
+
}>] | [context: TBaseAudioContext, source: TNativeExternal], import("./native.js").TAudioBuffer>;
|
|
7
8
|
declare class JsAudioBuffer extends AudioBuffer {
|
|
9
|
+
constructor(options: TAudioBufferOptions);
|
|
8
10
|
[inspect.custom](): string;
|
|
9
11
|
toString(): string;
|
|
10
12
|
}
|
|
@@ -5,7 +5,7 @@ export type TJsBaseAudioContext = TBaseAudioContext & {
|
|
|
5
5
|
_initListener: (destinationCtor: typeof AudioDestinationNode, listenerCtor: typeof AudioListener, sampleRate: number) => void;
|
|
6
6
|
createAnalyser: (opts?: TAudioNodeOptions) => TAnalyserNode;
|
|
7
7
|
createBiquadFilter: (opts?: TAudioNodeOptions) => TBiquadFilterNode;
|
|
8
|
-
createBuffer: (
|
|
8
|
+
createBuffer: (numberOfChannels: number, length: number, sampleRate: number) => TAudioBuffer;
|
|
9
9
|
createBufferSource: (opts?: TAudioNodeOptions) => TAudioBufferSourceNode;
|
|
10
10
|
createConvolver: (opts?: TAudioNodeOptions) => TConvolverNode;
|
|
11
11
|
createDelay: (maxDelayTime?: number) => TDelayNode;
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,13 @@ const { AudioBuffer: AudioBuffer } = native_native;
|
|
|
28
28
|
inherits(AudioBuffer, node_events);
|
|
29
29
|
audio_buffer_computedKey = _to_property_key(inspect.custom);
|
|
30
30
|
class JsAudioBuffer extends AudioBuffer {
|
|
31
|
+
constructor(options, source){
|
|
32
|
+
if ('length' in options) super(options);
|
|
33
|
+
else {
|
|
34
|
+
if (void 0 === source) throw new TypeError('AudioBuffer requires an options object');
|
|
35
|
+
super(options, source);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
31
38
|
[audio_buffer_computedKey]() {
|
|
32
39
|
return this.toString();
|
|
33
40
|
}
|
|
@@ -268,8 +275,14 @@ const baseAudioContextPrototype = {
|
|
|
268
275
|
createBiquadFilter (opts = {}) {
|
|
269
276
|
return new nodes.BiquadFilterNode(this, opts);
|
|
270
277
|
},
|
|
271
|
-
createBuffer (
|
|
272
|
-
|
|
278
|
+
createBuffer (numberOfChannels, length, sampleRate) {
|
|
279
|
+
if (arguments.length < 3) throw new TypeError('createBuffer requires numberOfChannels, length, and sampleRate');
|
|
280
|
+
const options = {
|
|
281
|
+
numberOfChannels,
|
|
282
|
+
length,
|
|
283
|
+
sampleRate
|
|
284
|
+
};
|
|
285
|
+
return new JsAudioBuffer(options);
|
|
273
286
|
},
|
|
274
287
|
createBufferSource (opts = {}) {
|
|
275
288
|
return new nodes.AudioBufferSourceNode(this, opts);
|
package/dist/native.d.ts
CHANGED
|
@@ -22,11 +22,10 @@ export type TNativeConstructor<TArgs extends readonly unknown[], TInstance exten
|
|
|
22
22
|
new (...args: TArgs): TInstance;
|
|
23
23
|
};
|
|
24
24
|
export type TNativeEs5Constructor<TArgs extends readonly unknown[], TInstance extends object> = TNativeConstructor<TArgs, TInstance> & ((...args: TArgs) => TInstance);
|
|
25
|
-
export type TAudioBufferData = ArrayLike<number> & object;
|
|
26
25
|
export type TAudioBufferOptions = Readonly<{
|
|
27
|
-
length
|
|
26
|
+
length: number;
|
|
28
27
|
numberOfChannels?: number;
|
|
29
|
-
sampleRate
|
|
28
|
+
sampleRate: number;
|
|
30
29
|
}>;
|
|
31
30
|
export type TAudioContextOptions = Readonly<{
|
|
32
31
|
sampleRate?: number;
|
|
@@ -70,9 +69,9 @@ export type TAudioBuffer = TAudioObject & {
|
|
|
70
69
|
readonly length: number;
|
|
71
70
|
readonly numberOfChannels: number;
|
|
72
71
|
readonly sampleRate: number;
|
|
73
|
-
copyFromChannel: (destination:
|
|
74
|
-
copyToChannel: (source:
|
|
75
|
-
getChannelData: (channelIndex: number) =>
|
|
72
|
+
copyFromChannel: (destination: Float32Array, channelNumber: number, bufferOffset?: number) => void;
|
|
73
|
+
copyToChannel: (source: Float32Array, channelNumber: number, bufferOffset?: number) => void;
|
|
74
|
+
getChannelData: (channelIndex: number) => Float32Array;
|
|
76
75
|
};
|
|
77
76
|
export type TAudioListener = TAudioObject & {
|
|
78
77
|
readonly forwardX: TAudioParam;
|
|
@@ -182,9 +181,8 @@ export type TNative = Readonly<{
|
|
|
182
181
|
opts: TAudioNodeOptions
|
|
183
182
|
], TAnalyserNode>;
|
|
184
183
|
AudioBuffer: TNativeEs5Constructor<[
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
], TAudioBuffer>;
|
|
184
|
+
options: TAudioBufferOptions
|
|
185
|
+
] | [context: TBaseAudioContext, source: TNativeExternal], TAudioBuffer>;
|
|
188
186
|
AudioBufferSourceNode: TNativeEs5Constructor<[
|
|
189
187
|
context: TBaseAudioContext,
|
|
190
188
|
paramCtor: TAudioParamConstructor,
|
package/install.js
CHANGED
|
@@ -2,6 +2,6 @@ import packageJson from './package.json' with { type: 'json' };
|
|
|
2
2
|
import { getInstallCandidateUrl, install } from '@node-3d/addon-tools';
|
|
3
3
|
|
|
4
4
|
const prefix = 'https://github.com/node-3d/webaudio/releases/download';
|
|
5
|
-
const tag = '6.0.
|
|
5
|
+
const tag = '6.0.3';
|
|
6
6
|
|
|
7
7
|
await install(getInstallCandidateUrl(packageJson.name) || `${prefix}/${tag}`);
|