Files
orx/orx-jvm/orx-minim/src/demo/kotlin/DemoFFT01.kt
Abe Pazos c8f7dd52c6 Demos: ensure all use fun main() = application {
- Adjust some demo window sizes.
- Replace Random.double by Double.uniform
- Tweak some demos so screenshots look more interesting
2025-01-26 20:57:04 +01:00

36 lines
968 B
Kotlin

import ddf.minim.Minim
import ddf.minim.analysis.FFT
import ddf.minim.analysis.LanczosWindow
import org.openrndr.application
import org.openrndr.extra.minim.minim
import org.openrndr.math.map
import kotlin.math.ln
fun main() = application {
configure {
width = 1280
height = 720
}
program {
val minim = minim()
if (minim.lineOut == null) {
application.exit()
}
val lineIn = minim.getLineIn(Minim.MONO, 2048, 48000f)
if (lineIn == null) {
application.exit()
}
val fft = FFT(lineIn.bufferSize(), lineIn.sampleRate())
fft.window(LanczosWindow())
extend {
fft.forward(lineIn.mix)
for (i in 0 until 200) {
val bandDB = 20.0 * ln(2.0 * fft.getBand(i) / fft.timeSize())
drawer.rectangle(i * 5.0, height / 2.0, 5.0, bandDB.map(0.0, -150.0, 0.0, -height / 8.0))
}
}
}
}