mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
audio: Rename writerContext -> writerPlayerFactory
This commit is contained in:
parent
a6b3f32f3a
commit
bd1c3ff030
@ -101,7 +101,7 @@ func NewContext(sampleRate int) *Context {
|
|||||||
|
|
||||||
c := &Context{
|
c := &Context{
|
||||||
sampleRate: sampleRate,
|
sampleRate: sampleRate,
|
||||||
np: newWriterContext(sampleRate),
|
np: newWriterPlayerFactory(sampleRate),
|
||||||
players: map[playerImpl]struct{}{},
|
players: map[playerImpl]struct{}{},
|
||||||
inited: make(chan struct{}),
|
inited: make(chan struct{}),
|
||||||
semaphore: make(chan struct{}, 1),
|
semaphore: make(chan struct{}, 1),
|
||||||
|
@ -48,17 +48,17 @@ func newWriterDriver(sampleRate int) writerDriver {
|
|||||||
return newOtoDriver(sampleRate, ch)
|
return newOtoDriver(sampleRate, ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
type writerContext struct {
|
type writerPlayerFactory struct {
|
||||||
driver writerDriver
|
driver writerDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWriterContext(sampleRate int) *writerContext {
|
func newWriterPlayerFactory(sampleRate int) *writerPlayerFactory {
|
||||||
return &writerContext{
|
return &writerPlayerFactory{
|
||||||
driver: newWriterDriver(sampleRate),
|
driver: newWriterDriver(sampleRate),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type writerContextPlayerImpl struct {
|
type writerPlayer struct {
|
||||||
context *Context
|
context *Context
|
||||||
driver writerDriver
|
driver writerDriver
|
||||||
src io.Reader
|
src io.Reader
|
||||||
@ -74,8 +74,8 @@ type writerContextPlayerImpl struct {
|
|||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *writerContext) newPlayerImpl(context *Context, src io.Reader) (playerImpl, error) {
|
func (c *writerPlayerFactory) newPlayerImpl(context *Context, src io.Reader) (playerImpl, error) {
|
||||||
p := &writerContextPlayerImpl{
|
p := &writerPlayer{
|
||||||
context: context,
|
context: context,
|
||||||
driver: c.driver,
|
driver: c.driver,
|
||||||
src: src,
|
src: src,
|
||||||
@ -92,7 +92,7 @@ func (c *writerContext) newPlayerImpl(context *Context, src io.Reader) (playerIm
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) Close() error {
|
func (p *writerPlayer) Close() error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ func (p *writerContextPlayerImpl) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) Play() {
|
func (p *writerPlayer) Play() {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ func (p *writerContextPlayerImpl) Play() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) loop() {
|
func (p *writerPlayer) loop() {
|
||||||
p.context.waitUntilInited()
|
p.context.waitUntilInited()
|
||||||
|
|
||||||
w := p.driver.NewPlayer()
|
w := p.driver.NewPlayer()
|
||||||
@ -167,7 +167,7 @@ func (p *writerContextPlayerImpl) loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) read() ([]byte, bool) {
|
func (p *writerPlayer) read() ([]byte, bool) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -220,21 +220,21 @@ func (p *writerContextPlayerImpl) read() ([]byte, bool) {
|
|||||||
return buf, true
|
return buf, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) IsPlaying() bool {
|
func (p *writerPlayer) IsPlaying() bool {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
r := p.playing
|
r := p.playing
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) Rewind() error {
|
func (p *writerPlayer) Rewind() error {
|
||||||
if _, ok := p.src.(io.Seeker); !ok {
|
if _, ok := p.src.(io.Seeker); !ok {
|
||||||
panic("audio: player to be rewound must be io.Seeker")
|
panic("audio: player to be rewound must be io.Seeker")
|
||||||
}
|
}
|
||||||
return p.Seek(0)
|
return p.Seek(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) Seek(offset time.Duration) error {
|
func (p *writerPlayer) Seek(offset time.Duration) error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
@ -255,27 +255,27 @@ func (p *writerContextPlayerImpl) Seek(offset time.Duration) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) Pause() {
|
func (p *writerPlayer) Pause() {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
p.playing = false
|
p.playing = false
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) Current() time.Duration {
|
func (p *writerPlayer) Current() time.Duration {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
sample := p.pos / bytesPerSample
|
sample := p.pos / bytesPerSample
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
return time.Duration(sample) * time.Second / time.Duration(p.context.SampleRate())
|
return time.Duration(sample) * time.Second / time.Duration(p.context.SampleRate())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) Volume() float64 {
|
func (p *writerPlayer) Volume() float64 {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
v := p.volume
|
v := p.volume
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) SetVolume(volume float64) {
|
func (p *writerPlayer) SetVolume(volume float64) {
|
||||||
// The condition must be true when volume is NaN.
|
// The condition must be true when volume is NaN.
|
||||||
if !(0 <= volume && volume <= 1) {
|
if !(0 <= volume && volume <= 1) {
|
||||||
panic("audio: volume must be in between 0 and 1")
|
panic("audio: volume must be in between 0 and 1")
|
||||||
@ -286,6 +286,6 @@ func (p *writerContextPlayerImpl) SetVolume(volume float64) {
|
|||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *writerContextPlayerImpl) source() io.Reader {
|
func (p *writerPlayer) source() io.Reader {
|
||||||
return p.src
|
return p.src
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user