Allow audio buffer size to be configured
This commit is contained in:
parent
93203a318a
commit
fc13cb0928
3 changed files with 8 additions and 16 deletions
|
@ -1,3 +1,6 @@
|
|||
0.1.2:
|
||||
- Allow audio buffer size to be configured
|
||||
|
||||
0.1.1:
|
||||
- Improve list browsing
|
||||
|
||||
|
|
17
audio.go
17
audio.go
|
@ -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()
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -28,6 +28,7 @@ Copyright (c) 2020 Trevor Slocum <trevor@rocketnine.space>
|
|||
|
||||
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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue