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 QueueIdentifier int
|
||||||
|
|
||||||
type QueueEntry struct {
|
type QueueEntry struct {
|
||||||
Identifier QueueIdentifier
|
Identifier QueueIdentifier
|
||||||
Source audio.Source
|
Source audio.Source
|
||||||
//TODO: convert ReadSamples to atomic.Uint64 once 1.19 releases
|
ReadSamples atomic.Uint64
|
||||||
ReadSamples uint64
|
|
||||||
cancel chan bool
|
cancel chan bool
|
||||||
StartCallback func(q *Queue, entry *QueueEntry)
|
StartCallback func(q *Queue, entry *QueueEntry)
|
||||||
EndCallback 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)
|
q.Remove(current.Identifier)
|
||||||
break F1
|
break F1
|
||||||
} else {
|
} 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)
|
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())
|
q.output.(audio.TypedSource[T]).IngestNative(block, current.Source.GetBitDepth())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"git.gammaspectra.live/S.O.N.G/Kirika/test"
|
"git.gammaspectra.live/S.O.N.G/Kirika/test"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sync/atomic"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -43,7 +42,7 @@ func TestQueue(t *testing.T) {
|
||||||
q.AddTail(source, func(q *Queue, entry *QueueEntry) {
|
q.AddTail(source, func(q *Queue, entry *QueueEntry) {
|
||||||
t.Logf("Started playback of %d %s\n", entry.Identifier, fullPath)
|
t.Logf("Started playback of %d %s\n", entry.Identifier, fullPath)
|
||||||
}, func(q *Queue, entry *QueueEntry) {
|
}, 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) {
|
}, func(q *Queue, entry *QueueEntry) {
|
||||||
fp.Close()
|
fp.Close()
|
||||||
if q.GetQueueSize() == 0 {
|
if q.GetQueueSize() == 0 {
|
||||||
|
|
Loading…
Reference in a new issue