mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
audio: Change NewPlayer to be an independent function
This commit is contained in:
parent
af06b5fba0
commit
9a18ffe563
@ -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,
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user