diff options
author | Christian Pointner <equinox@spreadspace.org> | 2019-02-10 20:25:59 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2019-02-10 20:25:59 +0100 |
commit | 788f06e1b6ce5455f10b8f273c13c4c6b20e95f9 (patch) | |
tree | 4df8c2ebfced2846e471af68184dda2b9fc23bcc /cmd/dolmetschctld/statemachine.go | |
parent | use mute state of voice channel to disable automatic switching for this language (diff) |
implement fading (needs improvinggit diff)
Diffstat (limited to 'cmd/dolmetschctld/statemachine.go')
-rw-r--r-- | cmd/dolmetschctld/statemachine.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/cmd/dolmetschctld/statemachine.go b/cmd/dolmetschctld/statemachine.go index 7e37af1..1fe4023 100644 --- a/cmd/dolmetschctld/statemachine.go +++ b/cmd/dolmetschctld/statemachine.go @@ -25,6 +25,7 @@ package main import ( "fmt" "log" + "time" "spreadspace.org/dolmetschctl/pkg/mixer" ) @@ -156,6 +157,18 @@ func (sm *StateMachine) selectLang(l Language) error { return nil } +func calcNextLevel(target, current mixer.FaderLevel) mixer.FaderLevel { + next := target + if current != mixer.FaderLevelUnknown { + if next > current { + next = current + 1 + } else { + next = current - 1 + } + } + return next +} + func (sm *StateMachine) reconcile() { for lang, mcs := range sm.languages { if sm.targetLang == "" || lang == sm.targetLang || mcs.voice.current.mute == mixer.MuteMuted { @@ -170,11 +183,11 @@ func (sm *StateMachine) reconcile() { sm.currentState = StateSettled for _, mcs := range sm.languages { if mcs.main.target.level != mcs.main.current.level { - sm.mixer.SetLevel(mcs.main.num, mcs.main.target.level) // TODO: implement smooth fading!! + sm.mixer.SetLevel(mcs.main.num, calcNextLevel(mcs.main.target.level, mcs.main.current.level)) sm.currentState = StateSettling } if mcs.voice.target.level != mcs.voice.current.level { - sm.mixer.SetLevel(mcs.voice.num, mcs.voice.target.level) // TODO: implement smooth fading!! + sm.mixer.SetLevel(mcs.voice.num, calcNextLevel(mcs.voice.target.level, mcs.voice.current.level)) sm.currentState = StateSettling } } @@ -184,8 +197,13 @@ func (sm *StateMachine) run() { defer close(sm.exitedCh) sm.initMixer() + t := time.NewTicker(10 * time.Millisecond) for { select { + case <-t.C: + if sm.currentState == StateSettling { + sm.reconcile() + } case req := <-sm.selectLangCh: req.resultCh <- sm.selectLang(req.l) sm.reconcile() |