chore: remove debug console.log calls from audio TS interop

This commit is contained in:
daniel-c-harvey
2026-06-04 18:40:45 -04:00
parent db8a44fc79
commit 034e9d5633
6 changed files with 0 additions and 47 deletions
@@ -31,8 +31,6 @@ export class AudioContextManager {
const analyserNode = this.spectrumAnalyzer.initialize(this.audioContext);
this.gainNode.connect(analyserNode);
analyserNode.connect(this.audioContext.destination);
console.log(`AudioContext initialized: sampleRate=${this.audioContext.sampleRate}Hz, state=${this.audioContext.state}`);
}
async ensureReady(): Promise<void> {
@@ -40,9 +38,7 @@ export class AudioContextManager {
throw new Error('AudioContext not initialized');
}
if (this.audioContext.state === 'suspended') {
console.log('🔊 Resuming AudioContext');
await this.audioContext.resume();
console.log(`✅ AudioContext resumed: state=${this.audioContext.state}`);
}
}
@@ -55,7 +51,6 @@ export class AudioContextManager {
return; // Already correct sample rate
}
console.log(`🔄 Recreating AudioContext: ${this.audioContext.sampleRate}Hz -> ${sampleRate}Hz`);
await this.audioContext.close();
await this.initialize(sampleRate);
}
@@ -100,7 +100,6 @@ export class AudioPlayer {
// Initialize new stream
this.isStreamingMode = true;
this.streamDecoder.initialize(totalStreamLength);
console.log(`Streaming initialized: ${totalStreamLength} bytes expected`);
return { success: true };
} catch (error) {
return { success: false, error: (error as Error).message };
@@ -126,7 +125,6 @@ export class AudioPlayer {
}
}
this.streamingCompleted = true;
console.log('Stream marked complete by C# signal');
return { success: true, bufferCount: this.scheduler.getBufferCount() };
} catch (error) {
return { success: false, error: (error as Error).message };
@@ -157,7 +155,6 @@ export class AudioPlayer {
// Check if streaming is complete
if (this.streamDecoder.isComplete) {
this.streamingCompleted = true;
console.log('Stream complete');
}
const canStart = this.streamDecoder.headerParsed &&
@@ -181,8 +178,6 @@ export class AudioPlayer {
}
try {
console.log('\n=== Starting streaming playback ===');
// A backgrounded tab leaves AudioContext suspended. createBufferSource/start
// against a suspended context produces no audio without throwing — the same
// failure mode that was fixed for play() (resume path). Awaiting ensureReady()
@@ -198,7 +193,6 @@ export class AudioPlayer {
this.scheduler.playFromPosition(0);
this.startProgressTracking();
console.log('✅ Streaming playback started');
return { success: true };
} catch (error) {
return { success: false, error: (error as Error).message };
@@ -218,7 +212,6 @@ export class AudioPlayer {
// Don't restart if already playing
if (this.isPlaying) {
console.log('Already playing, ignoring play()');
return { success: true };
}
@@ -236,7 +229,6 @@ export class AudioPlayer {
this.scheduler.playFromPosition(this.pausePosition);
this.startProgressTracking();
console.log(`▶️ Resumed from ${this.pausePosition.toFixed(3)}s`);
return { success: true };
} catch (error) {
return { success: false, error: (error as Error).message };
@@ -254,7 +246,6 @@ export class AudioPlayer {
this.isPaused = true;
this.stopProgressTracking();
console.log(`⏸️ Paused at ${this.pausePosition.toFixed(3)}s`);
return { success: true };
} catch (error) {
return { success: false, error: (error as Error).message };
@@ -268,7 +259,6 @@ export class AudioPlayer {
this.resetState();
this.stopProgressTracking();
console.log('⏹️ Stopped');
return { success: true };
} catch (error) {
return { success: false, error: (error as Error).message };
@@ -312,7 +302,6 @@ export class AudioPlayer {
this.scheduler.playFromPosition(Math.max(0, bufferRelativePosition));
}
console.log(`🔍 Seeked within buffer to ${position.toFixed(3)}s (buffer-relative: ${bufferRelativePosition.toFixed(3)}s)`);
return { success: true };
} catch (error) {
return { success: false, error: (error as Error).message };
@@ -331,8 +320,6 @@ export class AudioPlayer {
return { success: false, error: 'Cannot calculate byte offset' };
}
console.log(`🔍 Seek beyond buffer to ${position.toFixed(3)}s requires byte offset ${byteOffset}`);
// Signal that C# needs to request new stream from offset
return {
success: true,
@@ -364,9 +351,6 @@ export class AudioPlayer {
*/
reinitializeFromOffset(totalStreamLength: number, seekPosition: number): AudioResult {
try {
console.log(`\n=== Reinitializing for offset stream ===`);
console.log(`Seek position: ${seekPosition.toFixed(3)}s, Stream length: ${totalStreamLength}`);
// Stop current playback
this.stopProgressTracking();
const wasPlaying = this.isPlaying;
@@ -384,7 +368,6 @@ export class AudioPlayer {
this.streamingStarted = false; // Will restart when new buffers arrive
this.streamingCompleted = false;
console.log(`✅ Reinitialized for offset, was playing: ${wasPlaying}`);
return { success: true };
} catch (error) {
return { success: false, error: (error as Error).message };
@@ -43,7 +43,6 @@ export class PlaybackScheduler {
*/
addBuffer(buffer: AudioBuffer): void {
this.buffers.push(buffer);
console.log(`📦 Buffer[${this.buffers.length - 1}] added: ${buffer.duration.toFixed(3)}s (total: ${this.getTotalDuration().toFixed(3)}s)`);
}
/**
@@ -80,7 +79,6 @@ export class PlaybackScheduler {
*/
setPlaybackOffset(offset: number): void {
this.playbackOffset = offset;
console.log(`📍 Playback offset set to ${offset.toFixed(3)}s`);
}
/**
@@ -117,7 +115,6 @@ export class PlaybackScheduler {
// returned silently, leaving the player stuck "playing" with no source
// scheduled — a pause near the end followed by play never recovered.
// Treat this as end-of-track so listeners (UI / end callback) fire.
console.log('Position at/beyond available buffers — ending playback');
this.isActive_ = false;
this.playbackAnchorTime = 0;
this.playbackAnchorPosition = 0;
@@ -125,8 +122,6 @@ export class PlaybackScheduler {
return;
}
console.log(`▶️ Playing from ${position.toFixed(3)}s: buffer[${startBufferIndex}] offset=${offsetInBuffer.toFixed(3)}s`);
// Set timing anchors
this.playbackAnchorPosition = position;
this.playbackAnchorTime = this.contextManager.currentTime;
@@ -192,8 +187,6 @@ export class PlaybackScheduler {
// Schedule the source
source.start(scheduleTime, offset);
console.log(`🎵 Scheduled buffer[${i}]: ${scheduleTime.toFixed(3)}s -> ${endTime.toFixed(3)}s`);
// Update for next buffer
this.nextScheduleTime = endTime;
this.nextBufferIndex = i + 1;
@@ -201,7 +194,6 @@ export class PlaybackScheduler {
// Check if we have enough lookahead
const lookahead = this.nextScheduleTime - this.contextManager.currentTime;
if (lookahead > lookaheadTarget) {
console.log(`📋 Lookahead: ${(lookahead * 1000).toFixed(0)}ms buffered`);
break;
}
}
@@ -229,7 +221,6 @@ export class PlaybackScheduler {
// Check if all playback has finished
if (this.scheduledSources.length === 0 && this.nextBufferIndex >= this.buffers.length) {
console.log('✓ Playback complete');
this.isActive_ = false;
this.playbackAnchorTime = 0;
this.playbackAnchorPosition = 0;
@@ -247,7 +238,6 @@ export class PlaybackScheduler {
this.playbackAnchorPosition = position;
this.playbackAnchorTime = 0;
this.nextScheduleTime = 0;
console.log(`⏸️ Paused at ${position.toFixed(3)}s`);
return position;
}
@@ -275,7 +265,6 @@ export class PlaybackScheduler {
this.playbackAnchorTime = 0;
this.nextBufferIndex = 0;
this.nextScheduleTime = 0;
console.log('⏮️ Reset to start');
}
/**
@@ -290,7 +279,6 @@ export class PlaybackScheduler {
this.nextBufferIndex = 0;
this.nextScheduleTime = 0;
this.playbackOffset = 0;
console.log('🗑️ Scheduler cleared');
}
/**
@@ -305,7 +293,6 @@ export class PlaybackScheduler {
this.nextBufferIndex = 0;
this.nextScheduleTime = 0;
// Note: playbackOffset is NOT reset - it will be set by the caller
console.log('🗑️ Scheduler cleared for seek (offset preserved)');
}
/**
@@ -36,7 +36,6 @@ export class SpectrumAnalyzer {
this.analyser.smoothingTimeConstant = 0.8;
this.dataArray = new Float32Array(this.analyser.frequencyBinCount);
console.log(`SpectrumAnalyzer initialized: fftSize=${this.fftSize}, bins=${this.analyser.frequencyBinCount}`);
return this.analyser;
}
@@ -84,7 +84,6 @@ export class StreamDecoder {
this.headerBytesReceived = 0;
this.headerSearchChunks = [];
this.headerError = null;
console.log(`StreamDecoder initialized: expecting ${totalStreamLength} bytes`);
}
/**
@@ -149,13 +148,10 @@ export class StreamDecoder {
// without ever producing a valid header, the final processChunk will
// mark streamComplete and the player will report no audio decoded;
// that is the correct failure mode, since there is no audio to play.
console.log(`Header not yet parsable: ${this.headerBytesReceived} bytes accumulated`);
return;
}
this.wavHeader = header;
console.log(`WAV format: ${header.bitsPerSample}-bit, ${header.channels}ch, ${header.sampleRate}Hz`);
console.log(`Header size: ${header.headerSize}, byteRate: ${header.byteRate}`);
// Recreate AudioContext with correct sample rate if needed
if (this.contextManager.sampleRate !== header.sampleRate) {
@@ -174,7 +170,6 @@ export class StreamDecoder {
if (audioData.length > 0) {
this.addRawData(audioData);
}
console.log(`Extracted ${audioData.length} bytes of audio data from header buffer`);
// Header-search buffer no longer needed.
this.headerSearchChunks = [];
@@ -233,8 +228,6 @@ export class StreamDecoder {
if (alignedSize <= 0) return null;
const segmentOffset = this.processedBytes;
console.log(`\n--- Decoding segment ---`);
console.log(`Available: ${availableBytes} bytes, aligned size: ${alignedSize} bytes`);
const rawSegment = this.extractAlignedData(alignedSize);
const wavFile = this.createWavFile(rawSegment);
@@ -244,7 +237,6 @@ export class StreamDecoder {
// Advance only after a successful decode so a thrown timeout/decode
// failure does not silently drop the segment.
this.processedBytes += alignedSize;
console.log(`✓ Decoded: ${buffer.duration.toFixed(3)}s, ${buffer.numberOfChannels}ch`);
return { buffer, duration: buffer.duration };
} catch (error) {
// Re-throw typed errors so the outer drain loop in processChunk /
@@ -471,6 +463,5 @@ export class StreamDecoder {
this.headerError = null;
// wavHeader will be reparsed from the new stream (server sends fresh header)
this.wavHeader = null;
console.log(`StreamDecoder reinitialized for offset: expecting ${totalStreamLength} bytes`);
}
}
-2
View File
@@ -75,13 +75,11 @@ class WavUtils {
if (blockAlign !== channels * (bitsPerSample / 8)) return null;
foundFmt = true;
console.log(`Found fmt chunk: ${bitsPerSample}-bit, ${channels}ch, ${sampleRate}Hz, format=${audioFormat}`);
}
else if (chunkId === 'data') {
dataSize = chunkSize;
headerSize = chunkOffset + 8; // Audio data starts after 'data' + size (8 bytes)
foundData = true;
console.log(`Found data chunk at offset ${chunkOffset}, headerSize=${headerSize}, dataSize=${dataSize}`);
}
// Move to next chunk with proper alignment (chunks are word-aligned)