mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(tracker, gioui): add error message if vuanalyzer detects a NaN
Closes #50
This commit is contained in:
parent
68a50247bd
commit
ce52aa0ee9
@ -3,6 +3,7 @@ package gioui
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gioui.org/app"
|
||||
"gioui.org/io/clipboard"
|
||||
@ -29,6 +30,9 @@ func (t *Tracker) Run(w *app.Window) error {
|
||||
case v := <-t.volumeChan:
|
||||
t.lastVolume = v
|
||||
w.Invalidate()
|
||||
case e := <-t.errorChannel:
|
||||
t.Alert.Update(e.Error(), Error, time.Second*5)
|
||||
w.Invalidate()
|
||||
case e := <-w.Events():
|
||||
switch e := e.(type) {
|
||||
case system.DestroyEvent:
|
||||
|
@ -69,6 +69,7 @@ type Tracker struct {
|
||||
player *tracker.Player
|
||||
refresh chan struct{}
|
||||
playerCloser chan struct{}
|
||||
errorChannel chan error
|
||||
audioContext sointu.AudioContext
|
||||
|
||||
*tracker.Model
|
||||
@ -152,10 +153,11 @@ func New(audioContext sointu.AudioContext, synthService sointu.SynthService, syn
|
||||
PatternOrderList: &layout.List{Axis: layout.Vertical},
|
||||
PatternOrderScrollBar: &ScrollBar{Axis: layout.Vertical},
|
||||
ConfirmInstrDelete: new(Dialog),
|
||||
errorChannel: make(chan error, 32),
|
||||
}
|
||||
t.Model = tracker.NewModel()
|
||||
vuBufferObserver := make(chan []float32)
|
||||
go tracker.VuAnalyzer(0.3, 1e-4, 1, -100, 20, vuBufferObserver, t.volumeChan)
|
||||
go tracker.VuAnalyzer(0.3, 1e-4, 1, -100, 20, vuBufferObserver, t.volumeChan, t.errorChannel)
|
||||
t.Theme.Palette.Fg = primaryColor
|
||||
t.Theme.Palette.ContrastFg = black
|
||||
t.SetEditMode(tracker.EditTracks)
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user