[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.

Avoid bright flash at start

Kasper (Oct 2, 2025, 11:46 PM +0200) 9588da71 050d3c6f

+20 -1
+20 -1
src/lib/visualizer/visualizer.ts
··· 39 39 const def = visualizer_settings?.def || [2.5, 0.09] 40 40 const volumeBuffer: number[] = [] 41 41 42 + // Pre-fill buffer with some baseline values to avoid initial instability 43 + for (let i = 0; i < 60; i++) { 44 + volumeBuffer.push(0.1) // Small baseline value 45 + } 46 + 42 47 function sampleVolume(totalSamples: number) { 43 48 let value = 0 44 49 const start = Math.max(volumeBuffer.length - 1, 0) ··· 54 59 function measure_volume(frameRate: number) { 55 60 const rawVolume = getRawVolume() 56 61 volumeBuffer.push(rawVolume) 62 + 63 + // Need minimum samples before doing complex calculations 64 + const minSamplesNeeded = Math.max(2, (def[1] * 1000) / (1000 / frameRate)) 65 + if (volumeBuffer.length < minSamplesNeeded) { 66 + return 0.01 // Small default value while buffer builds up 67 + } 68 + 57 69 const [ref, min] = sampleVolume((def[0] * 1000) / (1000 / frameRate)) 58 70 const [sample] = sampleVolume((def[1] * 1000) / (1000 / frameRate)) 71 + 72 + // Avoid division by zero or very small differences 73 + const range = ref - min 74 + if (range < 0.001) { 75 + return 0.01 // Small default when no audio variance 76 + } 77 + 59 78 const scaled = scaleLinear([min, ref], [0, 1])(sample) 60 79 const raw = Number(Math.pow(scaled, 1.5).toFixed(3)) 61 - return isNaN(raw) ? 1 : raw / 2 80 + return isNaN(raw) ? 0.1 : Math.max(0, raw / 2) // Ensure non-negative 62 81 } 63 82 64 83 function getRawVolume() {