From b1c0c618b6d66c99e493815d667536d0c3f337ee Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 28 Mar 2017 00:56:14 +0900 Subject: [PATCH] examples/pcm: Improve debug messages --- examples/pcm/main.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/examples/pcm/main.go b/examples/pcm/main.go index 16c5423bd..efab15b11 100644 --- a/examples/pcm/main.go +++ b/examples/pcm/main.go @@ -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 }