mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
examples/piano: Refactoring
This commit is contained in:
parent
8b2dfdb3e7
commit
b30703eb00
@ -49,12 +49,13 @@ var pcm = make([]float64, 4*sampleRate)
|
|||||||
const baseFreq = 220
|
const baseFreq = 220
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
const twoPiF = 2.0 * math.Pi * baseFreq
|
||||||
|
|
||||||
s := float64(sampleRate)
|
s := float64(sampleRate)
|
||||||
amp := []float64{1.0, 0.8, 0.6, 0.4, 0.2}
|
amp := []float64{1.0, 0.8, 0.6, 0.4, 0.2}
|
||||||
x := []float64{4.0, 2.0, 1.0, 0.5, 0.25}
|
x := []float64{4.0, 2.0, 1.0, 0.5, 0.25}
|
||||||
for i := 0; i < len(pcm); i++ {
|
for i := 0; i < len(pcm); i++ {
|
||||||
v := 0.0
|
v := 0.0
|
||||||
twoPiF := 2.0 * math.Pi * baseFreq
|
|
||||||
for j := 0; j < len(amp); j++ {
|
for j := 0; j < len(amp); j++ {
|
||||||
a := amp[j] * math.Exp(-5*float64(i)/(x[j]*s))
|
a := amp[j] * math.Exp(-5*float64(i)/(x[j]*s))
|
||||||
v += a * math.Sin(float64(i)*twoPiF*float64(j+1)/s)
|
v += a * math.Sin(float64(i)*twoPiF*float64(j+1)/s)
|
||||||
|
Loading…
Reference in New Issue
Block a user