Update QueueEntry.ReadSamples to use atomic.Uint64

This commit is contained in:
DataHoarder 2022-08-02 20:44:16 +02:00
parent 51b7371574
commit d785718551
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 6 additions and 8 deletions

View file

@ -11,10 +11,9 @@ import (
type QueueIdentifier int
type QueueEntry struct {
Identifier QueueIdentifier
Source audio.Source
//TODO: convert ReadSamples to atomic.Uint64 once 1.19 releases
ReadSamples uint64
Identifier QueueIdentifier
Source audio.Source
ReadSamples atomic.Uint64
cancel chan bool
StartCallback func(q *Queue, entry *QueueEntry)
EndCallback func(q *Queue, entry *QueueEntry)
@ -147,10 +146,10 @@ func queueLoopStart[T audio.AllowedSourceTypes](q *Queue) {
q.Remove(current.Identifier)
break F1
} else {
if current.StartCallback != nil && atomic.LoadUint64(&current.ReadSamples) == 0 && len(block) > 0 {
if current.StartCallback != nil && current.ReadSamples.Load() == 0 && len(block) > 0 {
current.StartCallback(q, current)
}
atomic.AddUint64(&current.ReadSamples, uint64(len(block)/current.Source.GetChannels()))
current.ReadSamples.Add(uint64(len(block) / current.Source.GetChannels()))
q.output.(audio.TypedSource[T]).IngestNative(block, current.Source.GetBitDepth())
}
}

View file

@ -6,7 +6,6 @@ import (
"git.gammaspectra.live/S.O.N.G/Kirika/test"
"os"
"path"
"sync/atomic"
"testing"
)
@ -43,7 +42,7 @@ func TestQueue(t *testing.T) {
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, atomic.LoadUint64(&entry.ReadSamples))
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 {