mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: refactoring
This commit is contained in:
parent
9faa3f4601
commit
9cc017412f
@ -60,11 +60,6 @@ const (
|
|||||||
type Context struct {
|
type Context struct {
|
||||||
playerFactory *playerFactory
|
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
|
sampleRate int
|
||||||
err error
|
err error
|
||||||
ready bool
|
ready bool
|
||||||
@ -100,7 +95,6 @@ func NewContext(sampleRate int) *Context {
|
|||||||
sampleRate: sampleRate,
|
sampleRate: sampleRate,
|
||||||
playerFactory: newPlayerFactory(sampleRate),
|
playerFactory: newPlayerFactory(sampleRate),
|
||||||
playingPlayers: map[*playerImpl]struct{}{},
|
playingPlayers: map[*playerImpl]struct{}{},
|
||||||
inited: make(chan struct{}),
|
|
||||||
semaphore: make(chan struct{}, 1),
|
semaphore: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
theContext = c
|
theContext = c
|
||||||
@ -128,10 +122,6 @@ func NewContext(sampleRate int) *Context {
|
|||||||
})
|
})
|
||||||
|
|
||||||
h.AppendHookOnBeforeUpdate(func() error {
|
h.AppendHookOnBeforeUpdate(func() error {
|
||||||
c.initedOnce.Do(func() {
|
|
||||||
close(c.inited)
|
|
||||||
})
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
theContextLock.Lock()
|
theContextLock.Lock()
|
||||||
if theContext != nil {
|
if theContext != nil {
|
||||||
@ -316,18 +306,6 @@ func (c *Context) SampleRate() int {
|
|||||||
return c.sampleRate
|
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.
|
// Player is an audio player which has one stream.
|
||||||
//
|
//
|
||||||
// Even when all references to a Player object is gone,
|
// 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
|
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.
|
// contextProxy is a proxy between otoContext and context.
|
||||||
type contextProxy struct {
|
type contextProxy struct {
|
||||||
otoContext
|
*oto.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPlayer implements context.
|
// NewPlayer implements context.
|
||||||
func (c *contextProxy) NewPlayer(r io.Reader) player {
|
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