Merge branch 'remove-audio-debug-logs' into dev

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