@ain1084/audio-worklet-stream 0.1.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.
Files changed (79) hide show
  1. package/LICENSE +222 -0
  2. package/README.md +243 -0
  3. package/dist/constants.d.ts +12 -0
  4. package/dist/constants.js +15 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/events.d.ts +37 -0
  7. package/dist/events.js +35 -0
  8. package/dist/events.js.map +1 -0
  9. package/dist/frame-buffer/buffer-factory.d.ts +77 -0
  10. package/dist/frame-buffer/buffer-factory.js +52 -0
  11. package/dist/frame-buffer/buffer-factory.js.map +1 -0
  12. package/dist/frame-buffer/buffer-filler.d.ts +13 -0
  13. package/dist/frame-buffer/buffer-filler.js +2 -0
  14. package/dist/frame-buffer/buffer-filler.js.map +1 -0
  15. package/dist/frame-buffer/buffer-reader.d.ts +37 -0
  16. package/dist/frame-buffer/buffer-reader.js +51 -0
  17. package/dist/frame-buffer/buffer-reader.js.map +1 -0
  18. package/dist/frame-buffer/buffer-utils.d.ts +34 -0
  19. package/dist/frame-buffer/buffer-utils.js +34 -0
  20. package/dist/frame-buffer/buffer-utils.js.map +1 -0
  21. package/dist/frame-buffer/buffer-writer.d.ts +37 -0
  22. package/dist/frame-buffer/buffer-writer.js +51 -0
  23. package/dist/frame-buffer/buffer-writer.js.map +1 -0
  24. package/dist/frame-buffer/buffer.d.ts +40 -0
  25. package/dist/frame-buffer/buffer.js +65 -0
  26. package/dist/frame-buffer/buffer.js.map +1 -0
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.js +4 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/output-message.d.ts +42 -0
  31. package/dist/output-message.js +2 -0
  32. package/dist/output-message.js.map +1 -0
  33. package/dist/output-stream-node.d.ts +93 -0
  34. package/dist/output-stream-node.js +166 -0
  35. package/dist/output-stream-node.js.map +1 -0
  36. package/dist/output-stream-processor.d.ts +13 -0
  37. package/dist/output-stream-processor.js +99 -0
  38. package/dist/output-stream-processor.js.map +1 -0
  39. package/dist/stream-node-factory.d.ts +87 -0
  40. package/dist/stream-node-factory.js +113 -0
  41. package/dist/stream-node-factory.js.map +1 -0
  42. package/dist/write-strategy/manual.d.ts +36 -0
  43. package/dist/write-strategy/manual.js +43 -0
  44. package/dist/write-strategy/manual.js.map +1 -0
  45. package/dist/write-strategy/strategy.d.ts +23 -0
  46. package/dist/write-strategy/strategy.js +2 -0
  47. package/dist/write-strategy/strategy.js.map +1 -0
  48. package/dist/write-strategy/timed.d.ts +36 -0
  49. package/dist/write-strategy/timed.js +92 -0
  50. package/dist/write-strategy/timed.js.map +1 -0
  51. package/dist/write-strategy/worker/message.d.ts +54 -0
  52. package/dist/write-strategy/worker/message.js +2 -0
  53. package/dist/write-strategy/worker/message.js.map +1 -0
  54. package/dist/write-strategy/worker/strategy.d.ts +34 -0
  55. package/dist/write-strategy/worker/strategy.js +125 -0
  56. package/dist/write-strategy/worker/strategy.js.map +1 -0
  57. package/dist/write-strategy/worker/worker.d.ts +35 -0
  58. package/dist/write-strategy/worker/worker.js +135 -0
  59. package/dist/write-strategy/worker/worker.js.map +1 -0
  60. package/package.json +54 -0
  61. package/src/constants.ts +18 -0
  62. package/src/events.ts +43 -0
  63. package/src/frame-buffer/buffer-factory.ts +115 -0
  64. package/src/frame-buffer/buffer-filler.ts +14 -0
  65. package/src/frame-buffer/buffer-reader.ts +56 -0
  66. package/src/frame-buffer/buffer-utils.ts +48 -0
  67. package/src/frame-buffer/buffer-writer.ts +56 -0
  68. package/src/frame-buffer/buffer.ts +68 -0
  69. package/src/index.ts +9 -0
  70. package/src/output-message.ts +37 -0
  71. package/src/output-stream-node.ts +197 -0
  72. package/src/output-stream-processor.ts +124 -0
  73. package/src/stream-node-factory.ts +161 -0
  74. package/src/write-strategy/manual.ts +50 -0
  75. package/src/write-strategy/strategy.ts +26 -0
  76. package/src/write-strategy/timed.ts +103 -0
  77. package/src/write-strategy/worker/message.ts +48 -0
  78. package/src/write-strategy/worker/strategy.ts +154 -0
  79. package/src/write-strategy/worker/worker.ts +149 -0
@@ -0,0 +1,166 @@
1
+ import { PROCESSOR_NAME } from './constants';
2
+ import { StopEvent, UnderrunEvent } from './events';
3
+ /**
4
+ * OutputStreamNode class
5
+ * This class extends AudioWorkletNode to handle audio processing.
6
+ * It manages a buffer using a FrameBufferWriter instance and tracks the current frame position.
7
+ */
8
+ export class OutputStreamNode extends AudioWorkletNode {
9
+ _totalWriteFrames;
10
+ _totalReadFrames;
11
+ _strategy;
12
+ _state = 'ready';
13
+ /**
14
+ * Creates an instance of OutputStreamNode.
15
+ * @param baseAudioContext - The audio context to use.
16
+ * @param bufferConfig - The configuration for the buffer.
17
+ * @param strategy - The strategy for writing to the buffer.
18
+ */
19
+ constructor(baseAudioContext, bufferConfig, strategy) {
20
+ const processorOptions = {
21
+ ...bufferConfig,
22
+ totalFrames: bufferConfig.totalReadFrames,
23
+ };
24
+ super(baseAudioContext, PROCESSOR_NAME, {
25
+ outputChannelCount: [bufferConfig.samplesPerFrame],
26
+ processorOptions,
27
+ });
28
+ this._strategy = strategy;
29
+ this._totalWriteFrames = bufferConfig.totalWriteFrames;
30
+ this._totalReadFrames = bufferConfig.totalReadFrames;
31
+ this.port.onmessage = this.handleMessage.bind(this);
32
+ }
33
+ /**
34
+ * Start playback.
35
+ * The node must be connected before starting playback using connect() method.
36
+ * Output samples must be written to the buffer before starting.
37
+ * Playback can only be started once. Once stopped, it cannot be restarted.
38
+ * @returns A boolean indicating whether the playback started successfully.
39
+ */
40
+ start() {
41
+ if (this.numberOfOutputs === 0) {
42
+ throw new Error('Cannot start playback. Node is not connected.');
43
+ }
44
+ switch (this._state) {
45
+ case 'ready':
46
+ this._state = 'started';
47
+ if (!this._strategy.onStart(this)) {
48
+ this.stop(this.totalWriteFrames);
49
+ }
50
+ return true;
51
+ case 'started':
52
+ return false;
53
+ default:
54
+ throw new Error(`Cannot start playback. Current state: ${this._state}`);
55
+ }
56
+ }
57
+ /**
58
+ * Stop the node processing at a given frame position.
59
+ * Returns a Promise that resolves when the node has completely stopped.
60
+ * The node is disconnected once stopping is complete.
61
+ * @param frames - The frame position at which to stop the processing, in frames.
62
+ * If frames is 0 or if the current playback frame position has already passed the specified value,
63
+ * the node will stop immediately.
64
+ * @returns A promise that resolves when the node has stopped.
65
+ */
66
+ stop(frames = BigInt(0)) {
67
+ switch (this._state) {
68
+ case 'started':
69
+ return new Promise((resolve) => {
70
+ this._state = 'stopping';
71
+ const message = { type: 'stop', frames };
72
+ this.port.postMessage(message);
73
+ this.addEventListener(StopEvent.type, () => {
74
+ resolve();
75
+ }, { once: true });
76
+ });
77
+ case 'ready':
78
+ this.handleStopped();
79
+ break;
80
+ default:
81
+ throw new Error(`Cannot stop playback. Current state: ${this._state}`);
82
+ }
83
+ return Promise.resolve();
84
+ }
85
+ /**
86
+ * Handles incoming messages from the audio processor.
87
+ * @param event - The message event from the processor.
88
+ */
89
+ handleMessage(event) {
90
+ switch (event.data.type) {
91
+ case 'stop':
92
+ this.handleStopped();
93
+ this.dispatchEvent(new StopEvent(event.data.frames));
94
+ break;
95
+ case 'underrun':
96
+ this.dispatchEvent(new UnderrunEvent(event.data.frames));
97
+ break;
98
+ default:
99
+ throw new Error(`Unexpected event value: ${event.data}`);
100
+ }
101
+ }
102
+ /**
103
+ * Handles the stopping of the node.
104
+ * Disconnects the node and closes the port.
105
+ */
106
+ handleStopped() {
107
+ this._strategy.onStopped();
108
+ this.disconnect();
109
+ this.port.close();
110
+ this.port.onmessage = null;
111
+ this._state = 'stopped';
112
+ }
113
+ /**
114
+ * Checks if playback has started.
115
+ * @returns A boolean indicating if playback has started.
116
+ */
117
+ get isStart() {
118
+ return this._state === 'started';
119
+ }
120
+ /**
121
+ * Get the current frame position since the start of playback.
122
+ * The position is in frames and increases by 1 for each frame.
123
+ * It represents the total number of frames processed by the AudioWorkletProcessor.
124
+ * - AudioWorkletProcessor has read this total number of frames from the buffer.
125
+ * It closely indicates the playback position in frames.
126
+ * - totalReadFrames will never exceed the number of frames written to the buffer,
127
+ * ensuring it is always less than or equal to totalWriteFrames.
128
+ * - The difference between totalWriteFrames and totalReadFrames represents the delay
129
+ * in samples before playback (excluding processing beyond the AudioNode).
130
+ * @returns The current frame position as a bigint.
131
+ */
132
+ get totalReadFrames() {
133
+ return Atomics.load(this._totalReadFrames, 0);
134
+ }
135
+ /**
136
+ * Get the total number of frames written to the buffer.
137
+ * This reflects the total frames written by the BufferWriteStrategy.
138
+ * Note: The method of writing to the buffer is implemented by the BufferWriteStrategy.
139
+ * The OutputStreamNode itself does not modify this value.
140
+ * @returns The total number of frames written as a bigint.
141
+ */
142
+ get totalWriteFrames() {
143
+ return Atomics.load(this._totalWriteFrames, 0);
144
+ }
145
+ }
146
+ /**
147
+ * OutputStreamNodeFactory class
148
+ * Factory class to create instances of OutputStreamNode.
149
+ */
150
+ export class OutputStreamNodeFactory extends OutputStreamNode {
151
+ /**
152
+ * Creates an instance of OutputStreamNodeFactory.
153
+ * @param audioContext - The audio context to use.
154
+ * @param info - The configuration for the buffer.
155
+ * @param strategy - The strategy for writing to the buffer.
156
+ * @returns A promise that resolves to an instance of OutputStreamNodeFactory.
157
+ */
158
+ static async create(audioContext, info, strategy) {
159
+ const node = new OutputStreamNodeFactory(audioContext, info, strategy);
160
+ if (!(await strategy.onInit(node))) {
161
+ throw new Error('Failed to onPrepare.');
162
+ }
163
+ return node;
164
+ }
165
+ }
166
+ //# sourceMappingURL=output-stream-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-stream-node.js","sourceRoot":"","sources":["../src/output-stream-node.ts"],"names":[],"mappings":"AAEA,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,C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SAAS,EAAE,CAAA;QAC1B,IAAI,CAAC,UAAU,EAAE,CAAA;QACjB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;QACjB,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;IACzB,CAAC;IAED;;;OAGG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAA;IAClC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,IAAW,eAAe;QACxB,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED;;;;;;OAMG;IACH,IAAW,gBAAgB;QACzB,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAA;IAChD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;IAC3D;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,YAA8B,EAAE,IAAuB,EAAE,QAA6B;QAC/G,MAAM,IAAI,GAAG,IAAI,uBAAuB,CAAC,YAAY,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;QACtE,IAAI,CAAC,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
@@ -0,0 +1,13 @@
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
+ }>;
@@ -0,0 +1,99 @@
1
+ import { FrameBufferReader } from './frame-buffer/buffer-reader';
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
+ /**
8
+ * OutputStreamProcessor class
9
+ * This class extends AudioWorkletProcessor to process audio data.
10
+ * It uses a FrameBufferReader instance to read from a shared buffer and manage the audio data.
11
+ */
12
+ class OutputStreamProcessor extends AudioWorkletProcessor {
13
+ _frameReader;
14
+ _shouldStop = false;
15
+ _stopFrames;
16
+ _underrunFrames = 0;
17
+ /**
18
+ * Creates an instance of OutputStreamProcessor.
19
+ * @param options - The options for the processor, including shared buffers.
20
+ */
21
+ constructor(options) {
22
+ super();
23
+ this._frameReader = createFrameBufferReader(options.processorOptions);
24
+ this.port.onmessage = this.handleMessage.bind(this);
25
+ }
26
+ /**
27
+ * Handles incoming messages from the audio node.
28
+ * @param event - The message event from the audio node.
29
+ */
30
+ handleMessage(event) {
31
+ if (event.data.type !== 'stop') {
32
+ throw new Error(`Unexpected message type: ${event.data.type}`);
33
+ }
34
+ const frames = event.data.frames;
35
+ if (frames <= 0) {
36
+ this._shouldStop = true;
37
+ }
38
+ else {
39
+ this._stopFrames = frames;
40
+ }
41
+ }
42
+ /**
43
+ * Updates the underrun frame count.
44
+ * If underrunFrames is provided and not zero, it adds to the current underrun frame count.
45
+ * If underrunFrames is 0, it indicates that the underrun state has been resolved,
46
+ * and the total underrun frame count is sent to the main thread before being reset.
47
+ * @param underrunFrames - The number of underrun frames to add (default is 0).
48
+ */
49
+ updateUnderrun(underrunFrames = 0) {
50
+ if (underrunFrames !== 0) {
51
+ this._underrunFrames += underrunFrames;
52
+ return;
53
+ }
54
+ if (this._underrunFrames === 0) {
55
+ return;
56
+ }
57
+ this.port.postMessage({ type: 'underrun', frames: this._underrunFrames });
58
+ this._underrunFrames = 0;
59
+ }
60
+ /**
61
+ * Checks the stop condition.
62
+ * @param totalFrames - The total number of frames processed so far.
63
+ */
64
+ checkStopCondition(totalFrames) {
65
+ if (this._stopFrames !== undefined && totalFrames >= this._stopFrames) {
66
+ this._shouldStop = true;
67
+ }
68
+ }
69
+ /**
70
+ * Processes the audio data.
71
+ * @param _inputs - The input audio data.
72
+ * @param outputs - The output audio data.
73
+ * @returns A boolean indicating whether to continue processing.
74
+ */
75
+ process(_inputs, outputs) {
76
+ const output = outputs[0];
77
+ const readFrames = this._frameReader.read((frame, offset) => {
78
+ const frames = Math.min(frame.frames, output[0].length - offset);
79
+ frame.buffer.convertToOutput(frame.index, frames, output, offset);
80
+ return frames;
81
+ });
82
+ const totalFrames = this._frameReader.totalFrames;
83
+ this.checkStopCondition(totalFrames);
84
+ if (this._shouldStop) {
85
+ this.updateUnderrun();
86
+ this.port.postMessage({ type: 'stop', frames: totalFrames });
87
+ this.port.close();
88
+ return false;
89
+ }
90
+ const underrunFrames = output[0].length - readFrames;
91
+ // It seems process may be called before connect?
92
+ if (totalFrames !== BigInt(0)) {
93
+ this.updateUnderrun(underrunFrames);
94
+ }
95
+ return true;
96
+ }
97
+ }
98
+ registerProcessor(PROCESSOR_NAME, OutputStreamProcessor);
99
+ //# sourceMappingURL=output-stream-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-stream-processor.js","sourceRoot":"","sources":["../src/output-stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAgBnD,MAAM,uBAAuB,GAAG,CAAC,OAAqC,EAAE,EAAE;IACxE,O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,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"}
@@ -0,0 +1,87 @@
1
+ import type { OutputStreamNode } from './output-stream-node';
2
+ import type { FrameBufferFiller } from './frame-buffer/buffer-filler';
3
+ import { FrameBufferWriter } from './frame-buffer/buffer-writer';
4
+ /**
5
+ * Parameters for creating a manual buffer node.
6
+ */
7
+ export type ManualBufferNodeParams = Readonly<{
8
+ /** The number of audio channels. */
9
+ channelCount: number;
10
+ /** The size of the frame buffer in frames. */
11
+ frameBufferSize: number;
12
+ }>;
13
+ /**
14
+ * Parameters for creating a timed buffer node.
15
+ */
16
+ export type TimedBufferNodeParams = Readonly<{
17
+ /** The number of audio channels. */
18
+ channelCount: number;
19
+ /** Optional. The number of chunks in the frame buffer. */
20
+ frameBufferChunks?: number;
21
+ /** Optional. The interval in milliseconds for filling the buffer. */
22
+ fillInterval?: number;
23
+ /** Optional. The sample rate of the audio context. */
24
+ sampleRate?: number;
25
+ }>;
26
+ /**
27
+ * Parameters for creating a worker buffer node.
28
+ */
29
+ export type WorkerBufferNodeParams<T> = TimedBufferNodeParams & Readonly<{
30
+ /** Parameters specific to the filler used in the worker. */
31
+ fillerParams: T;
32
+ }>;
33
+ /**
34
+ * StreamNodeFactory class
35
+ * Factory class to create instances of OutputStreamNode with specific BufferWriteStrategy.
36
+ * This class provides methods to create different types of OutputStreamNodes,
37
+ * such as those using manual, timed, or worker-based buffer writing strategies.
38
+ */
39
+ export declare class StreamNodeFactory {
40
+ private _audioContext;
41
+ private readonly _outputStreamNodeFactory;
42
+ /**
43
+ * Constructor for StreamNodeFactory.
44
+ * @param context - The AudioContext to use.
45
+ * @param outputStreamNodeFactory - The factory for creating OutputStreamNode instances.
46
+ */
47
+ private constructor();
48
+ /**
49
+ * Create an instance of StreamNodeFactory.
50
+ * This method loads necessary modules and creates node creators.
51
+ * @param context - The AudioContext to use.
52
+ * @returns A promise that resolves to an instance of StreamNodeFactory.
53
+ * @throws Error - If module loading fails.
54
+ */
55
+ static create(context: AudioContext): Promise<StreamNodeFactory>;
56
+ /**
57
+ * Creates an OutputStreamNode with manual buffer writing strategy.
58
+ * @param params - The parameters for manual buffer node creation.
59
+ * @returns A promise that resolves to an OutputStreamNode and FrameBufferWriter instance.
60
+ */
61
+ createManualBufferNode(params: ManualBufferNodeParams): Promise<[OutputStreamNode, FrameBufferWriter]>;
62
+ /**
63
+ * Creates an OutputStreamNode with timed buffer writing strategy.
64
+ * @param frameFiller - The FrameBufferFiller instance.
65
+ * @param params - The parameters for timed buffer node creation.
66
+ * @returns A promise that resolves to an OutputStreamNode instance.
67
+ */
68
+ createTimedBufferNode(frameFiller: FrameBufferFiller, params: TimedBufferNodeParams): Promise<OutputStreamNode>;
69
+ /**
70
+ * Creates an OutputStreamNode with worker buffer writing strategy.
71
+ * @param worker - The worker instance.
72
+ * @param params - The parameters for worker buffer node creation.
73
+ * @returns A promise that resolves to an OutputStreamNode instance.
74
+ */
75
+ createWorkerBufferNode<FillerParams>(worker: new () => Worker, params: WorkerBufferNodeParams<FillerParams>): Promise<OutputStreamNode>;
76
+ /**
77
+ * Validates the parameters for timed buffer node creation.
78
+ * @param params - The parameters to validate.
79
+ * @throws Error - If validation fails.
80
+ */
81
+ private static validateTimedBufferNodeParams;
82
+ /**
83
+ * Get the AudioContext associated with this factory.
84
+ * @returns The AudioContext instance.
85
+ */
86
+ get audioContext(): BaseAudioContext;
87
+ }
@@ -0,0 +1,113 @@
1
+ import processor from './output-stream-processor?worker&url';
2
+ import { ManualBufferWriteStrategy } from './write-strategy/manual';
3
+ import { FrameBufferFactory } from './frame-buffer/buffer-factory';
4
+ import { TimedBufferWriteStrategy } from './write-strategy/timed';
5
+ import { WorkerBufferWriteStrategy } from './write-strategy/worker/strategy';
6
+ /**
7
+ * StreamNodeFactory class
8
+ * Factory class to create instances of OutputStreamNode with specific BufferWriteStrategy.
9
+ * This class provides methods to create different types of OutputStreamNodes,
10
+ * such as those using manual, timed, or worker-based buffer writing strategies.
11
+ */
12
+ export class StreamNodeFactory {
13
+ _audioContext;
14
+ _outputStreamNodeFactory;
15
+ /**
16
+ * Constructor for StreamNodeFactory.
17
+ * @param context - The AudioContext to use.
18
+ * @param outputStreamNodeFactory - The factory for creating OutputStreamNode instances.
19
+ */
20
+ constructor(context, outputStreamNodeFactory) {
21
+ this._audioContext = context;
22
+ this._outputStreamNodeFactory = outputStreamNodeFactory;
23
+ }
24
+ /**
25
+ * Create an instance of StreamNodeFactory.
26
+ * This method loads necessary modules and creates node creators.
27
+ * @param context - The AudioContext to use.
28
+ * @returns A promise that resolves to an instance of StreamNodeFactory.
29
+ * @throws Error - If module loading fails.
30
+ */
31
+ static async create(context) {
32
+ try {
33
+ const loadResults = await Promise.all([
34
+ context.audioWorklet.addModule(processor),
35
+ import('./output-stream-node'),
36
+ ]);
37
+ return new StreamNodeFactory(context, loadResults[1].OutputStreamNodeFactory);
38
+ }
39
+ catch (error) {
40
+ throw new Error('Failed to load modules: ' + error);
41
+ }
42
+ }
43
+ /**
44
+ * Creates an OutputStreamNode with manual buffer writing strategy.
45
+ * @param params - The parameters for manual buffer node creation.
46
+ * @returns A promise that resolves to an OutputStreamNode and FrameBufferWriter instance.
47
+ */
48
+ async createManualBufferNode(params) {
49
+ if (params.channelCount <= 0 || !Number.isInteger(params.channelCount)) {
50
+ throw new Error('Invalid channelCount: must be a positive integer.');
51
+ }
52
+ if (params.frameBufferSize <= 0 || !Number.isInteger(params.frameBufferSize)) {
53
+ throw new Error('Invalid frameBufferSize: must be a positive integer.');
54
+ }
55
+ const bufferConfig = FrameBufferFactory.createFrameBufferConfig({ ...params });
56
+ const strategy = new ManualBufferWriteStrategy(bufferConfig);
57
+ return [await this._outputStreamNodeFactory.create(this.audioContext, bufferConfig, strategy), strategy.writer];
58
+ }
59
+ /**
60
+ * Creates an OutputStreamNode with timed buffer writing strategy.
61
+ * @param frameFiller - The FrameBufferFiller instance.
62
+ * @param params - The parameters for timed buffer node creation.
63
+ * @returns A promise that resolves to an OutputStreamNode instance.
64
+ */
65
+ async createTimedBufferNode(frameFiller, params) {
66
+ StreamNodeFactory.validateTimedBufferNodeParams(params);
67
+ if (typeof frameFiller !== 'object' || frameFiller === null) {
68
+ throw new Error('Invalid frameFiller: must be an object.');
69
+ }
70
+ const config = FrameBufferFactory.createFillerFrameBufferConfig(this._audioContext.sampleRate, { ...params });
71
+ const strategy = new TimedBufferWriteStrategy(config, frameFiller);
72
+ return this._outputStreamNodeFactory.create(this.audioContext, config, strategy);
73
+ }
74
+ /**
75
+ * Creates an OutputStreamNode with worker buffer writing strategy.
76
+ * @param worker - The worker instance.
77
+ * @param params - The parameters for worker buffer node creation.
78
+ * @returns A promise that resolves to an OutputStreamNode instance.
79
+ */
80
+ async createWorkerBufferNode(worker, params) {
81
+ StreamNodeFactory.validateTimedBufferNodeParams(params);
82
+ const config = FrameBufferFactory.createFillerFrameBufferConfig(this._audioContext.sampleRate, { ...params });
83
+ const strategy = new WorkerBufferWriteStrategy(config, worker, params.fillerParams);
84
+ return this._outputStreamNodeFactory.create(this._audioContext, config, strategy);
85
+ }
86
+ /**
87
+ * Validates the parameters for timed buffer node creation.
88
+ * @param params - The parameters to validate.
89
+ * @throws Error - If validation fails.
90
+ */
91
+ static validateTimedBufferNodeParams(params) {
92
+ // Check if 'channelCount' is a positive integer
93
+ if (!Number.isInteger(params.channelCount) || params.channelCount <= 0) {
94
+ throw new Error('Invalid channelCount: must be a positive integer.');
95
+ }
96
+ // Check if 'fillInterval' is a positive number if provided
97
+ if (params.fillInterval !== undefined && (typeof params.fillInterval !== 'number' || params.fillInterval <= 0)) {
98
+ throw new Error('Invalid fillInterval: must be a positive number.');
99
+ }
100
+ // Check if 'frameBufferChunks' is a positive integer if provided
101
+ if (params.frameBufferChunks !== undefined && (!Number.isInteger(params.frameBufferChunks) || params.frameBufferChunks <= 0)) {
102
+ throw new Error('Invalid frameBufferChunks: must be a positive integer.');
103
+ }
104
+ }
105
+ /**
106
+ * Get the AudioContext associated with this factory.
107
+ * @returns The AudioContext instance.
108
+ */
109
+ get audioContext() {
110
+ return this._audioContext;
111
+ }
112
+ }
113
+ //# sourceMappingURL=stream-node-factory.js.map
@@ -0,0 +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,yBAAyB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAElE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AAGjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAkC5E;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACpB,aAAa,CAAc;IAClB,wBAAwB,CAAgC;IAEzE;;;;OAIG;IACH,YAAoB,OAAqB,EAAE,uBAAuD;QAChG,IAAI,CAAC,aAAa,GAAG,OAAO,CAAA;QAC5B,IAAI,CAAC,wBAAwB,GAAG,uBAAuB,CAAA;IACzD,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAqB;QAC9C,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACpC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC;gBACzC,MAAM,CAAC,sBAAsB,CAAC;aAC/B,CAAC,CAAA;YACF,OAAO,IAAI,iBAAiB,CAAC,OAAO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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;;;OAGG;IACH,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ import { BufferWriteStrategy } from './strategy';
2
+ import { FrameBufferConfig } from '../frame-buffer/buffer-factory';
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 { createFrameBufferWriter } from '../frame-buffer/buffer-factory';
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 = createFrameBufferWriter(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.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manual.js","sourceRoot":"","sources":["../../src/write-strategy/manual.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAqB,MAAM,gCAAgC,CAAA;AAG3F;;;IAGI;AACJ,MAAM,OAAO,yBAAyB;IACnB,OAAO,CAAmB;IAE3C;;;OAGG;IACH,YAAY,MAAyB;QACnC,IAAI,CAAC,OAAO,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAA;IAChD,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,23 @@
1
+ import type { OutputStreamNode } from '../output-stream-node';
2
+ /**
3
+ * BufferWriteStrategy interface
4
+ * Defines the methods for buffer writing strategies.
5
+ */
6
+ export interface BufferWriteStrategy {
7
+ /**
8
+ * Initializes the strategy.
9
+ * @param node - The OutputStreamNode instance.
10
+ * @returns A promise that resolves to true when initialization is complete.
11
+ */
12
+ onInit(node: OutputStreamNode): Promise<boolean>;
13
+ /**
14
+ * Starts the strategy.
15
+ * @param node - The OutputStreamNode instance.
16
+ * @returns A boolean indicating whether the strategy started successfully.
17
+ */
18
+ onStart(node: OutputStreamNode): boolean;
19
+ /**
20
+ * Stops the strategy.
21
+ */
22
+ onStopped(): void;
23
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/write-strategy/strategy.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ import { BufferWriteStrategy } from './strategy';
2
+ import { FillerFrameBufferConfig } from '../frame-buffer/buffer-factory';
3
+ import { FrameBufferFiller } from '../frame-buffer/buffer-filler';
4
+ import { 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
+ }