diff --git a/js/audio-context.js b/js/audio-context.js index c33f4d4..016a6f4 100644 --- a/js/audio-context.js +++ b/js/audio-context.js @@ -312,12 +312,12 @@ class AudioContextManager { try { const AudioContext = window.AudioContext || window.webkitAudioContext; - + // "playback" latency hint maximizes buffer size to prevent audio glitches (stuttering), // which is critical for high-fidelity music listening. // We also attempt to request 192kHz sample rate for high-res audio support. const highResOptions = { sampleRate: 192000, latencyHint: 'playback' }; - + try { this.audioContext = new AudioContext(highResOptions); console.log(`[AudioContext] Created with high-res settings: ${this.audioContext.sampleRate}Hz`); diff --git a/js/visualizer.js b/js/visualizer.js index bbfea7a..f7af63a 100644 --- a/js/visualizer.js +++ b/js/visualizer.js @@ -192,22 +192,22 @@ export class Visualizer { // Bass (dynamic bins based on sample rate) const volume = 10 * Math.max(this.audio.volume, 0.1); - + // Robust bass detection: sum bins up to ~250Hz const binSize = this.audioContext.sampleRate / this.analyser.fftSize; const startBin = 1; // Skip DC offset // Calculate how many bins cover the bass range (up to 250Hz) let numBins = Math.floor(250 / binSize); if (numBins < 1) numBins = 1; // Ensure at least one bin is checked - + let maxVal = 0; - for (let i = 0; i < numBins && (startBin + i) < this.dataArray.length; i++) { + for (let i = 0; i < numBins && startBin + i < this.dataArray.length; i++) { const val = this.dataArray[startBin + i]; if (val > maxVal) maxVal = val; } - + // Normalize: (Max / 255) / Volume - let bass = (maxVal) / 255 / volume; + let bass = maxVal / 255 / volume; const intensity = bass * bass * 10; const stats = this.stats; diff --git a/js/visualizers/lcd.js b/js/visualizers/lcd.js index f0f4dc7..26fc3ec 100644 --- a/js/visualizers/lcd.js +++ b/js/visualizers/lcd.js @@ -288,14 +288,14 @@ export class LCDPreset { // Sample rate and bin size const sampleRate = analyser?.context?.sampleRate || 48000; const binSize = sampleRate / (totalBins * 2); - + // Define frequency range to map const minFreq = 40; // Start at 40Hz const maxFreq = 22000; // End at 22kHz for (let i = 0; i < center; i++) { const p = i / (center - 1); - + // Logarithmic frequency mapping: F = min * (max/min)^p const targetStartFreq = minFreq * Math.pow(maxFreq / minFreq, p); // Calculate next frequency to determine bandwidth of this bar @@ -308,14 +308,14 @@ export class LCDPreset { let sum = 0, count = 0; - + // Sum bins for this column for (let k = startBin; k < endBin && k < totalBins; k++) { sum += dataArray[k]; count++; } let val = count > 0 ? sum / count : 0; - + // Fallback: if range was too narrow (startBin >= endBin or count=0), sample the startBin directly if (count === 0 && startBin < totalBins) { val = dataArray[startBin]; diff --git a/js/visualizers/unknown_pleasures_webgl.js b/js/visualizers/unknown_pleasures_webgl.js index 3bd1ea8..3d73a7b 100644 --- a/js/visualizers/unknown_pleasures_webgl.js +++ b/js/visualizers/unknown_pleasures_webgl.js @@ -615,8 +615,6 @@ export class UnknownPleasuresWebGL { gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 3); } - - // MUST DISABLE BLEND for post-processing passes so we strictly overwrite FBO contents! gl.disable(gl.BLEND);