Skip to content

Instantly share code, notes, and snippets.

import io.wavebeans.daw.SineVoice
import io.wavebeans.daw.Standard6StringTuning
import io.wavebeans.daw.synthesize
import io.wavebeans.daw.tab
import io.wavebeans.execution.SingleThreadedOverseer
import io.wavebeans.lib.io.toMono24bitWav
val stream =
"""
e|-------5-7-----7-|-8-----8-2-----2-|-0---------0-----|-----------------|
@asubb
asubb / docker-cleanup.sh
Created July 6, 2020 18:35
Clean up all docker resources
docker rm -f $(docker container ls -q -a)
docker volume rm $(docker volume ls -q)
docker rmi $(docker images -q)
@asubb
asubb / wave-blog:using-jupyter:long.signal.query.plot.kt
Created April 10, 2020 21:33
wave-blog/using-jupyter/long.signal.query.plot.kt
val df1 = fftData("fft-triangular", freqCutOff = 10 to 3800)
lets_plot(df1) {x = "time"; y = "freq"; fill = "value"} +
ggsize(1000, 600) +
geom_tile() +
scale_fill_gradient(low = "light_green", high = "red")
val df2 = fftData("fft-hamming", freqCutOff = 10 to 3800)
lets_plot(df2) {x = "time"; y = "freq"; fill = "value"} +
ggsize(1000, 600) +
geom_tile() +
@asubb
asubb / wave-blog:using-jupyter:long.signal.query.func.kt
Created April 10, 2020 21:27
wave-blog/using-jupyter/long.signal.query.func.kt
fun fftData(table: String, freqCutOff: Pair<Int, Int>): Map<String, List<Any>> {
val k = Klaxon()
val server = "http://localhost:6800"
// 1. read and deserializae the data
val data = URL("$server/table/$table/last?interval=10s").openStream().reader().readLines()
.map { k.parse<Result>(it)!! }
// 2. Calculate the time value to shift values to 0 by x-axis
val timeShift = data.asSequence().map { it.value.time }.min() ?: 0
@asubb
asubb / wave-blog:using-jupyter:long.signal.query.types.kt
Created April 10, 2020 21:23
wave-blog/using-jupyter/long.signal.query.types.kt
data class FftSample(
val index: Long,
val binCount: Int,
val samplesCount: Int,
val sampleRate: Float,
val magnitude: List<Double>,
val phase: List<Double>,
val frequency: List<Double>,
val time: Long
)
@asubb
asubb / wave-blog:using-jupyter:long.signal.query.imports.kt
Created April 10, 2020 21:21
wave-blog/using-jupyter/long.signal.query.imports.kt
%use klaxon
%use lets-plot
import java.net.*
import jetbrains.letsPlot.scale.*
@asubb
asubb / wave-blog:using-jupyter:long.signal.exe.kt
Created April 10, 2020 21:19
wave-blog/using-jupyter/long.signal.exe.kt
val overseer = LocalDistributedOverseer(
listOf(triangularFft, hammingFft),
threadsCount = 2,
partitionsCount = 2
)
val errors = overseer.eval(44100.0f)
.map { it.get().exception }
.filterNotNull()
.toList()
@asubb
asubb / wave-blog:using-jupyter:long.signal.kt
Created April 10, 2020 21:17
wave-blog/using-jupyter/long.signal.kt
//Specify the parameters of future calculations:
val windowSize = 801
val stepSize = 256
val fftSize = 1024
// Define a signal, windowed sum of sinusoids:
val signal = (880.sine() + 440.sine() + 220.sine())
.window(windowSize, stepSize)
// The first FFT applying the triangular window function:
@asubb
asubb / wave-blog:using-jupiter:long.imports.kt
Created April 10, 2020 21:12
wave-blog/using-jupiter/long.imports.kt
%use lets-plot
@file:Repository("https://dl.bintray.com/wavebeans/wavebeans")
@file:DependsOn("io.wavebeans:lib:0.0.3")
@file:DependsOn("io.wavebeans:exe:0.0.3")
@file:DependsOn("io.wavebeans:http:0.0.3")
import io.wavebeans.lib.*
import io.wavebeans.lib.io.*
import io.wavebeans.lib.math.*
@asubb
asubb / wave-blog:using-jupyter:short.signal.kt
Created April 10, 2020 21:01
wave-blog/using-jupyter/short.signal.kt
val o = (880.sine() + 440.sine() + 220.sine())
.trim(1000, MILLISECONDS)
val values = o.asSequence(44100.0f)
.drop(500)
.take(400)
.map { it.asDouble() }
.toList()
val values2 = o.asSequence(44100.0f)