mirror of https://bitbucket.org/ausocean/av.git
audio: fixed pcm exp cmds and removed buggy period negotiation
This commit is contained in:
parent
e3ba1e43f3
commit
b0588cee14
|
@ -81,9 +81,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save resampled to file.
|
// Save resampled to file.
|
||||||
err = ioutil.WriteFile(outPath, resampled, 0644)
|
err = ioutil.WriteFile(outPath, resampled.Data, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,9 +77,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save mono to file.
|
// Save mono to file.
|
||||||
err = ioutil.WriteFile(outPath, mono, 0644)
|
err = ioutil.WriteFile(outPath, mono.Data, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,17 +284,12 @@ func (d *Device) open() error {
|
||||||
// Some devices only accept even period sizes while others want powers of 2.
|
// 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.
|
// So we will find the closest power of 2 to the desired period size.
|
||||||
const wantPeriod = 0.05 //seconds
|
const wantPeriod = 0.05 //seconds
|
||||||
secondSize := devRate * devChan * (devBits / 8)
|
bytesPerSecond := devRate * devChan * (devBits / 8)
|
||||||
wantPeriodSize := int(float64(secondSize) * wantPeriod)
|
wantPeriodSize := int(float64(bytesPerSecond) * wantPeriod)
|
||||||
nearWantPeriodSize := nearestPowerOfTwo(wantPeriodSize)
|
nearWantPeriodSize := nearestPowerOfTwo(wantPeriodSize)
|
||||||
|
|
||||||
devPeriodSize, err := d.dev.NegotiatePeriodSize(nearWantPeriodSize)
|
// At least two period sizes should fit within the buffer.
|
||||||
if err != nil {
|
devBufferSize, err := d.dev.NegotiateBufferSize(nearWantPeriodSize * 2)
|
||||||
return err
|
|
||||||
}
|
|
||||||
d.l.Log(logger.Debug, pkg+"alsa device period size set", "periodsize", devPeriodSize)
|
|
||||||
|
|
||||||
devBufferSize, err := d.dev.NegotiateBufferSize(devPeriodSize * 2)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue