Compare commits
2 Commits
master
...
random-gen
Author | SHA1 | Date | |
---|---|---|---|
|
a0515ae626 | ||
|
39089cea40 |
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
procedural-musix
|
10
.idea/codeStyles/Project.xml
generated
Normal file
10
.idea/codeStyles/Project.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<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>
|
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
@ -18,6 +18,7 @@ class AudioSink : Thread() {
|
||||
get() = chunks.size
|
||||
|
||||
fun enqueueChunk(chunk: AudioChunk) {
|
||||
println(chunk.tick)
|
||||
chunks.add(chunk.toBytes())
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,7 +1,5 @@
|
||||
package gui
|
||||
|
||||
import javafx.scene.layout.StackPane
|
||||
import java.awt.EventQueue
|
||||
import java.awt.GridLayout
|
||||
import java.awt.Label
|
||||
import javax.swing.JFrame
|
||||
|
Loading…
Reference in New Issue
Block a user