[READ-ONLY] Mirror of https://github.com/probablykasper/ferrum. Music library app for Mac, Linux and Windows ferrum.kasper.space
electron linux macos music music-library music-player napi windows
0

Configure Feed

Select the types of activity you want to include in your feed.

Revert white flash fix, rename variables

Kasper (Oct 2, 2025, 11:46 PM +0200) de386649 b6394a51

+14 -29
+14 -29
src/lib/visualizer/visualizer.ts
··· 23 23 ) { 24 24 const analyser = audio_context.createAnalyser() 25 25 const filter = audio_context.createBiquadFilter() 26 - const time_buffer = new Float32Array(BIT_DEPTH) 26 + const current_rms_buffer = new Float32Array(BIT_DEPTH) 27 27 const raf = create_singular_request_animation_frame() 28 28 29 29 media_element_source.connect(filter) ··· 38 38 let volume = 0 39 39 40 40 const def = visualizer_settings?.def || [2.5, 0.09] 41 - const volume_buffer: number[] = [] 42 - 43 - // Pre-fill buffer with some baseline values to avoid initial instability 44 - for (let i = 0; i < 60; i++) { 45 - volume_buffer.push(0.1) // Small baseline value 46 - } 41 + const volume_history_buffer: number[] = [] 47 42 48 43 function sample_volume(total_samples: number) { 49 44 let value = 0 50 - const start = Math.max(volume_buffer.length - 1, 0) 51 - const end = Math.max(start - total_samples, 0) 45 + const end = Math.max(volume_history_buffer.length - 1, 0) 46 + const start = Math.max(end - total_samples, 0) 52 47 let min = Infinity 53 - for (let i = start; i >= end; i--) { 54 - value += volume_buffer[i] 55 - if (volume_buffer[i] < min) min = volume_buffer[i] 48 + for (let i = end; i >= start; i--) { 49 + value += volume_history_buffer[i] 50 + if (volume_history_buffer[i] < min) min = volume_history_buffer[i] 56 51 } 57 52 return [value / total_samples, min] 58 53 } 59 54 60 55 function measure_volume(frame_rate: number) { 61 56 const raw_volume = get_raw_volume() 62 - volume_buffer.push(raw_volume) 63 - 64 - // Need minimum samples before doing complex calculations 65 - const min_samples_needed = Math.max(2, (def[1] * 1000) / (1000 / frame_rate)) 66 - if (volume_buffer.length < min_samples_needed) { 67 - return 0.01 // Small default value while buffer builds up 68 - } 57 + volume_history_buffer.push(raw_volume) 69 58 70 59 const [ref, min] = sample_volume((def[0] * 1000) / (1000 / frame_rate)) 71 60 const [sample] = sample_volume((def[1] * 1000) / (1000 / frame_rate)) 72 - 73 - // Avoid division by zero or very small differences 74 - const range = ref - min 75 - if (range < 0.001) { 76 - return 0.01 // Small default when no audio variance 77 - } 78 - 79 61 const scaled = scaleLinear([min, ref], [0, 1])(sample) 80 62 const raw = Number(Math.pow(scaled, 1.5).toFixed(3)) 81 - return isNaN(raw) ? 0.1 : Math.max(0, raw / 2) // Ensure non-negative 63 + if (isNaN(raw)) { 64 + console.log('raw is NaN') 65 + } 66 + return isNaN(raw) ? 1 : raw / 2 82 67 } 83 68 84 69 function get_raw_volume() { 85 - analyser.getFloatTimeDomainData(time_buffer) 86 - return (Meyda.extract('rms', time_buffer) as number) || 0 70 + analyser.getFloatTimeDomainData(current_rms_buffer) 71 + return (Meyda.extract('rms', current_rms_buffer) as number) || 0 87 72 } 88 73 89 74 let destroyed = false