Commit fc13cb09 authored by Trevor Slocum's avatar Trevor Slocum

Allow audio buffer size to be configured

parent 93203a31
0.1.2:
- Allow audio buffer size to be configured
0.1.1:
- Improve list browsing
......
......@@ -20,6 +20,8 @@ import (
"github.com/faiface/beep/wav"
)
const DefaultBufferSize = 500 * time.Millisecond
var (
playingFileName string
playingFileInfo string
......@@ -110,7 +112,7 @@ func play(audioFile *AudioFile) {
}
if audioFile.Format.SampleRate != playingSampleRate {
err := speaker.Init(audioFile.Format.SampleRate, audioFile.Format.SampleRate.N(time.Second/2))
err := speaker.Init(audioFile.Format.SampleRate, audioFile.Format.SampleRate.N(bufferSize))
if err != nil {
log.Fatalf("failed to initialize audio device: %s", err)
}
......@@ -204,16 +206,3 @@ func fileFormat(fileName string) string {
return "?"
}
}
func closeAudio() {
audioLock.Lock()
defer audioLock.Unlock()
speaker.Lock()
if playingStreamer != nil {
playingStreamer.Close()
}
speaker.Unlock()
speaker.Close()
}
......@@ -28,6 +28,7 @@ Copyright (c) 2020 Trevor Slocum <[email protected]>
var (
printVersionInfo bool
bufferSize time.Duration
debugAddress string
cpuProfile string
......@@ -38,6 +39,7 @@ func main() {
log.SetFlags(0)
flag.BoolVar(&printVersionInfo, "version", false, "print version information and exit")
flag.DurationVar(&bufferSize, "buffer-size", DefaultBufferSize, "audio buffer size")
flag.StringVar(&debugAddress, "debug-address", "", "address to serve debug info")
flag.StringVar(&cpuProfile, "cpu-profile", "", "path to save CPU profiling")
flag.Parse()
......@@ -125,8 +127,6 @@ func main() {
}
defer func() {
closeAudio()
if app != nil {
app.Stop()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment