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:
Trek H 2019-05-08 19:56:02 +09:30
parent e699c30a85
commit 28eba2ad60
2 changed files with 5 additions and 14 deletions

View File

@ -257,18 +257,13 @@ func PCM(dst io.Writer, src io.Reader, delay time.Duration, bufSize int) error {
}
for {
<-tick
buf := make([]byte, bufSize)
fmt.Printf("LEXER reading: %v bytes\n", bufSize)
n, err := src.Read(buf)
_, err := src.Read(buf)
if err != nil {
return err
}
<-tick
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)
_, err = dst.Write(buf)
if err != nil {
return err
}

View File

@ -257,10 +257,8 @@ func (a *AudioInput) input() {
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
n, err = a.rb.Write(toWrite.Data)
fmt.Printf("Wrote %v bytes to ringbuffer\n", n)
switch err {
case nil:
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.
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...")
chunk, err := a.rb.Next(rbNextTimeout)
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())
return 0, err
}
fmt.Printf("Reading %v bytes from ringbuffer\n", chunk.Len())
n, err = io.ReadFull(a.rb, p[:chunk.Len()])
fmt.Printf("Read %v bytes from ringbuffer\n", n)
if err != nil {
log.Log(logger.Error, "Unexpected error from ring.Read", "error", err.Error())
return n, err