audio: add Ctrl decorator

This commit is contained in:
faiface 2017-07-07 18:46:20 +02:00
parent ee258c1d13
commit 4b70585f1a
1 changed files with 24 additions and 0 deletions

24
audio/ctrl.go Normal file
View File

@ -0,0 +1,24 @@
package audio
import "time"
type Ctrl struct {
Streamer Streamer
Paused bool
Duration time.Duration
}
func (c *Ctrl) Stream(samples [][2]float64) (n int, ok bool) {
if c.Streamer == nil {
return 0, false
}
if c.Paused {
for i := range samples {
samples[i] = [2]float64{}
}
return len(samples), true
}
n, ok = c.Streamer.Stream(samples)
c.Duration += time.Duration(n) * time.Second / time.Duration(SampleRate)
return n, ok
}