From da6ffdf2b9f8a693738edaa64a9eda3d6727bc2b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 5 Apr 2016 00:40:16 +0900 Subject: [PATCH] audio: Refactoring: context doesn't have to have a reference to stream --- exp/audio/audio.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/exp/audio/audio.go b/exp/audio/audio.go index 5e3639d7e..acc8a2cd9 100644 --- a/exp/audio/audio.go +++ b/exp/audio/audio.go @@ -23,7 +23,7 @@ import ( "github.com/hajimehoshi/ebiten" ) -type mixedPlayersStream struct { +type mixingStream struct { context *Context writtenBytes int } @@ -44,7 +44,7 @@ const ( mask = ^(channelNum*bytesPerSample - 1) ) -func (s *mixedPlayersStream) Read(b []byte) (int, error) { +func (s *mixingStream) Read(b []byte) (int, error) { s.context.Lock() defer s.context.Unlock() @@ -105,7 +105,6 @@ func (s *mixedPlayersStream) Read(b []byte) (int, error) { type Context struct { sampleRate int - stream *mixedPlayersStream players map[*Player]struct{} frames int errorCh chan error @@ -119,10 +118,10 @@ func NewContext(sampleRate int) (*Context, error) { players: map[*Player]struct{}{}, errorCh: make(chan error), } - c.stream = &mixedPlayersStream{ + s := &mixingStream{ context: c, } - p, err := newPlayer(c.stream, c.sampleRate) + p, err := newPlayer(s, c.sampleRate) if err != nil { return nil, err }