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 (
|
import (
|
||||||
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type float32Source struct {
|
type float32Source struct {
|
||||||
|
@ -9,7 +10,7 @@ type float32Source struct {
|
||||||
SampleRate int
|
SampleRate int
|
||||||
Channels int
|
Channels int
|
||||||
Blocks chan []float32
|
Blocks chan []float32
|
||||||
locked bool
|
locked atomic.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFloat32Source(bitDepth, sampleRate, channels int) TypedSource[float32] {
|
func newFloat32Source(bitDepth, sampleRate, channels int) TypedSource[float32] {
|
||||||
|
@ -33,8 +34,10 @@ func (s *float32Source) GetBlocks() chan []float32 {
|
||||||
if s.Locked() {
|
if s.Locked() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.locked = true
|
if !s.locked.Swap(true) {
|
||||||
return s.Blocks
|
return s.Blocks
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *float32Source) Close() {
|
func (s *float32Source) Close() {
|
||||||
|
@ -54,11 +57,11 @@ func (s *float32Source) GetBitDepth() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *float32Source) Locked() bool {
|
func (s *float32Source) Locked() bool {
|
||||||
return s.locked
|
return s.locked.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *float32Source) Unlock() {
|
func (s *float32Source) Unlock() {
|
||||||
s.locked = false
|
s.locked.Store(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *float32Source) SwapBlocks(blocks chan []float32) chan []float32 {
|
func (s *float32Source) SwapBlocks(blocks chan []float32) chan []float32 {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package audio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type int16Source struct {
|
type int16Source struct {
|
||||||
|
@ -9,7 +10,7 @@ type int16Source struct {
|
||||||
SampleRate int
|
SampleRate int
|
||||||
Channels int
|
Channels int
|
||||||
Blocks chan []int16
|
Blocks chan []int16
|
||||||
locked bool
|
locked atomic.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInt16Source(bitDepth, sampleRate, channels int) TypedSource[int16] {
|
func newInt16Source(bitDepth, sampleRate, channels int) TypedSource[int16] {
|
||||||
|
@ -36,8 +37,10 @@ func (s *int16Source) GetBlocks() chan []int16 {
|
||||||
if s.Locked() {
|
if s.Locked() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.locked = true
|
if !s.locked.Swap(true) {
|
||||||
return s.Blocks
|
return s.Blocks
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *int16Source) Close() {
|
func (s *int16Source) Close() {
|
||||||
|
@ -57,11 +60,11 @@ func (s *int16Source) GetBitDepth() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *int16Source) Locked() bool {
|
func (s *int16Source) Locked() bool {
|
||||||
return s.locked
|
return s.locked.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *int16Source) Unlock() {
|
func (s *int16Source) Unlock() {
|
||||||
s.locked = false
|
s.locked.Store(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *int16Source) SwapBlocks(blocks chan []int16) chan []int16 {
|
func (s *int16Source) SwapBlocks(blocks chan []int16) chan []int16 {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package audio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type int32Source struct {
|
type int32Source struct {
|
||||||
|
@ -9,7 +10,7 @@ type int32Source struct {
|
||||||
SampleRate int
|
SampleRate int
|
||||||
Channels int
|
Channels int
|
||||||
Blocks chan []int32
|
Blocks chan []int32
|
||||||
locked bool
|
locked atomic.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInt32Source(bitDepth, sampleRate, channels int) TypedSource[int32] {
|
func newInt32Source(bitDepth, sampleRate, channels int) TypedSource[int32] {
|
||||||
|
@ -36,8 +37,10 @@ func (s *int32Source) GetBlocks() chan []int32 {
|
||||||
if s.Locked() {
|
if s.Locked() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.locked = true
|
if !s.locked.Swap(true) {
|
||||||
return s.Blocks
|
return s.Blocks
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *int32Source) Close() {
|
func (s *int32Source) Close() {
|
||||||
|
@ -57,11 +60,11 @@ func (s *int32Source) GetBitDepth() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *int32Source) Locked() bool {
|
func (s *int32Source) Locked() bool {
|
||||||
return s.locked
|
return s.locked.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *int32Source) Unlock() {
|
func (s *int32Source) Unlock() {
|
||||||
s.locked = false
|
s.locked.Store(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *int32Source) SwapBlocks(blocks chan []int32) chan []int32 {
|
func (s *int32Source) SwapBlocks(blocks chan []int32) chan []int32 {
|
||||||
|
|
Loading…
Reference in a new issue