audio: Change NewPlayer to be an independent function

This commit is contained in:
Hajime Hoshi 2016-04-19 23:43:54 +09:00
parent af06b5fba0
commit 9a18ffe563
5 changed files with 9 additions and 9 deletions

View File

@ -251,11 +251,11 @@ type Player struct {
// The sample rate must be same as that of the audio context. // The sample rate must be same as that of the audio context.
// //
// This function is concurrent-safe. // This function is concurrent-safe.
func (c *Context) NewPlayer(src ReadSeekCloser) (*Player, error) { func NewPlayer(context *Context, src ReadSeekCloser) (*Player, error) {
p := &Player{ p := &Player{
players: c.players, players: context.players,
src: src, src: src,
sampleRate: c.sampleRate, sampleRate: context.sampleRate,
buf: []byte{}, buf: []byte{},
volume: 1, volume: 1,
} }

View File

@ -99,7 +99,7 @@ func (p *Player) updateSE() error {
} }
if sePlayer == nil { if sePlayer == nil {
var err error var err error
sePlayer, err = audioContext.NewPlayer(seStream) sePlayer, err = audio.NewPlayer(audioContext, seStream)
if err != nil { if err != nil {
return err return err
} }
@ -275,7 +275,7 @@ func main() {
log.Fatal(err) log.Fatal(err)
return return
} }
p, err := audioContext.NewPlayer(s) p, err := audio.NewPlayer(audioContext, s)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
return return

View File

@ -136,7 +136,7 @@ func addNote() error {
square(r, vol, freq, 0.25) square(r, vol, freq, 0.25)
b := toBytes(l, r) b := toBytes(l, r)
s := &srcStream{bytes.NewReader(b)} s := &srcStream{bytes.NewReader(b)}
p, err := audioContext.NewPlayer(s) p, err := audio.NewPlayer(audioContext, s)
if err != nil { if err != nil {
return err return err
} }

View File

@ -92,7 +92,7 @@ func (s *stream) Close() error {
func addNote(freq float64, vol float64) error { func addNote(freq float64, vol float64) error {
f := int(freq) f := int(freq)
if n, ok := noteCache[f]; ok { 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 { if err != nil {
return err return err
} }
@ -113,7 +113,7 @@ func addNote(freq float64, vol float64) error {
} }
n := toBytes(l, r) n := toBytes(l, r)
noteCache[f] = n noteCache[f] = n
p, err := audioContext.NewPlayer(&stream{bytes.NewReader(n)}) p, err := audio.NewPlayer(audioContext, &stream{bytes.NewReader(n)})
if err != nil { if err != nil {
return err return err
} }

View File

@ -92,7 +92,7 @@ func update(screen *ebiten.Image) error {
} }
if player == nil { if player == nil {
var err error var err error
player, err = audioContext.NewPlayer(&stream{}) player, err = audio.NewPlayer(audioContext, &stream{})
if err != nil { if err != nil {
return err return err
} }