mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
example/piano: Add KeyQ
This commit is contained in:
parent
17b7969764
commit
880ea55879
@ -52,25 +52,20 @@ func addNote(freq float64, vol float64) {
|
|||||||
length := len(pcm) * baseFreq / f
|
length := len(pcm) * baseFreq / f
|
||||||
l := make([]int16, length)
|
l := make([]int16, length)
|
||||||
r := make([]int16, length)
|
r := make([]int16, length)
|
||||||
if baseFreq <= freq {
|
j := 0
|
||||||
x := 0
|
jj := 0
|
||||||
i := 0
|
for i := 0; i < len(l); i++ {
|
||||||
for _, p := range pcm {
|
p := pcm[j]
|
||||||
x += baseFreq
|
|
||||||
x %= f
|
|
||||||
if x < baseFreq {
|
|
||||||
l[i] = int16(p * vol * math.MaxInt16)
|
l[i] = int16(p * vol * math.MaxInt16)
|
||||||
r[i] = l[i]
|
r[i] = l[i]
|
||||||
i++
|
jj += f
|
||||||
}
|
j = jj / baseFreq
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Not implemented
|
|
||||||
}
|
}
|
||||||
audio.Play(-1, l, r)
|
audio.Play(-1, l, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
var keys = []ebiten.Key{
|
var keys = []ebiten.Key{
|
||||||
|
ebiten.KeyQ,
|
||||||
ebiten.KeyA,
|
ebiten.KeyA,
|
||||||
ebiten.KeyW,
|
ebiten.KeyW,
|
||||||
ebiten.KeyS,
|
ebiten.KeyS,
|
||||||
@ -112,7 +107,7 @@ func update(screen *ebiten.Image) error {
|
|||||||
if keyStates[key] != 1 {
|
if keyStates[key] != 1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
addNote(220*math.Exp2(float64(i)/12.0), 1.0)
|
addNote(220*math.Exp2(float64(i-1)/12.0), 1.0)
|
||||||
}
|
}
|
||||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user