@ain1084/audio-worklet-stream 1.0.3 → 1.0.5
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 +30 -3
- package/dist/frame-buffer/buffer-config.d.ts +0 -7
- package/dist/frame-buffer/buffer-config.js +7 -14
- package/dist/frame-buffer/buffer-config.js.map +1 -1
- package/dist/frame-buffer/buffer-reader.d.ts +8 -5
- package/dist/frame-buffer/buffer-reader.js +11 -7
- package/dist/frame-buffer/buffer-reader.js.map +1 -1
- package/dist/frame-buffer/buffer-writer.d.ts +8 -5
- package/dist/frame-buffer/buffer-writer.js +11 -7
- package/dist/frame-buffer/buffer-writer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/output-stream-node.d.ts +3 -2
- package/dist/output-stream-node.js +5 -8
- package/dist/output-stream-node.js.map +1 -1
- package/dist/output-stream-processor.d.ts +1 -13
- package/dist/output-stream-processor.js +1 -5
- package/dist/output-stream-processor.js.map +1 -1
- package/dist/stream-node-factory.d.ts +23 -14
- package/dist/stream-node-factory.js +3 -3
- package/dist/stream-node-factory.js.map +1 -1
- package/dist/write-strategy/manual-strategy.d.ts +36 -0
- package/dist/write-strategy/manual-strategy.js +43 -0
- package/dist/write-strategy/manual-strategy.js.map +1 -0
- package/dist/write-strategy/timed-strategy.d.ts +36 -0
- package/dist/write-strategy/timed-strategy.js +92 -0
- package/dist/write-strategy/timed-strategy.js.map +1 -0
- package/dist/write-strategy/worker/worker-strategy.d.ts +34 -0
- package/dist/write-strategy/worker/worker-strategy.js +125 -0
- package/dist/write-strategy/worker/worker-strategy.js.map +1 -0
- package/dist/write-strategy/worker/worker.d.ts +4 -2
- package/dist/write-strategy/worker/worker.js +6 -4
- package/dist/write-strategy/worker/worker.js.map +1 -1
- package/dist/write-strategy/worker-strategy.d.ts +34 -0
- package/dist/write-strategy/worker-strategy.js +125 -0
- package/dist/write-strategy/worker-strategy.js.map +1 -0
- package/package.json +11 -9
- package/src/frame-buffer/buffer-config.ts +7 -20
- package/src/frame-buffer/buffer-reader.ts +11 -7
- package/src/frame-buffer/buffer-writer.ts +11 -7
- package/src/index.ts +1 -0
- package/src/output-stream-node.ts +5 -9
- package/src/output-stream-processor.ts +2 -23
- package/src/stream-node-factory.ts +26 -17
- package/src/write-strategy/{manual.ts → manual-strategy.ts} +3 -3
- package/src/write-strategy/{timed.ts → timed-strategy.ts} +5 -5
- package/src/write-strategy/worker/worker.ts +7 -5
- package/src/write-strategy/{worker/strategy.ts → worker-strategy.ts} +4 -4
package/README.md
CHANGED
|
@@ -142,6 +142,10 @@ 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'
|
|
148
|
+
|
|
145
149
|
let audioContext: AudioContext | null = null
|
|
146
150
|
let factory: StreamNodeFactory | null = null
|
|
147
151
|
|
|
@@ -150,7 +154,28 @@ const clicked = async () => {
|
|
|
150
154
|
audioContext = new AudioContext()
|
|
151
155
|
factory = await StreamNodeFactory.create(audioContext)
|
|
152
156
|
}
|
|
153
|
-
|
|
157
|
+
|
|
158
|
+
// Create manual buffer stream
|
|
159
|
+
const channelCount = 1
|
|
160
|
+
const [node, writer] = await factory.createManualBufferNode(
|
|
161
|
+
{ channelCount, frameBufferSize: 4096 }
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
// 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 */
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Return the count of written frames
|
|
173
|
+
return buffer.length / samplesPerFrame
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
// Play start
|
|
177
|
+
node.start()
|
|
178
|
+
audioContext.connect(audioContext.destination)
|
|
154
179
|
}
|
|
155
180
|
```
|
|
156
181
|
|
|
@@ -158,7 +183,7 @@ const clicked = async () => {
|
|
|
158
183
|
|
|
159
184
|
As outlined in the overview, OutputStreamNode requires external audio samples. These samples must be written to a ring buffer, and there are several methods to achieve this.
|
|
160
185
|
|
|
161
|
-
**Note
|
|
186
|
+
**Note**: The diagrams are simplified for ease of understanding and may differ from the actual implementation.
|
|
162
187
|
|
|
163
188
|
#### Manual
|
|
164
189
|
|
|
@@ -191,6 +216,8 @@ As outlined in the overview, OutputStreamNode requires external audio samples. T
|
|
|
191
216
|
- You need to create a custom Worker. However, helper implementations are available to simplify this process. Essentially, you only need to specify the `FrameBufferFiller` implementation class within the Worker.
|
|
192
217
|
- Depending on how you implement the `FrameBufferFiller` class, you can use the same implementation as the Timed method.
|
|
193
218
|
|
|
219
|
+
**Note**: Any data passed from the UI thread to the Worker (such as fillerParams in the WorkerBufferNodeParams<T>) must be serializable (e.g., primitives, arrays, objects). Non-serializable values like functions or DOM elements cannot be passed.
|
|
220
|
+
|
|
194
221
|
### Buffer Underrun Handling
|
|
195
222
|
|
|
196
223
|
- When the buffer becomes empty, silent audio is output instead of throwing an error.
|
|
@@ -235,7 +262,7 @@ For 48kHz sample rate and 20ms fillInterval:
|
|
|
235
262
|
- One chunk size = 48000 * 0.02 = 960 frames
|
|
236
263
|
- Total buffer size with default 5 chunks = 960 * 5 = 4800 frames
|
|
237
264
|
|
|
238
|
-
The actual values may slightly differ from the above because they are rounded up to 128
|
|
265
|
+
The actual values may slightly differ from the above because they are rounded up to 128 frame units.
|
|
239
266
|
|
|
240
267
|
</details>
|
|
241
268
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FrameBufferWriter } from './buffer-writer';
|
|
2
1
|
/**
|
|
3
2
|
* Parameters for creating a FrameBuffer.
|
|
4
3
|
* @property frameBufferSize - The size of the frame buffer.
|
|
@@ -47,12 +46,6 @@ export type FillerFrameBufferConfig = FrameBufferConfig & Readonly<{
|
|
|
47
46
|
sampleRate: number;
|
|
48
47
|
fillInterval: number;
|
|
49
48
|
}>;
|
|
50
|
-
/**
|
|
51
|
-
* Creates a FrameBufferWriter instance.
|
|
52
|
-
* @param config - The configuration for the FrameBuffer.
|
|
53
|
-
* @returns A new instance of FrameBufferWriter.
|
|
54
|
-
*/
|
|
55
|
-
export declare const createFrameBufferWriter: (config: FrameBufferConfig) => FrameBufferWriter;
|
|
56
49
|
/**
|
|
57
50
|
* Creates a FrameBufferConfig instance.
|
|
58
51
|
* @param params - The parameters for the FrameBuffer.
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FrameBufferWriter } from './buffer-writer';
|
|
1
|
+
import { createArrayBufferViews } from '@ain1084/array-buffer-partitioner';
|
|
3
2
|
/**
|
|
4
3
|
* The default number of chunks in the frame buffer when
|
|
5
4
|
* FillerFrameBufferParams.frameBufferChunks is not provided.
|
|
@@ -18,14 +17,6 @@ const DEFAULT_FRAME_BUFFER_CHUNKS = 5;
|
|
|
18
17
|
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process
|
|
19
18
|
*/
|
|
20
19
|
const AUDIO_WORKLET_BLOCK_SIZE = 128;
|
|
21
|
-
/**
|
|
22
|
-
* Creates a FrameBufferWriter instance.
|
|
23
|
-
* @param config - The configuration for the FrameBuffer.
|
|
24
|
-
* @returns A new instance of FrameBufferWriter.
|
|
25
|
-
*/
|
|
26
|
-
export const createFrameBufferWriter = (config) => {
|
|
27
|
-
return new FrameBufferWriter(new FrameBuffer(config.sampleBuffer, config.samplesPerFrame), config.usedFramesInBuffer, config.totalWriteFrames);
|
|
28
|
-
};
|
|
29
20
|
/**
|
|
30
21
|
* Creates a FrameBufferConfig instance.
|
|
31
22
|
* @param params - The parameters for the FrameBuffer.
|
|
@@ -33,11 +24,13 @@ export const createFrameBufferWriter = (config) => {
|
|
|
33
24
|
*/
|
|
34
25
|
export const createFrameBufferConfig = (params) => {
|
|
35
26
|
return {
|
|
36
|
-
|
|
27
|
+
...createArrayBufferViews(SharedArrayBuffer, {
|
|
28
|
+
sampleBuffer: [Float32Array, params.frameBufferSize * params.channelCount],
|
|
29
|
+
usedFramesInBuffer: [Uint32Array, 1],
|
|
30
|
+
totalReadFrames: [BigUint64Array, 1],
|
|
31
|
+
totalWriteFrames: [BigUint64Array, 1],
|
|
32
|
+
}),
|
|
37
33
|
samplesPerFrame: params.channelCount,
|
|
38
|
-
usedFramesInBuffer: new Uint32Array(new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT)),
|
|
39
|
-
totalReadFrames: new BigUint64Array(new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT)),
|
|
40
|
-
totalWriteFrames: new BigUint64Array(new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT)),
|
|
41
34
|
};
|
|
42
35
|
};
|
|
43
36
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-config.js","sourceRoot":"","sources":["../../src/frame-buffer/buffer-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"buffer-config.js","sourceRoot":"","sources":["../../src/frame-buffer/buffer-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAE1E;;;;GAIG;AACH,MAAM,wBAAwB,GAAG,EAAE,CAAA;AAEnC;;;;GAIG;AACH,MAAM,2BAA2B,GAAG,CAAC,CAAA;AAErC;;;;GAIG;AACH,MAAM,wBAAwB,GAAG,GAAG,CAAA;AAsDpC;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAyB,EAAqB,EAAE;IACtF,OAAO;QACL,GAAG,sBAAsB,CAAC,iBAAiB,EAAE;YAC3C,YAAY,EA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'./buffer-config';
|
|
2
2
|
/**
|
|
3
3
|
* FrameBufferReader class
|
|
4
4
|
* This class reads audio frame data from a shared Float32Array buffer and processes it.
|
|
@@ -10,12 +10,15 @@ export declare class FrameBufferReader {
|
|
|
10
10
|
private readonly _totalFrames;
|
|
11
11
|
private _index;
|
|
12
12
|
/**
|
|
13
|
+
* @internal
|
|
13
14
|
* Creates an instance of FrameBufferReader.
|
|
14
|
-
* @param
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* @param config - The configuration object containing:
|
|
16
|
+
* - `sampleBuffer`: The shared buffer to read audio data frames from.
|
|
17
|
+
* - `samplesPerFrame`: The number of samples per frame.
|
|
18
|
+
* - `usedFramesInBuffer`: A Uint32Array tracking the usage of frames in the buffer.
|
|
19
|
+
* - `totalReadFrames`: A BigUint64Array tracking the total frames read from the buffer.
|
|
17
20
|
*/
|
|
18
|
-
constructor(
|
|
21
|
+
constructor(config: FrameBufferConfig);
|
|
19
22
|
/**
|
|
20
23
|
* Get the number of available frames in the buffer.
|
|
21
24
|
* @returns The number of available frames in the buffer.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FrameBuffer } from './buffer';
|
|
1
2
|
/**
|
|
2
3
|
* FrameBufferReader class
|
|
3
4
|
* This class reads audio frame data from a shared Float32Array buffer and processes it.
|
|
@@ -9,15 +10,18 @@ export class FrameBufferReader {
|
|
|
9
10
|
_totalFrames;
|
|
10
11
|
_index = 0;
|
|
11
12
|
/**
|
|
13
|
+
* @internal
|
|
12
14
|
* Creates an instance of FrameBufferReader.
|
|
13
|
-
* @param
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* @param config - The configuration object containing:
|
|
16
|
+
* - `sampleBuffer`: The shared buffer to read audio data frames from.
|
|
17
|
+
* - `samplesPerFrame`: The number of samples per frame.
|
|
18
|
+
* - `usedFramesInBuffer`: A Uint32Array tracking the usage of frames in the buffer.
|
|
19
|
+
* - `totalReadFrames`: A BigUint64Array tracking the total frames read from the buffer.
|
|
16
20
|
*/
|
|
17
|
-
constructor(
|
|
18
|
-
this._frameBuffer =
|
|
19
|
-
this._usedFramesInBuffer = usedFramesInBuffer;
|
|
20
|
-
this._totalFrames =
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this._frameBuffer = new FrameBuffer(config.sampleBuffer, config.samplesPerFrame);
|
|
23
|
+
this._usedFramesInBuffer = config.usedFramesInBuffer;
|
|
24
|
+
this._totalFrames = config.totalReadFrames;
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
27
|
* Get the number of available frames in the buffer.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-reader.js","sourceRoot":"","sources":["../../src/frame-buffer/buffer-reader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffer-reader.js","sourceRoot":"","sources":["../../src/frame-buffer/buffer-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGtC;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IACX,YAAY,CAAa;IACzB,mBAAmB,CAAa;IAChC,YAAY,CAAgB;IACrC,MAAM,GAAW,CAAC,CAAA;IAE1B;;;;;;;;OAQG;IACH,YAAY,MAAyB;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,eAAe,CAAC,CAAA;QAChF,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,kBAAkB,CAAA;QACpD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,eAAe,CAAA;IAC5C,CAAC;IAED;;;OAGG;IACH,IAAW,eAAe;QACxB,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAA;IAClD,CAAC;IAED;;;;OAIG;IACH,IAAW,WAAW;QACpB,2DAA2D;QAC3D,4DAA4D;QAC5D,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,IAAI,CAAC,mBAAqE;QAC/E,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAA;QAC1G,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;QAC9B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAA;QACrE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAA;QACtE,OAAO,MAAM,CAAC,oBAAoB,CAAA;IACpC,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FrameBufferConfig } from './buffer-config';
|
|
2
2
|
/**
|
|
3
3
|
* FrameBufferWriter class
|
|
4
4
|
* This class writes audio frame data to a shared Float32Array buffer.
|
|
@@ -10,12 +10,15 @@ export declare class FrameBufferWriter {
|
|
|
10
10
|
private readonly _totalFrames;
|
|
11
11
|
private _index;
|
|
12
12
|
/**
|
|
13
|
+
* @internal
|
|
13
14
|
* Creates an instance of FrameBufferWriter.
|
|
14
|
-
* @param
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* @param config - The configuration object containing:
|
|
16
|
+
* - `sampleBuffer`: The shared buffer to write audio data frames.
|
|
17
|
+
* - `samplesPerFrame`: The number of samples per frame.
|
|
18
|
+
* - `usedFramesInBuffer`: A Uint32Array tracking the usage of frames in the buffer.
|
|
19
|
+
* - `totalWriteFrames`: A BigUint64Array tracking the total frames written to the buffer.
|
|
17
20
|
*/
|
|
18
|
-
constructor(
|
|
21
|
+
constructor(config: FrameBufferConfig);
|
|
19
22
|
/**
|
|
20
23
|
* Get the number of available frames in the buffer.
|
|
21
24
|
* This represents the number of frames that can be written before the buffer is full.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FrameBuffer } from './buffer';
|
|
1
2
|
/**
|
|
2
3
|
* FrameBufferWriter class
|
|
3
4
|
* This class writes audio frame data to a shared Float32Array buffer.
|
|
@@ -9,15 +10,18 @@ export class FrameBufferWriter {
|
|
|
9
10
|
_totalFrames;
|
|
10
11
|
_index = 0;
|
|
11
12
|
/**
|
|
13
|
+
* @internal
|
|
12
14
|
* Creates an instance of FrameBufferWriter.
|
|
13
|
-
* @param
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* @param config - The configuration object containing:
|
|
16
|
+
* - `sampleBuffer`: The shared buffer to write audio data frames.
|
|
17
|
+
* - `samplesPerFrame`: The number of samples per frame.
|
|
18
|
+
* - `usedFramesInBuffer`: A Uint32Array tracking the usage of frames in the buffer.
|
|
19
|
+
* - `totalWriteFrames`: A BigUint64Array tracking the total frames written to the buffer.
|
|
16
20
|
*/
|
|
17
|
-
constructor(
|
|
18
|
-
this._frameBuffer =
|
|
19
|
-
this._usedFramesInBuffer = usedFramesInBuffer;
|
|
20
|
-
this._totalFrames =
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this._frameBuffer = new FrameBuffer(config.sampleBuffer, config.samplesPerFrame);
|
|
23
|
+
this._usedFramesInBuffer = config.usedFramesInBuffer;
|
|
24
|
+
this._totalFrames = config.totalWriteFrames;
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
27
|
* Get the number of available frames in the buffer.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-writer.js","sourceRoot":"","sources":["../../src/frame-buffer/buffer-writer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffer-writer.js","sourceRoot":"","sources":["../../src/frame-buffer/buffer-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGtC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GED
|
@@ -2,5 +2,5 @@ export { StopEvent, UnderrunEvent } from './events';
|
|
|
2
2
|
export type { OutputStreamNode } from './output-stream-node';
|
|
3
3
|
export type { FrameBufferWriter } from './frame-buffer/buffer-writer';
|
|
4
4
|
export type { FrameBufferFiller } from './frame-buffer/buffer-filler';
|
|
5
|
-
export { StreamNodeFactory, type ManualBufferNodeParams, type TimedBufferNodeParams, } from './stream-node-factory';
|
|
5
|
+
export { StreamNodeFactory, type ManualBufferNodeParams, type TimedBufferNodeParams, type WorkerBufferNodeParams, } from './stream-node-factory';
|
|
6
6
|
export { BufferFillWorker } from './write-strategy/worker/worker';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAInD,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAInD,OAAO,EAAE,iBAAiB,GAIzB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA"}
|
|
@@ -23,13 +23,14 @@ export declare class OutputStreamNode extends AudioWorkletNode {
|
|
|
23
23
|
*/
|
|
24
24
|
private constructor();
|
|
25
25
|
/**
|
|
26
|
+
* @internal
|
|
26
27
|
* Creates an instance of OutputStreamNode.
|
|
27
28
|
* @param audioContext - The audio context to use.
|
|
28
|
-
* @param
|
|
29
|
+
* @param config - The configuration for the buffer.
|
|
29
30
|
* @param strategy - The strategy for writing to the buffer.
|
|
30
31
|
* @returns A promise that resolves to an instance of OutputStreamNode.
|
|
31
32
|
*/
|
|
32
|
-
static create(audioContext: BaseAudioContext,
|
|
33
|
+
static create(audioContext: BaseAudioContext, config: FrameBufferConfig, strategy: BufferWriteStrategy): Promise<OutputStreamNode>;
|
|
33
34
|
/**
|
|
34
35
|
* Start playback.
|
|
35
36
|
* The node must be connected before starting playback using connect() method.
|
|
@@ -17,13 +17,9 @@ export class OutputStreamNode extends AudioWorkletNode {
|
|
|
17
17
|
* @param strategy - The strategy for writing to the buffer.
|
|
18
18
|
*/
|
|
19
19
|
constructor(baseAudioContext, bufferConfig, strategy) {
|
|
20
|
-
const processorOptions = {
|
|
21
|
-
...bufferConfig,
|
|
22
|
-
totalFrames: bufferConfig.totalReadFrames,
|
|
23
|
-
};
|
|
24
20
|
super(baseAudioContext, PROCESSOR_NAME, {
|
|
25
21
|
outputChannelCount: [bufferConfig.samplesPerFrame],
|
|
26
|
-
processorOptions,
|
|
22
|
+
processorOptions: bufferConfig,
|
|
27
23
|
});
|
|
28
24
|
this._strategy = strategy;
|
|
29
25
|
this._totalWriteFrames = bufferConfig.totalWriteFrames;
|
|
@@ -31,14 +27,15 @@ export class OutputStreamNode extends AudioWorkletNode {
|
|
|
31
27
|
this.port.onmessage = this.handleMessage.bind(this);
|
|
32
28
|
}
|
|
33
29
|
/**
|
|
30
|
+
* @internal
|
|
34
31
|
* Creates an instance of OutputStreamNode.
|
|
35
32
|
* @param audioContext - The audio context to use.
|
|
36
|
-
* @param
|
|
33
|
+
* @param config - The configuration for the buffer.
|
|
37
34
|
* @param strategy - The strategy for writing to the buffer.
|
|
38
35
|
* @returns A promise that resolves to an instance of OutputStreamNode.
|
|
39
36
|
*/
|
|
40
|
-
static async create(audioContext,
|
|
41
|
-
const node = new OutputStreamNode(audioContext,
|
|
37
|
+
static async create(audioContext, config, strategy) {
|
|
38
|
+
const node = new OutputStreamNode(audioContext, config, strategy);
|
|
42
39
|
if (!(await strategy.onInit(node))) {
|
|
43
40
|
throw new Error('Failed to onInit.');
|
|
44
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-stream-node.js","sourceRoot":"","sources":["../src/output-stream-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output-stream-node.js","sourceRoot":"","sources":["../src/output-stream-node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAkBnD;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,gBAAgB;IACnC,iBAAiB,CAAgB;IACjC,gBAAgB,CAAgB;IAChC,SAAS,CAAqB;IACvC,MAAM,GAAgB,OAAO,CAAA;IAErC;;;;;OAKG;IACH,YACE,gBAAkC,EAClC,YAA+B,EAC/B,QAA6B;QAE7B,KAAK,CAAC,gBAAgB,EAAE,cAAc,EAAE;YACtC,kBAAkB,EAAE,CAAC,YAAY,CAAC,eAAe,CAAC;YAClD,gBAAgB,EAAE,YAAY;SAC/B,CAAC,CAAA;QACF,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QACzB,IAAI,CAAC,iBAAiB,GAAG,YAAY,CAAC,gBAAgB,CAAA;QACtD,IAAI,CAAC,gBAAgB,GAAG,YAAY,CAAC,eAAe,CAAA;QACpD,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrD,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,YAA8B,EAAE,MAAyB,EAAE,QAA6B;QACjH,MAAM,IAAI,GAAG,IAAI,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;QACjE,IAAI,CAAC,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;QACtC,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;OAMG;IACI,KAAK;QACV,I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AC,CAAA;IAChD,CAAC;CACF"}
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Options for the OutputStreamProcessor
|
|
3
|
-
* @property sampleBuffer - The shared buffer for audio data frames.
|
|
4
|
-
* @property samplesPerFrame - The number of samples per frame.
|
|
5
|
-
* @property usedFramesInBuffer - The usage count of the frames in the buffer.
|
|
6
|
-
* @property totalFrames - The current position in the buffer, in frames.
|
|
7
|
-
*/
|
|
8
|
-
export type OutputStreamProcessorOptions = Readonly<{
|
|
9
|
-
sampleBuffer: Float32Array;
|
|
10
|
-
samplesPerFrame: number;
|
|
11
|
-
usedFramesInBuffer: Uint32Array;
|
|
12
|
-
totalFrames: BigUint64Array;
|
|
13
|
-
}>;
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { FrameBufferReader } from './frame-buffer/buffer-reader';
|
|
2
2
|
import { PROCESSOR_NAME } from './constants';
|
|
3
|
-
import { FrameBuffer } from './frame-buffer/buffer';
|
|
4
|
-
const createFrameBufferReader = (options) => {
|
|
5
|
-
return new FrameBufferReader(new FrameBuffer(options.sampleBuffer, options.samplesPerFrame), options.usedFramesInBuffer, options.totalFrames);
|
|
6
|
-
};
|
|
7
3
|
/**
|
|
8
4
|
* OutputStreamProcessor class
|
|
9
5
|
* This class extends AudioWorkletProcessor to process audio data.
|
|
@@ -20,7 +16,7 @@ class OutputStreamProcessor extends AudioWorkletProcessor {
|
|
|
20
16
|
*/
|
|
21
17
|
constructor(options) {
|
|
22
18
|
super();
|
|
23
|
-
this._frameReader =
|
|
19
|
+
this._frameReader = new FrameBufferReader(options.processorOptions);
|
|
24
20
|
this.port.onmessage = this.handleMessage.bind(this);
|
|
25
21
|
}
|
|
26
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-stream-processor.js","sourceRoot":"","sources":["../src/output-stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8B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C,CAAC;YACH,CAAC,CAAC,CAAA;YACF,OAAO,UAAU,CAAA;QACnB,CAAC,CAAC,CAAA;QACF,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAA;QACjD,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAA;QACpC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,cAAc,EAAE,CAAA;YACrB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,oBAAoB,EAAE,WAAW,EAAwB,CAAC,CAAA;YAChG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;YACjB,OAAO,KAAK,CAAA;QACd,CAAC;QACD,MAAM,cAAc,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,UAAU,CAAA;QACpD,iDAAiD;QACjD,IAAI,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAA;QACrC,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED,iBAAiB,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAA"}
|
|
@@ -3,33 +3,42 @@ import type { FrameBufferFiller } from './frame-buffer/buffer-filler';
|
|
|
3
3
|
import { FrameBufferWriter } from './frame-buffer/buffer-writer';
|
|
4
4
|
/**
|
|
5
5
|
* Parameters for creating a manual buffer node.
|
|
6
|
+
* Used in the {@link StreamNodeFactory.createManualBufferNode} function.
|
|
6
7
|
*/
|
|
7
|
-
export type ManualBufferNodeParams =
|
|
8
|
+
export type ManualBufferNodeParams = {
|
|
8
9
|
/** The number of audio channels. */
|
|
9
|
-
channelCount: number;
|
|
10
|
+
readonly channelCount: number;
|
|
10
11
|
/** The size of the frame buffer in frames. */
|
|
11
|
-
frameBufferSize: number;
|
|
12
|
-
}
|
|
12
|
+
readonly frameBufferSize: number;
|
|
13
|
+
};
|
|
13
14
|
/**
|
|
14
15
|
* Parameters for creating a timed buffer node.
|
|
16
|
+
* Used in the {@link StreamNodeFactory.createTimedBufferNode} function.
|
|
15
17
|
*/
|
|
16
|
-
export type TimedBufferNodeParams =
|
|
18
|
+
export type TimedBufferNodeParams = {
|
|
17
19
|
/** The number of audio channels. */
|
|
18
|
-
channelCount: number;
|
|
20
|
+
readonly channelCount: number;
|
|
19
21
|
/** Optional. The number of chunks in the frame buffer. */
|
|
20
|
-
frameBufferChunks?: number;
|
|
22
|
+
readonly frameBufferChunks?: number;
|
|
21
23
|
/** Optional. The interval in milliseconds for filling the buffer. */
|
|
22
|
-
fillInterval?: number;
|
|
24
|
+
readonly fillInterval?: number;
|
|
23
25
|
/** Optional. The sample rate of the audio context. */
|
|
24
|
-
sampleRate?: number;
|
|
25
|
-
}
|
|
26
|
+
readonly sampleRate?: number;
|
|
27
|
+
};
|
|
26
28
|
/**
|
|
27
29
|
* Parameters for creating a worker buffer node.
|
|
30
|
+
* Used in the {@link StreamNodeFactory.createWorkerBufferNode} function.
|
|
31
|
+
*
|
|
32
|
+
* @template FillerParams - The parameters used by the FrameBufferFiller in the worker.
|
|
28
33
|
*/
|
|
29
|
-
export type WorkerBufferNodeParams<
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
export type WorkerBufferNodeParams<FillerParams> = TimedBufferNodeParams & {
|
|
35
|
+
/**
|
|
36
|
+
* Parameters passed to the constructor when the Worker instantiates the FrameBufferFiller implementation class.
|
|
37
|
+
* Note: The values passed as FillerParams must be serializable (e.g., primitives, arrays, objects).
|
|
38
|
+
* Non-serializable values such as functions or DOM elements cannot be passed.
|
|
39
|
+
*/
|
|
40
|
+
readonly fillerParams: FillerParams;
|
|
41
|
+
};
|
|
33
42
|
/**
|
|
34
43
|
* StreamNodeFactory class
|
|
35
44
|
* Factory class to create instances of OutputStreamNode with specific BufferWriteStrategy.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import processor from './output-stream-processor?worker&url';
|
|
2
|
-
import { ManualBufferWriteStrategy } from './write-strategy/manual';
|
|
2
|
+
import { ManualBufferWriteStrategy } from './write-strategy/manual-strategy';
|
|
3
3
|
import { createFillerFrameBufferConfig, createFrameBufferConfig } from './frame-buffer/buffer-config';
|
|
4
|
-
import { TimedBufferWriteStrategy } from './write-strategy/timed';
|
|
5
|
-
import { WorkerBufferWriteStrategy } from './write-strategy/worker
|
|
4
|
+
import { TimedBufferWriteStrategy } from './write-strategy/timed-strategy';
|
|
5
|
+
import { WorkerBufferWriteStrategy } from './write-strategy/worker-strategy';
|
|
6
6
|
/**
|
|
7
7
|
* StreamNodeFactory class
|
|
8
8
|
* Factory class to create instances of OutputStreamNode with specific BufferWriteStrategy.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-node-factory.js","sourceRoot":"","sources":["../src/stream-node-factory.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,sCAAsC,CAAA;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"stream-node-factory.js","sourceRoot":"","sources":["../src/stream-node-factory.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,sCAAsC,CAAA;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAC5E,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAErG,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAG1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AA2C5E;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACpB,aAAa,CAAc;IAClB,wBAAwB,CAAyB;IAElE;;;;OAIG;IACH,YAAoB,OAAqB,EAAE,uBAAgD;QACzF,IAAI,CAAC,aAAa,GAAG,OAAO,CAAA;QAC5B,IAAI,CAAC,wBAAwB,GAAG,uBAAuB,CAAA;IACzD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QACtE,CAAC;QAED,2DAA2D;QAC3D,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,IAAI,CAAC,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ,IAAI,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,EAAE,CAAC;YAC/G,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;QACrE,CAAC;QAED,iEAAiE;QACjE,IAAI,MAAM,CAAC,iBAAiB,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,MAAM,CAAC,iBAAiB,IAAI,CAAC,CAAC,EAAE,CAAC;YAC7H,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;QAC3E,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACK,MAAM,CAAC,uBAAuB,CAAC,MAA6B,EAAE,iBAAyB;QAC7F,OAAO;YACL,GAAG,MAAM;YACT,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,iBAAiB;SACnD,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BufferWriteStrategy } from './strategy';
|
|
2
|
+
import type { FrameBufferConfig } from '../frame-buffer/buffer-config';
|
|
3
|
+
import { FrameBufferWriter } from '../frame-buffer/buffer-writer';
|
|
4
|
+
/**
|
|
5
|
+
* ManualBufferWriteStrategy class
|
|
6
|
+
* Implements the BufferWriteStrategy interface for manually writing to the buffer.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ManualBufferWriteStrategy implements BufferWriteStrategy {
|
|
9
|
+
private readonly _writer;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of ManualBufferWriteStrategy.
|
|
12
|
+
* @param config - The configuration for the frame buffer.
|
|
13
|
+
*/
|
|
14
|
+
constructor(config: FrameBufferConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Gets the FrameBufferWriter instance.
|
|
17
|
+
* @returns The FrameBufferWriter instance.
|
|
18
|
+
*/
|
|
19
|
+
get writer(): FrameBufferWriter;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the strategy.
|
|
22
|
+
* @param node - The OutputStreamNode instance.
|
|
23
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
24
|
+
*/
|
|
25
|
+
onInit(): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Starts the strategy.
|
|
28
|
+
* @param node - The OutputStreamNode instance.
|
|
29
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
30
|
+
*/
|
|
31
|
+
onStart(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Stops the strategy.
|
|
34
|
+
*/
|
|
35
|
+
onStopped(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FrameBufferWriter } from '../frame-buffer/buffer-writer';
|
|
2
|
+
/**
|
|
3
|
+
* ManualBufferWriteStrategy class
|
|
4
|
+
* Implements the BufferWriteStrategy interface for manually writing to the buffer.
|
|
5
|
+
*/
|
|
6
|
+
export class ManualBufferWriteStrategy {
|
|
7
|
+
_writer;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of ManualBufferWriteStrategy.
|
|
10
|
+
* @param config - The configuration for the frame buffer.
|
|
11
|
+
*/
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this._writer = new FrameBufferWriter(config);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets the FrameBufferWriter instance.
|
|
17
|
+
* @returns The FrameBufferWriter instance.
|
|
18
|
+
*/
|
|
19
|
+
get writer() {
|
|
20
|
+
return this._writer;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initializes the strategy.
|
|
24
|
+
* @param node - The OutputStreamNode instance.
|
|
25
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
26
|
+
*/
|
|
27
|
+
async onInit( /* node: OutputStreamNode */) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Starts the strategy.
|
|
32
|
+
* @param node - The OutputStreamNode instance.
|
|
33
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
34
|
+
*/
|
|
35
|
+
onStart( /* node: OutputStreamNode */) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Stops the strategy.
|
|
40
|
+
*/
|
|
41
|
+
onStopped() { }
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=manual-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual-strategy.js","sourceRoot":"","sources":["../../src/write-strategy/manual-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAEjE;;;IAGI;AACJ,MAAM,OAAO,yBAAyB;IACnB,OAAO,CAAmB;IAE3C;;;OAGG;IACH,YAAY,MAAyB;QACnC,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAA;IAC9C,CAAC;IAED;;;OAGG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAC,4BAA4B;QACvC,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;OAIG;IACH,OAAO,EAAC,4BAA4B;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,SAAS,KAAU,CAAC;CACrB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BufferWriteStrategy } from './strategy';
|
|
2
|
+
import type { FillerFrameBufferConfig } from '../frame-buffer/buffer-config';
|
|
3
|
+
import type { FrameBufferFiller } from '../frame-buffer/buffer-filler';
|
|
4
|
+
import type { OutputStreamNode } from '../output-stream-node';
|
|
5
|
+
/**
|
|
6
|
+
* TimedBufferWriteStrategy class
|
|
7
|
+
* Implements the BufferWriteStrategy interface using a timer to manage buffer filling.
|
|
8
|
+
*/
|
|
9
|
+
export declare class TimedBufferWriteStrategy implements BufferWriteStrategy {
|
|
10
|
+
private readonly _writer;
|
|
11
|
+
private readonly _filler;
|
|
12
|
+
private readonly _interval;
|
|
13
|
+
private readonly _isContinuePlayback;
|
|
14
|
+
private _context;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of TimedBufferWriteStrategy.
|
|
17
|
+
* @param config - The configuration for the filler frame buffer.
|
|
18
|
+
* @param filler - The FrameBufferFiller instance.
|
|
19
|
+
*/
|
|
20
|
+
constructor(config: FillerFrameBufferConfig, filler: FrameBufferFiller);
|
|
21
|
+
/**
|
|
22
|
+
* Initializes the strategy.
|
|
23
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
24
|
+
*/
|
|
25
|
+
onInit(): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Starts the strategy.
|
|
28
|
+
* @param node - The OutputStreamNode instance.
|
|
29
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
30
|
+
*/
|
|
31
|
+
onStart(node: OutputStreamNode): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Stops the strategy.
|
|
34
|
+
*/
|
|
35
|
+
onStopped(): void;
|
|
36
|
+
}
|