mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio: More narrow critical section
This commit is contained in:
parent
7ad82dab44
commit
17d6ea16de
@ -381,21 +381,21 @@ func (p *Player) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) readToBuffer(length int) error {
|
func (p *Player) readToBuffer(length int) error {
|
||||||
p.srcM.Lock()
|
|
||||||
p.m.Lock()
|
|
||||||
bb := make([]byte, length)
|
bb := make([]byte, length)
|
||||||
|
p.srcM.Lock()
|
||||||
n, err := p.src.Read(bb)
|
n, err := p.src.Read(bb)
|
||||||
if 0 < n {
|
|
||||||
p.buf = append(p.buf, bb[:n]...)
|
|
||||||
}
|
|
||||||
p.m.Unlock()
|
|
||||||
p.srcM.Unlock()
|
p.srcM.Unlock()
|
||||||
|
if 0 < n {
|
||||||
|
p.m.Lock()
|
||||||
|
p.buf = append(p.buf, bb[:n]...)
|
||||||
|
p.m.Unlock()
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) bufferToInt16(lengthInBytes int) []int16 {
|
func (p *Player) bufferToInt16(lengthInBytes int) []int16 {
|
||||||
p.m.RLock()
|
|
||||||
r := make([]int16, lengthInBytes/2)
|
r := make([]int16, lengthInBytes/2)
|
||||||
|
p.m.RLock()
|
||||||
for i := 0; i < lengthInBytes/2; i++ {
|
for i := 0; i < lengthInBytes/2; i++ {
|
||||||
r[i] = int16(p.buf[2*i]) | (int16(p.buf[2*i+1]) << 8)
|
r[i] = int16(p.buf[2*i]) | (int16(p.buf[2*i+1]) << 8)
|
||||||
r[i] = int16(float64(r[i]) * p.volume)
|
r[i] = int16(float64(r[i]) * p.volume)
|
||||||
|
Loading…
Reference in New Issue
Block a user