@node-3d/webaudio 6.0.1 → 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 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
- Some features are missing for good.
42
+ Unimplemented or noncompliant Web Audio behavior remains work to fix.
29
43
 
30
44
  Currently exported classes:
31
45
 
@@ -1,10 +1,12 @@
1
1
  import { inspect } from 'node:util';
2
- declare const AudioBuffer: import("./native.js").TNativeEs5Constructor<[context: import("./native.js").TBaseAudioContext, source?: Readonly<{
3
- length?: number;
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?: number;
6
- }> | import("./native.js").TNativeExternal | undefined], import("./native.js").TAudioBuffer>;
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: (opts?: TAudioNodeOptions) => TAudioBuffer;
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 (opts = {}) {
272
- return new JsAudioBuffer(this, opts);
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?: number;
26
+ length: number;
28
27
  numberOfChannels?: number;
29
- sampleRate?: number;
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: TAudioBufferData, channelNumber: number, startInChannel: number) => void;
74
- copyToChannel: (source: TAudioBufferData, channelNumber: number, startInChannel: number) => void;
75
- getChannelData: (channelIndex: number) => void;
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
- context: TBaseAudioContext,
186
- source?: TNativeExternal | TAudioBufferOptions
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
@@ -1,6 +1,7 @@
1
- import { install } from '@node-3d/addon-tools';
1
+ import packageJson from './package.json' with { type: 'json' };
2
+ import { getInstallCandidateUrl, install } from '@node-3d/addon-tools';
2
3
 
3
4
  const prefix = 'https://github.com/node-3d/webaudio/releases/download';
4
- const tag = '6.0.0';
5
+ const tag = '6.0.3';
5
6
 
6
- await install(`${prefix}/${tag}`);
7
+ await install(getInstallCandidateUrl(packageJson.name) || `${prefix}/${tag}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Luis Blanco <luisblanco1337@gmail.com>",
3
3
  "name": "@node-3d/webaudio",
4
- "version": "6.0.1",
4
+ "version": "6.0.3",
5
5
  "description": "Web Audio for Node.js",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
@@ -49,20 +49,21 @@
49
49
  "url": "git+https://github.com/node-3d/webaudio.git"
50
50
  },
51
51
  "dependencies": {
52
- "@node-3d/addon-tools": "~10.1.0",
53
- "@node-3d/deps-labsound": "~7.0.1",
54
- "@node-3d/segfault": "~4.0.2"
52
+ "@node-3d/addon-tools": "~10.2.0",
53
+ "@node-3d/deps-labsound": "~7.0.2",
54
+ "@node-3d/segfault": "~4.0.3"
55
55
  },
56
56
  "devDependencies": {
57
- "@types/node": "24.13.2",
57
+ "@types/node": "24.19.0",
58
58
  "node-addon-api": "8.9.2",
59
- "oxlint": "1.81.0",
60
- "oxlint-tsgolint": "7.0.2001",
59
+ "node-gyp": "12.4.0",
60
+ "oxlint": "1.85.0",
61
+ "oxlint-tsgolint": "7.0.2003",
61
62
  "tslib": "2.8.1",
62
- "@rslib/core": "1.0.0",
63
- "oxfmt": "0.66.0",
63
+ "@rslib/core": "1.0.2",
64
+ "oxfmt": "0.70.0",
64
65
  "typescript": "7.0.2",
65
- "clang-format-node": "3.0.7"
66
+ "clang-format-node": "4.0.1"
66
67
  },
67
68
  "type": "module",
68
69
  "types": "dist/index.d.ts",