mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
audio: refactoring
This commit is contained in:
parent
9faa3f4601
commit
9cc017412f
@ -60,11 +60,6 @@ const (
|
||||
type Context struct {
|
||||
playerFactory *playerFactory
|
||||
|
||||
// inited represents whether the audio device is initialized and available or not.
|
||||
// On Android, audio loop cannot be started unless JVM is accessible. After updating one frame, JVM should exist.
|
||||
inited chan struct{}
|
||||
initedOnce sync.Once
|
||||
|
||||
sampleRate int
|
||||
err error
|
||||
ready bool
|
||||
@ -100,7 +95,6 @@ func NewContext(sampleRate int) *Context {
|
||||
sampleRate: sampleRate,
|
||||
playerFactory: newPlayerFactory(sampleRate),
|
||||
playingPlayers: map[*playerImpl]struct{}{},
|
||||
inited: make(chan struct{}),
|
||||
semaphore: make(chan struct{}, 1),
|
||||
}
|
||||
theContext = c
|
||||
@ -128,10 +122,6 @@ func NewContext(sampleRate int) *Context {
|
||||
})
|
||||
|
||||
h.AppendHookOnBeforeUpdate(func() error {
|
||||
c.initedOnce.Do(func() {
|
||||
close(c.inited)
|
||||
})
|
||||
|
||||
var err error
|
||||
theContextLock.Lock()
|
||||
if theContext != nil {
|
||||
@ -316,18 +306,6 @@ func (c *Context) SampleRate() int {
|
||||
return c.sampleRate
|
||||
}
|
||||
|
||||
func (c *Context) acquireSemaphore() {
|
||||
c.semaphore <- struct{}{}
|
||||
}
|
||||
|
||||
func (c *Context) releaseSemaphore() {
|
||||
<-c.semaphore
|
||||
}
|
||||
|
||||
func (c *Context) waitUntilInited() {
|
||||
<-c.inited
|
||||
}
|
||||
|
||||
// Player is an audio player which has one stream.
|
||||
//
|
||||
// Even when all references to a Player object is gone,
|
||||
|
@ -30,20 +30,12 @@ func newContext(sampleRate int) (context, chan struct{}, error) {
|
||||
return &contextProxy{ctx}, ready, err
|
||||
}
|
||||
|
||||
// otoContext is an interface for *oto.Context.
|
||||
type otoContext interface {
|
||||
NewPlayer(io.Reader) *oto.Player
|
||||
Suspend() error
|
||||
Resume() error
|
||||
Err() error
|
||||
}
|
||||
|
||||
// contextProxy is a proxy between otoContext and context.
|
||||
type contextProxy struct {
|
||||
otoContext
|
||||
*oto.Context
|
||||
}
|
||||
|
||||
// NewPlayer implements context.
|
||||
func (c *contextProxy) NewPlayer(r io.Reader) player {
|
||||
return c.otoContext.NewPlayer(r)
|
||||
return c.Context.NewPlayer(r)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user