examples/pcm: Improve debug messages

This commit is contained in:
Hajime Hoshi 2017-03-28 00:56:14 +09:00
parent 892d5d07d0
commit b1c0c618b6

View File

@ -17,7 +17,6 @@
package main
import (
"fmt"
"log"
"math"
@ -98,7 +97,7 @@ func toBytes(l, r []int16) []byte {
return b
}
func addNote() error {
func addNote() (rune, error) {
size := sampleRate / ebiten.FPS
notes := []float64{freqC, freqD, freqE, freqF, freqG, freqA * 2, freqB * 2}
@ -129,27 +128,38 @@ func addNote() error {
b := toBytes(l, r)
p, err := audio.NewPlayerFromBytes(audioContext, b)
if err != nil {
return err
return 0, err
}
if err := p.Play(); err != nil {
return err
return 0, err
}
return nil
return rune(note), nil
}
var currentNote rune
func update(screen *ebiten.Image) error {
defer func() {
frames++
}()
if frames%30 == 0 {
if err := addNote(); err != nil {
n, err := addNote()
if err != nil {
return err
}
currentNote = n
}
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
frames++
if err := audioContext.Update(); err != nil {
return err
}
if ebiten.IsRunningSlowly() {
return nil
}
msg := "Note: "
if currentNote == 'R' {
msg += "-"
} else {
msg += string(currentNote)
}
ebitenutil.DebugPrint(screen, msg)
return nil
}