mirror of https://bitbucket.org/ausocean/av.git
revid: changed PCM lexer timing
previously the lexer would read before any audio was generated, resulting in silence but now the timing is correct.
This commit is contained in:
parent
e699c30a85
commit
28eba2ad60
|
@ -257,18 +257,13 @@ func PCM(dst io.Writer, src io.Reader, delay time.Duration, bufSize int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
<-tick
|
||||||
buf := make([]byte, bufSize)
|
buf := make([]byte, bufSize)
|
||||||
fmt.Printf("LEXER reading: %v bytes\n", bufSize)
|
_, err := src.Read(buf)
|
||||||
n, err := src.Read(buf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
<-tick
|
_, err = dst.Write(buf)
|
||||||
fmt.Printf("LEXER: read %v bytes\n", n)
|
|
||||||
fmt.Printf("LEXER: writing: %v bytes\n", len(buf))
|
|
||||||
// fmt.Printf("LEXER: %v\n", buf)
|
|
||||||
n, err = dst.Write(buf)
|
|
||||||
fmt.Printf("LEXER: wrote %v bytes\n\n", n)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,10 +257,8 @@ func (a *AudioInput) input() {
|
||||||
|
|
||||||
log.Log(logger.Debug, "Audio format conversion has been performed where needed")
|
log.Log(logger.Debug, "Audio format conversion has been performed where needed")
|
||||||
|
|
||||||
fmt.Printf("Writing %v bytes to ringbuffer\n", len(toWrite.Data))
|
|
||||||
var n int
|
var n int
|
||||||
n, err = a.rb.Write(toWrite.Data)
|
n, err = a.rb.Write(toWrite.Data)
|
||||||
fmt.Printf("Wrote %v bytes to ringbuffer\n", n)
|
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
log.Log(logger.Debug, "Wrote audio to ringbuffer", "length", n)
|
log.Log(logger.Debug, "Wrote audio to ringbuffer", "length", n)
|
||||||
|
@ -273,9 +271,9 @@ func (a *AudioInput) input() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// read reads a full PCM chunk from the ringbuffer, returning the number of bytes read upon success.
|
// Read reads a full PCM chunk from the ringbuffer, returning the number of bytes read upon success.
|
||||||
// Any errors returned are unexpected and should be considered fatal.
|
// Any errors returned are unexpected and should be considered fatal.
|
||||||
func (a AudioInput) Read(p []byte) (n int, err error) {
|
func (a *AudioInput) Read(p []byte) (n int, err error) {
|
||||||
fmt.Println("Performing AudioInput read...")
|
fmt.Println("Performing AudioInput read...")
|
||||||
chunk, err := a.rb.Next(rbNextTimeout)
|
chunk, err := a.rb.Next(rbNextTimeout)
|
||||||
switch err {
|
switch err {
|
||||||
|
@ -290,9 +288,7 @@ func (a AudioInput) Read(p []byte) (n int, err error) {
|
||||||
log.Log(logger.Error, "Unexpected error from ring.Next", "error", err.Error())
|
log.Log(logger.Error, "Unexpected error from ring.Next", "error", err.Error())
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
fmt.Printf("Reading %v bytes from ringbuffer\n", chunk.Len())
|
|
||||||
n, err = io.ReadFull(a.rb, p[:chunk.Len()])
|
n, err = io.ReadFull(a.rb, p[:chunk.Len()])
|
||||||
fmt.Printf("Read %v bytes from ringbuffer\n", n)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(logger.Error, "Unexpected error from ring.Read", "error", err.Error())
|
log.Log(logger.Error, "Unexpected error from ring.Read", "error", err.Error())
|
||||||
return n, err
|
return n, err
|
||||||
|
|
Loading…
Reference in New Issue