RandomGenerator
This commit is contained in:
parent
fca2ca7dc1
commit
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())
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ import Params.TWO_PI
|
||||
import Params.as_samples
|
||||
import filter.Compressor
|
||||
import filter.Limiter
|
||||
import java.lang.StrictMath.pow
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sin
|
||||
@ -35,7 +36,24 @@ 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(-0)
|
||||
}
|
||||
var loudnessSum = 0.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()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val sink = AudioSink()
|
||||
@ -46,7 +64,7 @@ fun main(args: Array<String>) {
|
||||
gen.globalEffects.add(Compressor(as_samples(.4f).toInt())::apply)
|
||||
gen.globalEffects.add(Limiter(.9f)::apply)
|
||||
|
||||
gen.generators.add(Chain(SineWaveGenerator(0f)::generate, ArrayList()))
|
||||
gen.generators.add(Chain(RandomGenerator(0f)::generate, ArrayList()))
|
||||
|
||||
sink.enqueueChunk(gen.nextChunk())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user