actually fix the race condition
This commit is contained in:
parent
d0f6e646ac
commit
5d3f082240
|
@ -64,8 +64,8 @@ func Play(s audio.Streamer) {
|
||||||
// This function should be called at least once the duration of bufferSize given in Init, but it's
|
// This function should be called at least once the duration of bufferSize given in Init, but it's
|
||||||
// recommended to call it more frequently to avoid glitches.
|
// recommended to call it more frequently to avoid glitches.
|
||||||
func Update() error {
|
func Update() error {
|
||||||
// pull data from the streamer, if any
|
|
||||||
streamerMu.Lock()
|
streamerMu.Lock()
|
||||||
|
// pull data from the streamer, if any
|
||||||
n := 0
|
n := 0
|
||||||
if streamer != nil {
|
if streamer != nil {
|
||||||
var ok bool
|
var ok bool
|
||||||
|
@ -74,9 +74,6 @@ func Update() error {
|
||||||
streamer = nil
|
streamer = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
streamerMu.Unlock()
|
|
||||||
|
|
||||||
playerMu.Lock()
|
|
||||||
// convert samples to bytes
|
// convert samples to bytes
|
||||||
for i := range samples[:n] {
|
for i := range samples[:n] {
|
||||||
for c := range samples[i] {
|
for c := range samples[i] {
|
||||||
|
@ -98,7 +95,10 @@ func Update() error {
|
||||||
for i := n * 4; i < len(buf); i++ {
|
for i := n * 4; i < len(buf); i++ {
|
||||||
buf[i] = 0
|
buf[i] = 0
|
||||||
}
|
}
|
||||||
|
streamerMu.Unlock()
|
||||||
|
|
||||||
// send data to speaker
|
// send data to speaker
|
||||||
|
playerMu.Lock()
|
||||||
player.Write(buf)
|
player.Write(buf)
|
||||||
playerMu.Unlock()
|
playerMu.Unlock()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue