feat(tracker): add a rudimentary VU-meter to show master volume, peaks & clipping

Closes #16
This commit is contained in:
vsariola
2021-02-16 12:23:18 +02:00
parent 962d0f1152
commit 088bbc6c58
4 changed files with 98 additions and 4 deletions

View File

@ -47,7 +47,7 @@ type noteID struct {
id uint32
}
func NewSequencer(bufferSize int, service sointu.SynthService, context sointu.AudioContext, iterator func([]RowNote) []RowNote) *Sequencer {
func NewSequencer(bufferSize int, service sointu.SynthService, context sointu.AudioContext, callBack func([]float32), iterator func([]RowNote) []RowNote) *Sequencer {
ret := &Sequencer{
closer: make(chan struct{}),
setPatch: make(chan sointu.Patch, 32),
@ -60,11 +60,11 @@ func NewSequencer(bufferSize int, service sointu.SynthService, context sointu.Au
// the iterator is a bit unconventional in the sense that it might return
// false to indicate that there is no row available, but might still return
// true in future attempts if new rows become available.
go ret.loop(bufferSize, service, context, iterator)
go ret.loop(bufferSize, service, context, callBack, iterator)
return ret
}
func (s *Sequencer) loop(bufferSize int, service sointu.SynthService, context sointu.AudioContext, iterator func([]RowNote) []RowNote) {
func (s *Sequencer) loop(bufferSize int, service sointu.SynthService, context sointu.AudioContext, callBack func([]float32), iterator func([]RowNote) []RowNote) {
buffer := make([]float32, bufferSize)
renderTries := 0
audioOut := context.Output()
@ -141,6 +141,7 @@ func (s *Sequencer) loop(bufferSize int, service sointu.SynthService, context so
}
}
rendered, timeAdvanced, err := s.synth.Render(buffer, renderTime)
callBack(buffer)
if err != nil {
s.Disable()
break