From b0588cee1487e4499630b3d46ba8bb29d33435d6 Mon Sep 17 00:00:00 2001 From: Trek H Date: Fri, 14 Jun 2019 00:51:26 +0930 Subject: [PATCH] audio: fixed pcm exp cmds and removed buggy period negotiation --- exp/pcm/resample/resample.go | 4 ++-- exp/pcm/stereo-to-mono/stereo-to-mono.go | 4 ++-- input/audio/audio.go | 13 ++++--------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/exp/pcm/resample/resample.go b/exp/pcm/resample/resample.go index 3d595bb8..f7f5342e 100644 --- a/exp/pcm/resample/resample.go +++ b/exp/pcm/resample/resample.go @@ -81,9 +81,9 @@ func main() { } // Save resampled to file. - err = ioutil.WriteFile(outPath, resampled, 0644) + err = ioutil.WriteFile(outPath, resampled.Data, 0644) if err != nil { log.Fatal(err) } - fmt.Println("Encoded and wrote", len(resampled), "bytes to file", outPath) + fmt.Println("Encoded and wrote", len(resampled.Data), "bytes to file", outPath) } diff --git a/exp/pcm/stereo-to-mono/stereo-to-mono.go b/exp/pcm/stereo-to-mono/stereo-to-mono.go index 7dbfd9a5..729caa96 100644 --- a/exp/pcm/stereo-to-mono/stereo-to-mono.go +++ b/exp/pcm/stereo-to-mono/stereo-to-mono.go @@ -77,9 +77,9 @@ func main() { } // Save mono to file. - err = ioutil.WriteFile(outPath, mono, 0644) + err = ioutil.WriteFile(outPath, mono.Data, 0644) if err != nil { log.Fatal(err) } - fmt.Println("Encoded and wrote", len(mono), "bytes to file", outPath) + fmt.Println("Encoded and wrote", len(mono.Data), "bytes to file", outPath) } diff --git a/input/audio/audio.go b/input/audio/audio.go index 702ab35b..0ca61e3f 100644 --- a/input/audio/audio.go +++ b/input/audio/audio.go @@ -284,17 +284,12 @@ func (d *Device) open() error { // Some devices only accept even period sizes while others want powers of 2. // So we will find the closest power of 2 to the desired period size. const wantPeriod = 0.05 //seconds - secondSize := devRate * devChan * (devBits / 8) - wantPeriodSize := int(float64(secondSize) * wantPeriod) + bytesPerSecond := devRate * devChan * (devBits / 8) + wantPeriodSize := int(float64(bytesPerSecond) * wantPeriod) nearWantPeriodSize := nearestPowerOfTwo(wantPeriodSize) - devPeriodSize, err := d.dev.NegotiatePeriodSize(nearWantPeriodSize) - if err != nil { - return err - } - d.l.Log(logger.Debug, pkg+"alsa device period size set", "periodsize", devPeriodSize) - - devBufferSize, err := d.dev.NegotiateBufferSize(devPeriodSize * 2) + // At least two period sizes should fit within the buffer. + devBufferSize, err := d.dev.NegotiateBufferSize(nearWantPeriodSize * 2) if err != nil { return err }