speaker: fix race condition
This commit is contained in:
parent
0737b86059
commit
fdb6359fbb
|
@ -77,6 +77,7 @@ func Update() error {
|
||||||
}
|
}
|
||||||
streamerMu.Unlock()
|
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] {
|
||||||
|
@ -94,13 +95,11 @@ func Update() error {
|
||||||
buf[i*4+c*2+1] = high
|
buf[i*4+c*2+1] = high
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill the rest with silence
|
// fill the rest with silence
|
||||||
for i := n * 4; i < len(buf); i++ {
|
for i := n * 4; i < len(buf); i++ {
|
||||||
buf[i] = 0
|
buf[i] = 0
|
||||||
}
|
}
|
||||||
|
// send data to speaker
|
||||||
playerMu.Lock()
|
|
||||||
player.Write(buf)
|
player.Write(buf)
|
||||||
playerMu.Unlock()
|
playerMu.Unlock()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue