diff --git a/lib/audiodriver/wavfifo.go b/lib/audiodriver/wavfifo.go index ffe9f07..85adb76 100644 --- a/lib/audiodriver/wavfifo.go +++ b/lib/audiodriver/wavfifo.go @@ -4,6 +4,7 @@ import ( "context" "encoding/binary" "io" + "time" "github.com/pion/mediadevices/pkg/io/audio" "github.com/pion/mediadevices/pkg/prop" @@ -63,6 +64,12 @@ func (w *WavFIFODriver) Properties() []prop.Media { } func (w *WavFIFODriver) AudioRecord(p prop.Media) (audio.Reader, error) { + a := wave.NewInt16Interleaved(wave.ChunkInfo{ + Len: BufferSize / int(p.SampleSize/BitsPerByte), + Channels: p.ChannelCount, + SamplingRate: p.SampleRate, + }) + reader := func() (wave.Audio, func(), error) { select { case <-w.closed: @@ -72,15 +79,10 @@ func (w *WavFIFODriver) AudioRecord(p prop.Media) (audio.Reader, error) { if !ok { return nil, func() {}, io.ErrClosedPipe } - - a := wave.NewInt16Interleaved(wave.ChunkInfo{ - Len: BufferSize / int(p.SampleSize/BitsPerByte), - Channels: p.ChannelCount, - SamplingRate: p.SampleRate, - }) copy(a.Data, bytesTo16BitSamples(pcmData[:])) - return a, func() {}, nil + case <-time.After(p.Latency): } + return a, func() {}, nil } return audio.ReaderFunc(reader), nil }