mirror of https://bitbucket.org/ausocean/av.git
revid: added basic PCM lexer and started adding startMic() func to revid setup.
This commit is contained in:
parent
6ee286e988
commit
e0ec6a8dc9
|
@ -36,6 +36,10 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
audioChunkSize = 16000
|
||||
)
|
||||
|
||||
var noDelay = make(chan time.Time)
|
||||
|
||||
func init() {
|
||||
|
@ -245,3 +249,28 @@ func MJPEG(dst io.Writer, src io.Reader, delay time.Duration) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PCM(dst io.Writer, src io.Reader, delay time.Duration) error {
|
||||
var tick <-chan time.Time
|
||||
if delay == 0 {
|
||||
tick = noDelay
|
||||
} else {
|
||||
ticker := time.NewTicker(delay)
|
||||
defer ticker.Stop()
|
||||
tick = ticker.C
|
||||
}
|
||||
|
||||
r := bufio.NewReader(src)
|
||||
for {
|
||||
buf := make([]byte, 0, audioChunkSize)
|
||||
_, err := r.Read(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
<-tick
|
||||
_, err = dst.Write(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -668,6 +668,13 @@ func (r *Revid) setupInputForFile() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// startMic is used to start capturing audio from an audio device and processing it.
|
||||
func startMic() {
|
||||
|
||||
go processFrom(stream, r.config.Rate)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Revid) processFrom(read io.Reader, delay time.Duration) {
|
||||
r.config.Logger.Log(logger.Info, pkg+"reading input data")
|
||||
r.err <- r.lexTo(r.buffer, read, delay)
|
||||
|
|
Loading…
Reference in New Issue