Add orx-minim

This commit is contained in:
Edwin Jakobs
2022-03-15 21:26:44 +01:00
parent 1bf7abbb96
commit 702af453e4
5 changed files with 94 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
# orx-minim
A minimal Minim support library
## usage
Add `orx-minim` to `orxFeatures`
Check the [example](src/demo/kotlin/DemoFFT01.kt)

View File

@@ -0,0 +1,34 @@
sourceSets {
val main by getting { }
val demo by creating {
java {
srcDir("src/demo/kotlin")
compileClasspath += main.getCompileClasspath()
runtimeClasspath += main.getRuntimeClasspath()
}
}
}
val openrndrVersion: String by rootProject.extra
val openrndrOS: String by rootProject.extra
val slf4jVersion: String by rootProject.extra
val kotlinVersion: String by rootProject.extra
val demoImplementation by configurations.getting {}
val demoRuntimeOnly by configurations.getting {}
dependencies {
api(project(":orx-parameters"))
api(project(":orx-jvm:orx-panel"))
api("net.compartmental.code:minim:2.2.2") {
exclude(group = "org.apache.maven.plugins", module = "maven-javadoc-plugin")
}
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
demoImplementation("org.openrndr:openrndr-application:$openrndrVersion")
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
demoRuntimeOnly("org.slf4j:slf4j-simple:$slf4jVersion")
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
demoImplementation(sourceSets.getByName("main").output)
}

View File

@@ -0,0 +1,31 @@
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()
val lineIn = minim.getLineIn(Minim.MONO, 2048, 48000f)
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))
}
}
}
}
}

View File

@@ -0,0 +1,19 @@
package org.openrndr.extra.minim
import ddf.minim.Minim
import org.openrndr.Program
import java.io.File
class MinimObject {
fun sketchPath(fileName:String) = "./"
fun createInput(fileName: String) = File(fileName).inputStream()
}
fun Program.minim(): Minim {
val minim = Minim(MinimObject())
ended.listen {
minim.stop()
}
return minim
}

View File

@@ -27,6 +27,7 @@ include 'openrndr-demos',
'orx-kdtree',
'orx-jvm:orx-keyframer',
'orx-mesh-generators',
'orx-jvm:orx-minim',
'orx-jvm:orx-kotlin-parser',
'orx-jvm:orx-midi',
'orx-no-clear',