feat(tracker, gioui): add error message if vuanalyzer detects a NaN

Closes #50
This commit is contained in:
vsariola
2021-04-12 20:05:18 +03:00
parent 68a50247bd
commit ce52aa0ee9
3 changed files with 14 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package tracker
import (
"errors"
"math"
)
@ -28,7 +29,7 @@ type Volume struct {
//
// minVolume is just a hard limit for the vuanalyzer volumes, in decibels, just to
// prevent negative infinities for volumes
func VuAnalyzer(tau float64, attack float64, release float64, minVolume float64, maxVolume float64, bc <-chan []float32, vc chan<- Volume) {
func VuAnalyzer(tau float64, attack float64, release float64, minVolume float64, maxVolume float64, bc <-chan []float32, vc chan<- Volume, ec chan<- error) {
v := Volume{Average: [2]float64{minVolume, minVolume}, Peak: [2]float64{minVolume, minVolume}}
alpha := 1 - math.Exp(-1.0/(tau*44100)) // from https://en.wikipedia.org/wiki/Exponential_smoothing
alphaAttack := 1 - math.Exp(-1.0/(attack*44100))
@ -38,7 +39,11 @@ func VuAnalyzer(tau float64, attack float64, release float64, minVolume float64,
for i := 0; i < len(buffer); i += 2 {
sample2 := float64(buffer[i+j] * buffer[i+j])
if math.IsNaN(sample2) {
sample2 = float64(minVolume)
select {
case ec <- errors.New("NaN detected in master output"):
default:
}
continue
}
dB := 10 * math.Log10(float64(sample2))
if dB < minVolume || math.IsNaN(dB) {