mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
doc: Update
This commit is contained in:
parent
5ec3180919
commit
816c6469a2
@ -102,12 +102,18 @@ func (s *stream) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func addNote(freq float64, vol float64) {
|
||||
func addNote(freq float64, vol float64) error {
|
||||
f := int(freq)
|
||||
if n, ok := noteCache[f]; ok {
|
||||
p := audio.NewPlayer(&stream{bytes.NewReader(n)}, sampleRate)
|
||||
p, err := audio.NewPlayer(&stream{bytes.NewReader(n)}, sampleRate)
|
||||
if err == audio.ErrTooManyPlayers {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Play()
|
||||
return
|
||||
return nil
|
||||
}
|
||||
length := len(pcm) * baseFreq / f
|
||||
l := make([]int16, length)
|
||||
@ -123,8 +129,15 @@ func addNote(freq float64, vol float64) {
|
||||
}
|
||||
n := toBytes(l, r)
|
||||
noteCache[f] = n
|
||||
p := audio.NewPlayer(&stream{bytes.NewReader(n)}, sampleRate)
|
||||
p, err := audio.NewPlayer(&stream{bytes.NewReader(n)}, sampleRate)
|
||||
if err == audio.ErrTooManyPlayers {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Play()
|
||||
return nil
|
||||
}
|
||||
|
||||
var keys = []ebiten.Key{
|
||||
@ -217,7 +230,9 @@ func update(screen *ebiten.Image) error {
|
||||
if keyStates[key] != 1 {
|
||||
continue
|
||||
}
|
||||
addNote(220*math.Exp2(float64(i-1)/12.0), 1.0)
|
||||
if err := addNote(220*math.Exp2(float64(i-1)/12.0), 1.0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
|
||||
|
Loading…
Reference in New Issue
Block a user