From d243957ab1f7f7c38622ecd35e4465a81efc4727 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 28 Sep 2018 01:52:30 +0900 Subject: [PATCH] examples/audioinfiniteloop: Refactoring: Remove magic numbers --- examples/audioinfiniteloop/main.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/audioinfiniteloop/main.go b/examples/audioinfiniteloop/main.go index 2c6a93d3d..c08169772 100644 --- a/examples/audioinfiniteloop/main.go +++ b/examples/audioinfiniteloop/main.go @@ -32,6 +32,9 @@ const ( screenWidth = 320 screenHeight = 240 sampleRate = 44100 + + introLengthInSecond = 5 + loopLengthInSecond = 4 ) var audioContext *audio.Context @@ -57,7 +60,7 @@ func update(screen *ebiten.Image) error { // Create an infinite loop stream from the decoded bytes. // s is still an io.ReadCloser and io.Seeker. - s := audio.NewInfiniteLoopWithIntro(oggS, 5*4*sampleRate, 4*4*sampleRate) + s := audio.NewInfiniteLoopWithIntro(oggS, introLengthInSecond*4*sampleRate, loopLengthInSecond*4*sampleRate) player, err = audio.NewPlayer(audioContext, s) if err != nil { @@ -78,9 +81,9 @@ func update(screen *ebiten.Image) error { } msg := fmt.Sprintf(`FPS: %0.2f This is an example using audio.NewInfiniteLoop. -Intro: 0[s] - 5[s] -Loop: 5[s] - 9[s] -Current: %0.2f[s]`, ebiten.CurrentFPS(), float64(pos)/float64(time.Second)) +Intro: 0[s] - %[2]d[s] +Loop: %[2]d[s] - %[3]d[s] +Current: %0.2[4]f[s]`, ebiten.CurrentFPS(), introLengthInSecond, introLengthInSecond+loopLengthInSecond, float64(pos)/float64(time.Second)) ebitenutil.DebugPrint(screen, msg) return nil }