Compare commits

..

No commits in common. 'random-generator' and 'master' have entirely different histories.

@ -1 +0,0 @@
procedural-musix

@ -1,10 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

@ -1,5 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

@ -18,7 +18,6 @@ class AudioSink : Thread() {
get() = chunks.size
fun enqueueChunk(chunk: AudioChunk) {
println(chunk.tick)
chunks.add(chunk.toBytes())
}

@ -5,7 +5,6 @@ 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
@ -42,25 +41,6 @@ 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()
@ -79,18 +59,23 @@ class RandomDisplacementFractalNoiseGenerator(private val period: Float, val rep
}
fun main(args: Array<String>) {
val sink = AudioSink()
val machine = SoundMachine()
SoundMachine.State.bpm = 1024F
val gen = SoundMachine()
machine.globalEffects.add(Compressor(as_samples(.4f).toInt())::apply)
machine.globalEffects.add(Limiter(.9f)::apply)
gen.globalEffects.add(Compressor(as_samples(.4f).toInt())::apply)
gen.globalEffects.add(Limiter(.9f)::apply)
val gen = RandomGenerator(0f)
machine.generators.add(Chain(gen::generate, ArrayList()))
gen.generators.add(Chain(
RandomDisplacementFractalNoiseGenerator(.2f, 100)::generate,
listOf(
EchoFilter((SAMPLES * 2).toInt(), 0.2f)::apply,
)
)
)
sink.enqueueChunk(machine.nextChunk())
sink.enqueueChunk(gen.nextChunk())
sink.start()
@ -98,8 +83,8 @@ fun main(args: Array<String>) {
Thread {
while (!close) {
sink.enqueueChunk(machine.nextChunk())
while (sink.queueSize > 1) {
sink.enqueueChunk(gen.nextChunk())
while (sink.queueSize > 2) {
Thread.sleep(1)
}
}
@ -107,10 +92,10 @@ fun main(args: Array<String>) {
val frame = SimpleEx("Play!")
frame.add_slider("Property 1", 0, 10000, 50).addChangeListener { e ->
frame.add_slider("Property 1", 0, 100, 50).addChangeListener { e ->
val value = (e.source as JSlider).value
gen.power = -value.toDouble()/100.0
println("Switching power to " + gen.power.toString())
println(value)
}
frame.isVisible = true

@ -1,5 +1,7 @@
package gui
import javafx.scene.layout.StackPane
import java.awt.EventQueue
import java.awt.GridLayout
import java.awt.Label
import javax.swing.JFrame

Loading…
Cancel
Save