go-opengl-pixel/audio/ctrl.go

25 lines
450 B
Go
Raw Normal View History

2017-07-07 11:46:20 -05:00
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
}