It won’t be a question, at least not asked by me. My friend asked me during the OPENRNDR workshop how to use sound with OPENRNDR. and then she immediately googled it. There was no answer over the Internet. So I will write how I do it in my projects with Minim library.
Despite what you might think Minim is not bound directly to Processing. It can be integrated with any java derived code. In case of OPENRNDR you need to add this dependency to build.gradle.kts:
I didn’t realize Minim has a synthesis framework too. That was mostly my reason for going with Beads, plus that it was easy to drop-in an audio back-end. I used OpenAL to achieve positional audio with a 4 speaker setup.
fun main() = application {
program {
var pitch = -1f
// Based on https://stackoverflow.com/questions/31231813/tarsosdsp-pitch-analysis-for-dummies
// On separate thread to not block drawing process
// Use daemon thread to allow the app to quit when main thread finishes
thread(isDaemon = true) {
val bufferSize = 4080
val audioDispatcher = AudioDispatcherFactory.fromDefaultMicrophone(bufferSize, 0)
val pitchProcessor = PitchProcessor(PitchEstimationAlgorithm.YIN, 44100f, bufferSize) {
detectionResult, _ -> pitch = detectionResult.pitch
}
audioDispatcher.addAudioProcessor(pitchProcessor)
audioDispatcher.run()
}
extend {
// -1f means no tone detected
if (pitch != -1f) {
val x = (pitch / 1000.0) * width
drawer.rectangle(x, 0.0, 5.0, height.toDouble())
}
}
}
}
I gotta say that you can just easily use Java libraries (of which there are a lot!) yet essentially write nice Kotlin is a really nice feature of OPENRNDR.
It would maybe it’d be nice to have something about how to add JARs in the guide? I used way more time simply trying to get the JAR to work than I did actually using the library.
PS: TarsosDSP is GPL which might affect your project license.
The guide tapers off quickly at the point where other documentation exist. I see your point though, I think at least pointing towards other texts to read when dealing with these kind of problems would definitely help.
Thanks for sharing! I think it might be nice to convert your reply into an independent post, maybe titled “how to use .jar libraries in OPENRNDR”. Later we could even do a sticky post listing useful posts like that one, a bit like a “user made, easy to update and discuss” guide.