@ain1084/audio-worklet-stream 2.0.0 → 2.0.2

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
@@ -142,9 +142,7 @@ The library does not handle the construction or destruction of AudioContext. Whe
142
142
  Example:
143
143
 
144
144
  ```typescript
145
- import { StreamNodeFactory,
146
- type OutputStreamNode,
147
- } from '@ain1084/audio-worklet-stream'
145
+ import { StreamNodeFactory, type OutputStreamNode } from '@ain1084/audio-worklet-stream'
148
146
 
149
147
  let audioContext: AudioContext | null = null
150
148
  let factory: StreamNodeFactory | null = null
@@ -157,23 +155,23 @@ const clicked = async () => {
157
155
 
158
156
  // Create manual buffer stream
159
157
  const channelCount = 1
160
- const [node, writer] = await factory.createManualBufferNode(
161
- { channelCount, frameBufferSize: 4096 }
162
- )
158
+ const [node, writer] = await factory.createManualBufferNode({
159
+ channelCount,
160
+ frameCount: 4096,
161
+ })
163
162
 
164
163
  // Write frames
165
- writer.write((buffer) => {
166
- const samplesPerFrame = channelCount
167
- for (let i = 0; i < buffer.length; i += samplePerFrame) {
168
- for (let channel = 0; channel < samplesPerFrame; ++channel)
169
- buffer[i + channel] = sampleValue /* TODO: Write sample */
164
+ writer.write((segment) => {
165
+ for (let frame = 0; frame < segment.frameCount; frame++) {
166
+ for (let channel = 0; channel < segment.channels; ++channel) {
167
+ segment.set(frame, channel, /* TODO: Write sample value */)
170
168
  }
171
169
  }
172
170
  // Return the count of written frames
173
- return buffer.length / samplesPerFrame
171
+ return segment.frameCount
174
172
  })
175
173
 
176
- // Play start
174
+ // Start playback
177
175
  node.start()
178
176
  audioContext.connect(audioContext.destination)
179
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ain1084/audio-worklet-stream",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "module": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -39,16 +39,16 @@
39
39
  "docs": "typedoc"
40
40
  },
41
41
  "devDependencies": {
42
- "@stylistic/eslint-plugin": "^2.10.1",
43
- "@types/audioworklet": "^0.0.64",
44
- "@types/node": "^22.9.0",
45
- "@typescript-eslint/parser": "^8.13.0",
46
- "eslint": "^9.14.0",
47
- "globals": "^15.12.0",
48
- "typedoc": "^0.26.11",
49
- "typescript": "^5.6.3",
50
- "typescript-eslint": "^8.13.0",
51
- "vite": "^5.4.10"
42
+ "@stylistic/eslint-plugin": "^5.7.0",
43
+ "@types/audioworklet": "^0.0.92",
44
+ "@types/node": "^25.0.9",
45
+ "@typescript-eslint/parser": "^8.53.0",
46
+ "eslint": "^9.39.2",
47
+ "globals": "^17.0.0",
48
+ "typedoc": "^0.28.16",
49
+ "typescript": "^5.9.3",
50
+ "typescript-eslint": "^8.53.0",
51
+ "vite": "^7.3.1"
52
52
  },
53
53
  "dependencies": {
54
54
  "@ain1084/audio-frame-buffer": "^0.2.0"
@@ -16,9 +16,9 @@
16
16
  * const message: MessageToAudioNode = { type: 'underrun', underrunFrameCount: 256 };
17
17
  * ```
18
18
  */
19
- export type MessageToAudioNode =
20
- | { type: 'stop', totalProcessedFrames: bigint }
21
- | { type: 'underrun', underrunFrameCount: number }
19
+ export type MessageToAudioNode
20
+ = { type: 'stop', totalProcessedFrames: bigint }
21
+ | { type: 'underrun', underrunFrameCount: number }
22
22
 
23
23
  /**
24
24
  * Messages sent from the main thread to the processor.
@@ -33,5 +33,5 @@ export type MessageToAudioNode =
33
33
  * const message: MessageToProcessor = { type: 'stop', framePosition: 1000n };
34
34
  * ```
35
35
  */
36
- export type MessageToProcessor =
37
- | { type: 'stop', framePosition: bigint }
36
+ export type MessageToProcessor
37
+ = { type: 'stop', framePosition: bigint }
@@ -8,15 +8,15 @@ import { FrameBufferContext } from '@ain1084/audio-frame-buffer'
8
8
  * Stream state
9
9
  * Represents the different states of the stream.
10
10
  */
11
- export type StreamState =
11
+ export type StreamState
12
12
  // Initial state where playback can start
13
- | 'ready'
13
+ = | 'ready'
14
14
  // State where playback has started
15
- | 'started'
16
- // State where playback is stopping
17
- | 'stopping'
15
+ | 'started'
16
+ // State where playback is stopping
17
+ | 'stopping'
18
18
  // State where playback has stopped
19
- | 'stopped'
19
+ | 'stopped'
20
20
 
21
21
  /**
22
22
  * OutputStreamNode class
@@ -22,10 +22,10 @@ import type { FillerFrameBufferContext } from '../../filler-frame-buffer-context
22
22
  * };
23
23
  * ```
24
24
  */
25
- export type MessageToWorker<FillerParams> =
26
- | { type: 'init', config: FillerFrameBufferContext, fillerParams: FillerParams }
27
- | { type: 'start' }
28
- | { type: 'stop' }
25
+ export type MessageToWorker<FillerParams>
26
+ = | { type: 'init', config: FillerFrameBufferContext, fillerParams: FillerParams }
27
+ | { type: 'start' }
28
+ | { type: 'stop' }
29
29
 
30
30
  /**
31
31
  * Message sent from the worker to the main thread.
@@ -43,6 +43,6 @@ export type MessageToWorker<FillerParams> =
43
43
  * };
44
44
  * ```
45
45
  */
46
- export type MessageToStrategy =
47
- | { type: 'init-done' }
48
- | { type: 'stop', stopFrames: bigint }
46
+ export type MessageToStrategy
47
+ = | { type: 'init-done' }
48
+ | { type: 'stop', stopFrames: bigint }