diff --git a/audio/audio.go b/audio/audio.go index 30ae201e5..a5621939b 100644 --- a/audio/audio.go +++ b/audio/audio.go @@ -251,11 +251,11 @@ type Player struct { // The sample rate must be same as that of the audio context. // // This function is concurrent-safe. -func (c *Context) NewPlayer(src ReadSeekCloser) (*Player, error) { +func NewPlayer(context *Context, src ReadSeekCloser) (*Player, error) { p := &Player{ - players: c.players, + players: context.players, src: src, - sampleRate: c.sampleRate, + sampleRate: context.sampleRate, buf: []byte{}, volume: 1, } diff --git a/examples/audio/main.go b/examples/audio/main.go index c40ad12ce..2850cfb06 100644 --- a/examples/audio/main.go +++ b/examples/audio/main.go @@ -99,7 +99,7 @@ func (p *Player) updateSE() error { } if sePlayer == nil { var err error - sePlayer, err = audioContext.NewPlayer(seStream) + sePlayer, err = audio.NewPlayer(audioContext, seStream) if err != nil { return err } @@ -275,7 +275,7 @@ func main() { log.Fatal(err) return } - p, err := audioContext.NewPlayer(s) + p, err := audio.NewPlayer(audioContext, s) if err != nil { log.Fatal(err) return diff --git a/examples/pcm/main.go b/examples/pcm/main.go index 2dc0f8508..baf074076 100644 --- a/examples/pcm/main.go +++ b/examples/pcm/main.go @@ -136,7 +136,7 @@ func addNote() error { square(r, vol, freq, 0.25) b := toBytes(l, r) s := &srcStream{bytes.NewReader(b)} - p, err := audioContext.NewPlayer(s) + p, err := audio.NewPlayer(audioContext, s) if err != nil { return err } diff --git a/examples/piano/main.go b/examples/piano/main.go index 7cd62dc63..98bbb79a1 100644 --- a/examples/piano/main.go +++ b/examples/piano/main.go @@ -92,7 +92,7 @@ func (s *stream) Close() error { func addNote(freq float64, vol float64) error { f := int(freq) if n, ok := noteCache[f]; ok { - p, err := audioContext.NewPlayer(&stream{bytes.NewReader(n)}) + p, err := audio.NewPlayer(audioContext, &stream{bytes.NewReader(n)}) if err != nil { return err } @@ -113,7 +113,7 @@ func addNote(freq float64, vol float64) error { } n := toBytes(l, r) noteCache[f] = n - p, err := audioContext.NewPlayer(&stream{bytes.NewReader(n)}) + p, err := audio.NewPlayer(audioContext, &stream{bytes.NewReader(n)}) if err != nil { return err } diff --git a/examples/sinewave/main.go b/examples/sinewave/main.go index 9c7e6f52a..6a12a1d08 100644 --- a/examples/sinewave/main.go +++ b/examples/sinewave/main.go @@ -92,7 +92,7 @@ func update(screen *ebiten.Image) error { } if player == nil { var err error - player, err = audioContext.NewPlayer(&stream{}) + player, err = audio.NewPlayer(audioContext, &stream{}) if err != nil { return err }