From ac69e0c48d1f4a33888be9a7da7ca7cfb3f14bbc Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Mon, 3 Aug 2020 21:57:05 +0200 Subject: [PATCH] renamed some stuff --- src/main/kotlin/music/Main.kt | 28 +++++++------------ src/main/kotlin/music/generators/Generator.kt | 6 ++-- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/music/Main.kt b/src/main/kotlin/music/Main.kt index ebdf114..19da707 100644 --- a/src/main/kotlin/music/Main.kt +++ b/src/main/kotlin/music/Main.kt @@ -2,21 +2,19 @@ package music import music.Filter.Filters import music.Params.SAMPLES -import music.generators.Generator import music.generators.ToneGenerator -import javax.sound.sampled.AudioFormat; -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.DataLine; -import javax.sound.sampled.SourceDataLine; +import javax.sound.sampled.AudioFormat +import javax.sound.sampled.AudioSystem +import javax.sound.sampled.DataLine +import javax.sound.sampled.SourceDataLine object Params { - val SAMPLES = 44100; + const val SAMPLES = 44100 + const val PI = kotlin.math.PI.toFloat() val CORES = Runtime.getRuntime().availableProcessors() - val PI = kotlin.math.PI.toFloat() } - -fun main(args: Array) { +fun main() { val format = AudioFormat(SAMPLES.toFloat(), 16, 1, true, false) val info = DataLine.Info( SourceDataLine::class.java, format) @@ -25,15 +23,9 @@ fun main(args: Array) { line.open(format) line.start() - for (i in 0..12) { - - val gen = ToneGenerator(.2f, i, WaveformTransformations::sine) - - - - val signal = Filters.ease(gen.getWave(Samples(1))) + val gen = ToneGenerator(.2f, -24, WaveformTransformations::sawtooth) - line.write(signal.toBytes(), 0, signal.size * 2) - } + val signal = Filters.ease(gen.get(Samples(2))) + line.write(signal.toBytes(), 0, signal.size * 2) } diff --git a/src/main/kotlin/music/generators/Generator.kt b/src/main/kotlin/music/generators/Generator.kt index beadab6..6720569 100644 --- a/src/main/kotlin/music/generators/Generator.kt +++ b/src/main/kotlin/music/generators/Generator.kt @@ -4,12 +4,12 @@ import music.Samples import music.Signal import music.WaveformTransformation -abstract class Generator(val volume: Float, val waveform: WaveformTransformation) { +abstract class Generator(private val volume: Float, private val waveform: WaveformTransformation) { - fun getWave(samples: Samples): Signal { + fun get(samples: Samples): Signal { return waveform(generate(samples), volume) } - abstract fun generate(samples: Samples): Samples + protected abstract fun generate(samples: Samples): Samples }