-
Notifications
You must be signed in to change notification settings - Fork 37
/
DemoFFT01.kt
38 lines (34 loc) · 1.04 KB
/
DemoFFT01.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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))
}
}
}
}
}