2121 */
2222
2323/**
24- * Number of bytes per sample (Float32).
24+ * Number of bytes per sample (Float32)
2525 */
2626const BYTES_PER_SAMPLE = 4 ;
2727
2828/**
29- * Number of samples per audio frame (stereo).
29+ * Number of samples per audio frame (stereo)
3030 */
3131const SAMPLES_PER_FRAME = 2 ;
3232
3333/**
34- * Number of bytes per audio frame.
34+ * Number of bytes per audio frame
3535 */
3636const BYTES_PER_FRAME = BYTES_PER_SAMPLE * SAMPLES_PER_FRAME ;
3737
3838/**
39- * Default maximum number of frames for buffer allocation.
39+ * Default maximum number of frames for buffer allocation
4040 */
4141const DEFAULT_MAX_FRAMES = 131072 ;
4242
4343/**
44- * Resizable interleaved sample buffer for audio processing.
45- * Uses ES2024 ArrayBuffer for zero-allocation growth.
44+ * Resizable interleaved sample buffer for audio processing
45+ * Uses ES2024 ArrayBuffer for zero-allocation growth
4646 *
4747 * @remarks
48- * Stores stereo audio samples in a contiguous Float32Array.
49- * Provides methods for efficient buffer management and sample transfer.
48+ * Stores stereo audio samples in a contiguous Float32Array
49+ * Provides methods for efficient buffer management and sample transfer
5050 */
5151export default class FifoSampleBuffer {
5252 /**
53- * Backing ArrayBuffer for sample storage.
53+ * Backing ArrayBuffer for sample storage
5454 */
5555 private _buffer : ArrayBuffer ;
5656
5757 /**
58- * Float32Array view of the buffer.
58+ * Float32Array view of the buffer
5959 */
6060 private _vector : Float32Array ;
6161
6262 /**
63- * Current read position (frame index).
63+ * Current read position (frame index)
6464 */
6565 private _position : number ;
6666
6767 /**
68- * Number of frames currently stored.
68+ * Number of frames currently stored
6969 */
7070 private _frameCount : number ;
7171
7272 /**
73- * Creates a new FifoSampleBuffer.
74- * @param maxFrames Maximum number of frames for buffer allocation.
73+ * Creates a new FifoSampleBuffer
74+ * @param maxFrames Maximum number of frames for buffer allocation
7575 */
7676 constructor ( maxFrames = DEFAULT_MAX_FRAMES ) {
7777 this . _buffer = new ArrayBuffer ( 0 , {
@@ -83,42 +83,42 @@ export default class FifoSampleBuffer {
8383 }
8484
8585 /**
86- * Returns the Float32Array view of the buffer.
86+ * Returns the Float32Array view of the buffer
8787 */
8888 get vector ( ) : Float32Array {
8989 return this . _vector ;
9090 }
9191
9292 /**
93- * Returns the current read position (frame index).
93+ * Returns the current read position (frame index)
9494 */
9595 get position ( ) : number {
9696 return this . _position ;
9797 }
9898
9999 /**
100- * Returns the start sample index for reading.
100+ * Returns the start sample index for reading
101101 */
102102 get startIndex ( ) : number {
103103 return this . _position * 2 ;
104104 }
105105
106106 /**
107- * Returns the number of frames currently stored.
107+ * Returns the number of frames currently stored
108108 */
109109 get frameCount ( ) : number {
110110 return this . _frameCount ;
111111 }
112112
113113 /**
114- * Returns the end sample index for reading.
114+ * Returns the end sample index for reading
115115 */
116116 get endIndex ( ) : number {
117117 return ( this . _position + this . _frameCount ) * 2 ;
118118 }
119119
120120 /**
121- * Clears the buffer and resets position and frame count.
121+ * Clears the buffer and resets position and frame count
122122 */
123123 clear ( ) : void {
124124 this . _vector . fill ( 0 ) ;
@@ -127,18 +127,18 @@ export default class FifoSampleBuffer {
127127 }
128128
129129 /**
130- * Adds empty frames to the buffer.
131- * @param numFrames Number of frames to add.
130+ * Adds empty frames to the buffer
131+ * @param numFrames Number of frames to add
132132 */
133133 put ( numFrames : number ) : void {
134134 this . _frameCount += numFrames ;
135135 }
136136
137137 /**
138- * Adds samples to the buffer from a Float32Array.
139- * @param samples Source samples (interleaved stereo).
140- * @param position Start frame index in source.
141- * @param numFrames Number of frames to copy (default: all available).
138+ * Adds samples to the buffer from a Float32Array
139+ * @param samples Source samples (interleaved stereo)
140+ * @param position Start frame index in source
141+ * @param numFrames Number of frames to copy (default: all available)
142142 */
143143 putSamples ( samples : Float32Array , position = 0 , numFrames = 0 ) : void {
144144 const sourceOffset = position * 2 ;
@@ -159,10 +159,10 @@ export default class FifoSampleBuffer {
159159 }
160160
161161 /**
162- * Adds samples from another FifoSampleBuffer.
163- * @param buffer Source buffer.
164- * @param position Start frame index in source buffer.
165- * @param numFrames Number of frames to copy (default: all available).
162+ * Adds samples from another FifoSampleBuffer
163+ * @param buffer Source buffer
164+ * @param position Start frame index in source buffer
165+ * @param numFrames Number of frames to copy (default: all available)
166166 */
167167 putBuffer ( buffer : FifoSampleBuffer , position = 0 , numFrames = 0 ) : void {
168168 if ( ! ( numFrames >= 0 ) || numFrames === 0 ) {
@@ -172,8 +172,8 @@ export default class FifoSampleBuffer {
172172 }
173173
174174 /**
175- * Advances the read position and reduces frame count.
176- * @param numFrames Number of frames to receive (default: all available).
175+ * Advances the read position and reduces frame count
176+ * @param numFrames Number of frames to receive (default: all available)
177177 */
178178 receive ( numFrames ?: number ) : void {
179179 if (
@@ -188,9 +188,9 @@ export default class FifoSampleBuffer {
188188 }
189189
190190 /**
191- * Copies and receives samples into an output array.
192- * @param output Destination Float32Array.
193- * @param numFrames Number of frames to copy and receive.
191+ * Copies and receives samples into an output array
192+ * @param output Destination Float32Array
193+ * @param numFrames Number of frames to copy and receive
194194 */
195195 receiveSamples ( output : Float32Array , numFrames = 0 ) : void {
196196 const numSamples = numFrames * 2 ;
@@ -200,10 +200,10 @@ export default class FifoSampleBuffer {
200200 }
201201
202202 /**
203- * Extracts samples into an output array without advancing position.
204- * @param output Destination Float32Array.
205- * @param position Start frame index in buffer.
206- * @param numFrames Number of frames to extract.
203+ * Extracts samples into an output array without advancing position
204+ * @param output Destination Float32Array
205+ * @param position Start frame index in buffer
206+ * @param numFrames Number of frames to extract
207207 */
208208 extract ( output : Float32Array , position = 0 , numFrames = 0 ) : void {
209209 const sourceOffset = this . startIndex + position * 2 ;
@@ -212,8 +212,8 @@ export default class FifoSampleBuffer {
212212 }
213213
214214 /**
215- * Ensures the buffer has capacity for at least numFrames.
216- * @param numFrames Minimum number of frames required.
215+ * Ensures the buffer has capacity for at least numFrames
216+ * @param numFrames Minimum number of frames required
217217 */
218218 ensureCapacity ( numFrames = 0 ) : void {
219219 const minLength = Math . floor ( numFrames * SAMPLES_PER_FRAME ) ;
@@ -240,15 +240,15 @@ export default class FifoSampleBuffer {
240240 }
241241
242242 /**
243- * Ensures buffer has capacity for additional frames.
244- * @param numFrames Number of additional frames required.
243+ * Ensures buffer has capacity for additional frames
244+ * @param numFrames Number of additional frames required
245245 */
246246 ensureAdditionalCapacity ( numFrames = 0 ) : void {
247247 this . ensureCapacity ( this . _frameCount + numFrames ) ;
248248 }
249249
250250 /**
251- * Moves all unread samples to the start of the buffer.
251+ * Moves all unread samples to the start of the buffer
252252 */
253253 rewind ( ) : void {
254254 if ( this . _position > 0 ) {
0 commit comments