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.
//
// 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,
}

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}