mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Revert "audio: Bug fix: Fill empty data even when audio is suspended"
This reverts commit 529dddda53
.
Updates #975
Reason: This causes PARTIAL_WAKE_LOCK on Android (AudioDirectOut) (#931)
This commit is contained in:
parent
8d12446dbe
commit
5182060899
@ -63,11 +63,11 @@ type Context struct {
|
||||
sampleRate int
|
||||
err error
|
||||
ready bool
|
||||
suspended bool
|
||||
|
||||
players map[*playerImpl]struct{}
|
||||
|
||||
m sync.Mutex
|
||||
m sync.Mutex
|
||||
semaphore chan struct{}
|
||||
}
|
||||
|
||||
var (
|
||||
@ -75,8 +75,6 @@ var (
|
||||
theContextLock sync.Mutex
|
||||
)
|
||||
|
||||
var emptyBytes = make([]byte, 256)
|
||||
|
||||
// NewContext creates a new audio context with the given sample rate.
|
||||
//
|
||||
// The sample rate is also used for decoding MP3 with audio/mp3 package
|
||||
@ -101,19 +99,16 @@ func NewContext(sampleRate int) (*Context, error) {
|
||||
c: newContext(sampleRate),
|
||||
players: map[*playerImpl]struct{}{},
|
||||
inited: make(chan struct{}),
|
||||
semaphore: make(chan struct{}, 1),
|
||||
}
|
||||
theContext = c
|
||||
|
||||
h := getHook()
|
||||
h.OnSuspendAudio(func() {
|
||||
c.m.Lock()
|
||||
c.suspended = true
|
||||
c.m.Unlock()
|
||||
c.semaphore <- struct{}{}
|
||||
})
|
||||
h.OnResumeAudio(func() {
|
||||
c.m.Lock()
|
||||
c.suspended = false
|
||||
c.m.Unlock()
|
||||
<-c.semaphore
|
||||
})
|
||||
|
||||
h.AppendHookOnBeforeUpdate(func() error {
|
||||
@ -460,14 +455,10 @@ func (p *playerImpl) read() ([]byte, bool) {
|
||||
|
||||
const bufSize = 2048
|
||||
|
||||
// If audio is suspended, fill zero values not to cause delay (#975).
|
||||
// TODO: Oto's players should be able to be suspended and resumed.
|
||||
p.context.m.Lock()
|
||||
s := p.context.suspended
|
||||
p.context.m.Unlock()
|
||||
if s {
|
||||
return emptyBytes, true
|
||||
}
|
||||
p.context.semaphore <- struct{}{}
|
||||
defer func() {
|
||||
<-p.context.semaphore
|
||||
}()
|
||||
|
||||
newBuf := make([]byte, bufSize-len(p.buf))
|
||||
n, err := p.src.Read(newBuf)
|
||||
|
Loading…
Reference in New Issue
Block a user