Kirika/audio/queue/queue_test.go
DataHoarder bf39ddac3a
All checks were successful
continuous-integration/drone/push Build is passing
Update several sections to use atomic[T] instead of pointers
2022-08-03 15:38:29 +02:00

75 lines
1.7 KiB
Go

package queue
import (
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/guess"
"git.gammaspectra.live/S.O.N.G/Kirika/test"
"os"
"path"
"testing"
)
func TestQueue(t *testing.T) {
t.Parallel()
const sampleRate = 44100
q := NewQueue(audio.SourceInt16, 16, sampleRate, 2)
flacFormat := guess.GetDecoder("flac")
for _, location := range test.TestSampleLocations {
entries, err := os.ReadDir(location)
if err != nil {
t.Error(err)
return
}
for _, f := range entries {
if path.Ext(f.Name()) == ".flac" {
fullPath := path.Join(location, f.Name())
fp, err := os.Open(fullPath)
if err != nil {
t.Error(err)
return
}
source, err := flacFormat.Open(fp)
if err != nil {
fp.Close()
t.Error(err)
return
}
q.AddTail(source, func(q *Queue, entry *QueueEntry) {
t.Logf("Started playback of %d %s\n", entry.Identifier, fullPath)
}, func(q *Queue, entry *QueueEntry) {
t.Logf("Finished playback of %d %s: output %d samples\n", entry.Identifier, fullPath, entry.ReadSamples.Load())
}, func(q *Queue, entry *QueueEntry) {
fp.Close()
if q.GetQueueSize() == 0 {
t.Log("Finished playback, closing\n")
q.Close()
}
})
}
}
}
//Decode
result := q.GetSource()
sink := audio.NewForwardSink(audio.NewNullSink())
sink.Process(result)
q.Wait()
if result.GetSampleRate() != sampleRate {
t.Errorf("Wrong SampleRate %d != %d", result.GetSampleRate(), sampleRate)
}
if result.GetChannels() != 2 {
t.Errorf("Wrong Channel Count %d != %d", result.GetChannels(), 2)
}
if sink.GetSamplesRead() != 470828559 {
t.Errorf("Wrong Sample Count %d != %d", sink.GetSamplesRead(), 470828559)
}
}