From 7ef721afb75709525d29f66871922fd4dfb31b45 Mon Sep 17 00:00:00 2001 From: TonyChyi Date: Tue, 27 Sep 2022 12:34:57 +0800 Subject: [PATCH] zero sample when no pcm data --- lib/audiodriver/wavfifo.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 }