audio: add Ctrl decorator
This commit is contained in:
parent
ee258c1d13
commit
4b70585f1a
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue