doc: Update

This commit is contained in:
Hajime Hoshi 2016-02-13 23:08:01 +09:00
parent 5ec3180919
commit 816c6469a2

View File

@ -102,12 +102,18 @@ func (s *stream) Close() error {
return nil return nil
} }
func addNote(freq float64, vol float64) { 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 := 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() p.Play()
return return nil
} }
length := len(pcm) * baseFreq / f length := len(pcm) * baseFreq / f
l := make([]int16, length) l := make([]int16, length)
@ -123,8 +129,15 @@ func addNote(freq float64, vol float64) {
} }
n := toBytes(l, r) n := toBytes(l, r)
noteCache[f] = n 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() p.Play()
return nil
} }
var keys = []ebiten.Key{ var keys = []ebiten.Key{
@ -217,7 +230,9 @@ func update(screen *ebiten.Image) error {
if keyStates[key] != 1 { if keyStates[key] != 1 {
continue 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}) screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})