Made Source Locked atomic.Bool
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
efa01d5c31
commit
5b3948f68c
|
@ -2,6 +2,7 @@ package audio
|
|||
|
||||
import (
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type float32Source struct {
|
||||
|
@ -9,7 +10,7 @@ type float32Source struct {
|
|||
SampleRate int
|
||||
Channels int
|
||||
Blocks chan []float32
|
||||
locked bool
|
||||
locked atomic.Bool
|
||||
}
|
||||
|
||||
func newFloat32Source(bitDepth, sampleRate, channels int) TypedSource[float32] {
|
||||
|
@ -33,9 +34,11 @@ func (s *float32Source) GetBlocks() chan []float32 {
|
|||
if s.Locked() {
|
||||
return nil
|
||||
}
|
||||
s.locked = true
|
||||
if !s.locked.Swap(true) {
|
||||
return s.Blocks
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *float32Source) Close() {
|
||||
close(s.Blocks)
|
||||
|
@ -54,11 +57,11 @@ func (s *float32Source) GetBitDepth() int {
|
|||
}
|
||||
|
||||
func (s *float32Source) Locked() bool {
|
||||
return s.locked
|
||||
return s.locked.Load()
|
||||
}
|
||||
|
||||
func (s *float32Source) Unlock() {
|
||||
s.locked = false
|
||||
s.locked.Store(false)
|
||||
}
|
||||
|
||||
func (s *float32Source) SwapBlocks(blocks chan []float32) chan []float32 {
|
||||
|
|
|
@ -2,6 +2,7 @@ package audio
|
|||
|
||||
import (
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type int16Source struct {
|
||||
|
@ -9,7 +10,7 @@ type int16Source struct {
|
|||
SampleRate int
|
||||
Channels int
|
||||
Blocks chan []int16
|
||||
locked bool
|
||||
locked atomic.Bool
|
||||
}
|
||||
|
||||
func newInt16Source(bitDepth, sampleRate, channels int) TypedSource[int16] {
|
||||
|
@ -36,9 +37,11 @@ func (s *int16Source) GetBlocks() chan []int16 {
|
|||
if s.Locked() {
|
||||
return nil
|
||||
}
|
||||
s.locked = true
|
||||
if !s.locked.Swap(true) {
|
||||
return s.Blocks
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *int16Source) Close() {
|
||||
close(s.Blocks)
|
||||
|
@ -57,11 +60,11 @@ func (s *int16Source) GetBitDepth() int {
|
|||
}
|
||||
|
||||
func (s *int16Source) Locked() bool {
|
||||
return s.locked
|
||||
return s.locked.Load()
|
||||
}
|
||||
|
||||
func (s *int16Source) Unlock() {
|
||||
s.locked = false
|
||||
s.locked.Store(false)
|
||||
}
|
||||
|
||||
func (s *int16Source) SwapBlocks(blocks chan []int16) chan []int16 {
|
||||
|
|
|
@ -2,6 +2,7 @@ package audio
|
|||
|
||||
import (
|
||||
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type int32Source struct {
|
||||
|
@ -9,7 +10,7 @@ type int32Source struct {
|
|||
SampleRate int
|
||||
Channels int
|
||||
Blocks chan []int32
|
||||
locked bool
|
||||
locked atomic.Bool
|
||||
}
|
||||
|
||||
func newInt32Source(bitDepth, sampleRate, channels int) TypedSource[int32] {
|
||||
|
@ -36,9 +37,11 @@ func (s *int32Source) GetBlocks() chan []int32 {
|
|||
if s.Locked() {
|
||||
return nil
|
||||
}
|
||||
s.locked = true
|
||||
if !s.locked.Swap(true) {
|
||||
return s.Blocks
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *int32Source) Close() {
|
||||
close(s.Blocks)
|
||||
|
@ -57,11 +60,11 @@ func (s *int32Source) GetBitDepth() int {
|
|||
}
|
||||
|
||||
func (s *int32Source) Locked() bool {
|
||||
return s.locked
|
||||
return s.locked.Load()
|
||||
}
|
||||
|
||||
func (s *int32Source) Unlock() {
|
||||
s.locked = false
|
||||
s.locked.Store(false)
|
||||
}
|
||||
|
||||
func (s *int32Source) SwapBlocks(blocks chan []int32) chan []int32 {
|
||||
|
|
Loading…
Reference in a new issue