mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
audio: Refactoring: context doesn't have to have a reference to stream
This commit is contained in:
parent
f222885d97
commit
da6ffdf2b9
@ -23,7 +23,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mixedPlayersStream struct {
|
type mixingStream struct {
|
||||||
context *Context
|
context *Context
|
||||||
writtenBytes int
|
writtenBytes int
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ const (
|
|||||||
mask = ^(channelNum*bytesPerSample - 1)
|
mask = ^(channelNum*bytesPerSample - 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *mixedPlayersStream) Read(b []byte) (int, error) {
|
func (s *mixingStream) Read(b []byte) (int, error) {
|
||||||
s.context.Lock()
|
s.context.Lock()
|
||||||
defer s.context.Unlock()
|
defer s.context.Unlock()
|
||||||
|
|
||||||
@ -105,7 +105,6 @@ func (s *mixedPlayersStream) Read(b []byte) (int, error) {
|
|||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
sampleRate int
|
sampleRate int
|
||||||
stream *mixedPlayersStream
|
|
||||||
players map[*Player]struct{}
|
players map[*Player]struct{}
|
||||||
frames int
|
frames int
|
||||||
errorCh chan error
|
errorCh chan error
|
||||||
@ -119,10 +118,10 @@ func NewContext(sampleRate int) (*Context, error) {
|
|||||||
players: map[*Player]struct{}{},
|
players: map[*Player]struct{}{},
|
||||||
errorCh: make(chan error),
|
errorCh: make(chan error),
|
||||||
}
|
}
|
||||||
c.stream = &mixedPlayersStream{
|
s := &mixingStream{
|
||||||
context: c,
|
context: c,
|
||||||
}
|
}
|
||||||
p, err := newPlayer(c.stream, c.sampleRate)
|
p, err := newPlayer(s, c.sampleRate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user