Do resampling later, to keep the Seeker
This commit is contained in:
parent
ce3dd841c4
commit
6f28271e47
21
main.go
21
main.go
@ -43,9 +43,7 @@ func xPrintIdle() (idle uint64) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFile(path string) (s beep.Streamer, err error) {
|
func loadFile(path string) (s beep.StreamSeekCloser, format beep.Format, err error) {
|
||||||
var format beep.Format
|
|
||||||
|
|
||||||
for _, decoder := range []func(io.ReadCloser) (beep.StreamSeekCloser, beep.Format, error){flac.Decode, mp3.Decode} {
|
for _, decoder := range []func(io.ReadCloser) (beep.StreamSeekCloser, beep.Format, error){flac.Decode, mp3.Decode} {
|
||||||
var fd *os.File
|
var fd *os.File
|
||||||
|
|
||||||
@ -65,10 +63,6 @@ func loadFile(path string) (s beep.Streamer, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if format.SampleRate != SampleRate {
|
|
||||||
s = beep.Resample(3, format.SampleRate, SampleRate, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -83,21 +77,24 @@ func main() {
|
|||||||
|
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
|
|
||||||
playlist := []beep.Streamer{}
|
playlist := []beep.StreamSeekCloser{}
|
||||||
|
formats := []beep.Format{}
|
||||||
|
|
||||||
// Load playlist
|
// Load playlist
|
||||||
for _, arg := range flag.Args() {
|
for _, arg := range flag.Args() {
|
||||||
s, err := loadFile(arg)
|
s, f, err := loadFile(arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to load %s: %s", arg, err)
|
log.Printf("Unable to load %s: %s", arg, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
playlist = append(playlist, s)
|
playlist = append(playlist, s)
|
||||||
|
formats = append(formats, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shuffle the playlist
|
// Shuffle the playlist
|
||||||
rand.Shuffle(len(playlist), func(i, j int) {
|
rand.Shuffle(len(playlist), func(i, j int) {
|
||||||
playlist[i], playlist[j] = playlist[j], playlist[i]
|
playlist[i], playlist[j] = playlist[j], playlist[i]
|
||||||
|
formats[i], formats[j] = formats[j], formats[i]
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create infinite stream
|
// Create infinite stream
|
||||||
@ -107,7 +104,13 @@ func main() {
|
|||||||
if playedItem >= len(playlist) {
|
if playedItem >= len(playlist) {
|
||||||
playedItem = 0
|
playedItem = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resample if needed
|
||||||
|
if formats[playedItem].SampleRate != SampleRate {
|
||||||
|
return beep.Resample(3, formats[playedItem].SampleRate, SampleRate, playlist[playedItem])
|
||||||
|
} else {
|
||||||
return playlist[playedItem]
|
return playlist[playedItem]
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Prepare sound player
|
// Prepare sound player
|
||||||
|
Loading…
x
Reference in New Issue
Block a user