Update QueueEntry.ReadSamples to use atomic.Uint64
This commit is contained in:
parent
51b7371574
commit
d785718551
|
@ -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(¤t.ReadSamples) == 0 && len(block) > 0 {
|
||||
if current.StartCallback != nil && current.ReadSamples.Load() == 0 && len(block) > 0 {
|
||||
current.StartCallback(q, current)
|
||||
}
|
||||
atomic.AddUint64(¤t.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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue