mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
audio: refactoring: rename types
This commit is contained in:
parent
55add3e323
commit
eaaa601261
@ -68,7 +68,7 @@ type Context struct {
|
|||||||
ready bool
|
ready bool
|
||||||
readyOnce sync.Once
|
readyOnce sync.Once
|
||||||
|
|
||||||
players map[*player]struct{}
|
players map[*playerImpl]struct{}
|
||||||
|
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
semaphore chan struct{}
|
semaphore chan struct{}
|
||||||
@ -100,7 +100,7 @@ func NewContext(sampleRate int) *Context {
|
|||||||
c := &Context{
|
c := &Context{
|
||||||
sampleRate: sampleRate,
|
sampleRate: sampleRate,
|
||||||
playerFactory: newPlayerFactory(sampleRate),
|
playerFactory: newPlayerFactory(sampleRate),
|
||||||
players: map[*player]struct{}{},
|
players: map[*playerImpl]struct{}{},
|
||||||
inited: make(chan struct{}),
|
inited: make(chan struct{}),
|
||||||
semaphore: make(chan struct{}, 1),
|
semaphore: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ func (c *Context) setReady() {
|
|||||||
c.m.Unlock()
|
c.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) addPlayer(p *player) {
|
func (c *Context) addPlayer(p *playerImpl) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
c.players[p] = struct{}{}
|
c.players[p] = struct{}{}
|
||||||
@ -188,7 +188,7 @@ func (c *Context) addPlayer(p *player) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) removePlayer(p *player) {
|
func (c *Context) removePlayer(p *playerImpl) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
delete(c.players, p)
|
delete(c.players, p)
|
||||||
c.m.Unlock()
|
c.m.Unlock()
|
||||||
@ -269,7 +269,7 @@ func (c *Context) waitUntilInited() {
|
|||||||
// This means that if a Player plays an infinite stream,
|
// This means that if a Player plays an infinite stream,
|
||||||
// the object is never GCed unless Close is called.
|
// the object is never GCed unless Close is called.
|
||||||
type Player struct {
|
type Player struct {
|
||||||
p *player
|
p *playerImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPlayer creates a new player with the given stream.
|
// NewPlayer creates a new player with the given stream.
|
||||||
|
@ -34,7 +34,7 @@ type contextProxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// contextProxy implements context.
|
// contextProxy implements context.
|
||||||
func (c *contextProxy) NewPlayer(r io.Reader) otoPlayer {
|
func (c *contextProxy) NewPlayer(r io.Reader) player {
|
||||||
return c.otoContext.NewPlayer(r)
|
return c.otoContext.NewPlayer(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// otoPlayer is exactly same as the interface oto.Player.
|
// player is exactly same as the interface oto.Player.
|
||||||
// This is defined in order to remove the dependency on Oto from this file.
|
// This is defined in order to remove the dependency on Oto from this file.
|
||||||
type otoPlayer interface {
|
type player interface {
|
||||||
Pause()
|
Pause()
|
||||||
Play()
|
Play()
|
||||||
IsPlaying() bool
|
IsPlaying() bool
|
||||||
@ -36,7 +36,7 @@ type otoPlayer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type context interface {
|
type context interface {
|
||||||
NewPlayer(io.Reader) otoPlayer
|
NewPlayer(io.Reader) player
|
||||||
Suspend() error
|
Suspend() error
|
||||||
Resume() error
|
Resume() error
|
||||||
Err() error
|
Err() error
|
||||||
@ -62,25 +62,25 @@ func newPlayerFactory(sampleRate int) *playerFactory {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
type player struct {
|
type playerImpl struct {
|
||||||
context *Context
|
context *Context
|
||||||
player otoPlayer
|
player player
|
||||||
src io.Reader
|
src io.Reader
|
||||||
stream *timeStream
|
stream *timeStream
|
||||||
factory *playerFactory
|
factory *playerFactory
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *playerFactory) newPlayer(context *Context, src io.Reader) (*player, error) {
|
func (f *playerFactory) newPlayer(context *Context, src io.Reader) (*playerImpl, error) {
|
||||||
f.m.Lock()
|
f.m.Lock()
|
||||||
defer f.m.Unlock()
|
defer f.m.Unlock()
|
||||||
|
|
||||||
p := &player{
|
p := &playerImpl{
|
||||||
src: src,
|
src: src,
|
||||||
context: context,
|
context: context,
|
||||||
factory: f,
|
factory: f,
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(p, (*player).Close)
|
runtime.SetFinalizer(p, (*playerImpl).Close)
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ func (f *playerFactory) initContextIfNeeded() (<-chan struct{}, error) {
|
|||||||
return ready, nil
|
return ready, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) ensurePlayer() error {
|
func (p *playerImpl) ensurePlayer() error {
|
||||||
// Initialize the underlying player lazily to enable calling NewContext in an 'init' function.
|
// Initialize the underlying player lazily to enable calling NewContext in an 'init' function.
|
||||||
// Accessing the underlying player functions requires the environment to be already initialized,
|
// Accessing the underlying player functions requires the environment to be already initialized,
|
||||||
// but if Ebiten is used for a shared library, the timing when init functions are called
|
// but if Ebiten is used for a shared library, the timing when init functions are called
|
||||||
@ -160,7 +160,7 @@ func (p *player) ensurePlayer() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) Play() {
|
func (p *playerImpl) Play() {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ func (p *player) Play() {
|
|||||||
p.context.addPlayer(p)
|
p.context.addPlayer(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) Pause() {
|
func (p *playerImpl) Pause() {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ func (p *player) Pause() {
|
|||||||
p.context.removePlayer(p)
|
p.context.removePlayer(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) IsPlaying() bool {
|
func (p *playerImpl) IsPlaying() bool {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ func (p *player) IsPlaying() bool {
|
|||||||
return p.player.IsPlaying()
|
return p.player.IsPlaying()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) Volume() float64 {
|
func (p *playerImpl) Volume() float64 {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ func (p *player) Volume() float64 {
|
|||||||
return p.player.Volume()
|
return p.player.Volume()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) SetVolume(volume float64) {
|
func (p *playerImpl) SetVolume(volume float64) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ func (p *player) SetVolume(volume float64) {
|
|||||||
p.player.SetVolume(volume)
|
p.player.SetVolume(volume)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) Close() error {
|
func (p *playerImpl) Close() error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
runtime.SetFinalizer(p, nil)
|
runtime.SetFinalizer(p, nil)
|
||||||
@ -237,7 +237,7 @@ func (p *player) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) Current() time.Duration {
|
func (p *playerImpl) Current() time.Duration {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
if err := p.ensurePlayer(); err != nil {
|
if err := p.ensurePlayer(); err != nil {
|
||||||
@ -249,11 +249,11 @@ func (p *player) Current() time.Duration {
|
|||||||
return time.Duration(sample) * time.Second / time.Duration(p.factory.sampleRate)
|
return time.Duration(sample) * time.Second / time.Duration(p.factory.sampleRate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) Rewind() error {
|
func (p *playerImpl) Rewind() error {
|
||||||
return p.Seek(0)
|
return p.Seek(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) Seek(offset time.Duration) error {
|
func (p *playerImpl) Seek(offset time.Duration) error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ func (p *player) Seek(offset time.Duration) error {
|
|||||||
return p.stream.Seek(offset)
|
return p.stream.Seek(offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) Err() error {
|
func (p *playerImpl) Err() error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ func (p *player) Err() error {
|
|||||||
return p.player.Err()
|
return p.player.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *player) source() io.Reader {
|
func (p *playerImpl) source() io.Reader {
|
||||||
return p.src
|
return p.src
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user