@@ -14,11 +14,12 @@ import type { Track } from './track.js';
1414export interface AudioStreamOptions {
1515 noiseCancellation ?: NoiseCancellationOptions | FrameProcessor < AudioFrame > ;
1616 /**
17- * If true and `noiseCancellation` is a {@link FrameProcessor}, leaves the
18- * processor open when the stream closes so the same processor can be reused
19- * with another {@link AudioStream}. Defaults to `false`.
17+ * When the audio stream closes, whether to run the {@link FrameProcessor}'s
18+ * `close()` method. If `false`, the processor is left open so it can be
19+ * reused with another {@link AudioStream}. Only relevant when
20+ * `noiseCancellation` is a {@link FrameProcessor}. Defaults to `true`.
2021 */
21- noiseCancellationLeaveOpen ?: boolean ;
22+ autoCloseNoiseCancellation ?: boolean ;
2223 sampleRate ?: number ;
2324 numChannels ?: number ;
2425 frameSizeMs ?: number ;
@@ -38,7 +39,7 @@ export class AudioStreamSource implements UnderlyingSource<AudioFrame> {
3839 private numChannels : number ;
3940 private legacyNcOptions ?: NoiseCancellationOptions ;
4041 private frameProcessor : FrameProcessor < AudioFrame > | null = null ;
41- private leaveProcessorOpen = false ;
42+ private autoCloseProcessor = true ;
4243 private frameSizeMs ?: number ;
4344 private track : Track ;
4445
@@ -53,7 +54,7 @@ export class AudioStreamSource implements UnderlyingSource<AudioFrame> {
5354 this . numChannels = sampleRateOrOptions . numChannels ?? 1 ;
5455 if ( isFrameProcessor ( sampleRateOrOptions . noiseCancellation ) ) {
5556 this . frameProcessor = sampleRateOrOptions . noiseCancellation ;
56- this . leaveProcessorOpen = sampleRateOrOptions . noiseCancellationLeaveOpen ?? false ;
57+ this . autoCloseProcessor = sampleRateOrOptions . autoCloseNoiseCancellation ?? true ;
5758 } else {
5859 this . legacyNcOptions = sampleRateOrOptions . noiseCancellation ;
5960 }
@@ -131,7 +132,7 @@ export class AudioStreamSource implements UnderlyingSource<AudioFrame> {
131132 this . disposed = true ;
132133 this . track . unregisterAudioStream ( this ) ;
133134 this . ffiHandle . dispose ( ) ;
134- if ( this . frameProcessor && ! this . leaveProcessorOpen ) {
135+ if ( this . frameProcessor && this . autoCloseProcessor ) {
135136 this . frameProcessor . close ( ) ;
136137 }
137138 }
@@ -151,7 +152,7 @@ export class AudioStreamSource implements UnderlyingSource<AudioFrame> {
151152 this . ffiHandle . dispose ( ) ;
152153 // Also close the frame processor on cancel for symmetry with the EOS path,
153154 // so resources are released regardless of how the stream ends.
154- if ( this . frameProcessor && ! this . leaveProcessorOpen ) {
155+ if ( this . frameProcessor && this . autoCloseProcessor ) {
155156 this . frameProcessor . close ( ) ;
156157 }
157158 }
0 commit comments