|
|
|
@ -5,6 +5,7 @@ import Params.as_samples
|
|
|
|
|
import filter.Compressor
|
|
|
|
|
import filter.EchoFilter
|
|
|
|
|
import filter.Limiter
|
|
|
|
|
import java.lang.StrictMath.pow
|
|
|
|
|
import gui.SimpleEx
|
|
|
|
|
import random.RandomDisplacementFractal
|
|
|
|
|
import java.awt.event.WindowAdapter
|
|
|
|
@ -41,6 +42,25 @@ class SineWaveGenerator(var tone: Float) : StepGenerator() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RandomGenerator(var tone: Float) :StepGenerator() {
|
|
|
|
|
val N = 200
|
|
|
|
|
val loudness = fun(i:Int): Double {
|
|
|
|
|
return i.toDouble().pow(power)
|
|
|
|
|
}
|
|
|
|
|
var loudnessSum = 0.0
|
|
|
|
|
var power:Double = -1.0
|
|
|
|
|
init {
|
|
|
|
|
for (i in 1 .. N)
|
|
|
|
|
loudnessSum+=loudness(i)
|
|
|
|
|
}
|
|
|
|
|
override fun generateSingle(time: Float): Float {
|
|
|
|
|
var p : Double = 0.0
|
|
|
|
|
for (i in 1 .. N) {
|
|
|
|
|
p += sin(time * toFrequency(tone) * TWO_PI * i) * loudness(i)
|
|
|
|
|
}
|
|
|
|
|
return (p/loudnessSum).toFloat()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
class RandomDisplacementFractalNoiseGenerator(private val period: Float, val repetitions: Int): StepGenerator() {
|
|
|
|
|
val width = (period * SAMPLES).toInt()
|
|
|
|
|
|
|
|
|
@ -59,23 +79,18 @@ class RandomDisplacementFractalNoiseGenerator(private val period: Float, val rep
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun main(args: Array<String>) {
|
|
|
|
|
val sink = AudioSink()
|
|
|
|
|
val gen = SoundMachine()
|
|
|
|
|
val machine = SoundMachine()
|
|
|
|
|
SoundMachine.State.bpm = 1024F
|
|
|
|
|
|
|
|
|
|
gen.globalEffects.add(Compressor(as_samples(.4f).toInt())::apply)
|
|
|
|
|
gen.globalEffects.add(Limiter(.9f)::apply)
|
|
|
|
|
machine.globalEffects.add(Compressor(as_samples(.4f).toInt())::apply)
|
|
|
|
|
machine.globalEffects.add(Limiter(.9f)::apply)
|
|
|
|
|
|
|
|
|
|
gen.generators.add(Chain(
|
|
|
|
|
RandomDisplacementFractalNoiseGenerator(.2f, 100)::generate,
|
|
|
|
|
listOf(
|
|
|
|
|
EchoFilter((SAMPLES * 2).toInt(), 0.2f)::apply,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
val gen = RandomGenerator(0f)
|
|
|
|
|
machine.generators.add(Chain(gen::generate, ArrayList()))
|
|
|
|
|
|
|
|
|
|
sink.enqueueChunk(gen.nextChunk())
|
|
|
|
|
sink.enqueueChunk(machine.nextChunk())
|
|
|
|
|
|
|
|
|
|
sink.start()
|
|
|
|
|
|
|
|
|
@ -83,8 +98,8 @@ fun main(args: Array<String>) {
|
|
|
|
|
|
|
|
|
|
Thread {
|
|
|
|
|
while (!close) {
|
|
|
|
|
sink.enqueueChunk(gen.nextChunk())
|
|
|
|
|
while (sink.queueSize > 2) {
|
|
|
|
|
sink.enqueueChunk(machine.nextChunk())
|
|
|
|
|
while (sink.queueSize > 1) {
|
|
|
|
|
Thread.sleep(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -92,10 +107,10 @@ fun main(args: Array<String>) {
|
|
|
|
|
|
|
|
|
|
val frame = SimpleEx("Play!")
|
|
|
|
|
|
|
|
|
|
frame.add_slider("Property 1", 0, 100, 50).addChangeListener { e ->
|
|
|
|
|
frame.add_slider("Property 1", 0, 10000, 50).addChangeListener { e ->
|
|
|
|
|
val value = (e.source as JSlider).value
|
|
|
|
|
println(value)
|
|
|
|
|
|
|
|
|
|
gen.power = -value.toDouble()/100.0
|
|
|
|
|
println("Switching power to " + gen.power.toString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frame.isVisible = true
|
|
|
|
|