Skip to content

Instantly share code, notes, and snippets.

@ingoogni
ingoogni / _iteroscillator.nim
Created June 11, 2025 07:30
Nim closure iterators for audio synthesis.
import math, sugar
import iterit
const
SampleRate {.intdefine.} = 44100
SRate* = SampleRate.float32
proc linOsc*[Tf, Tp: float or iterator:float](
@ingoogni
ingoogni / _lutsynth.nim
Last active June 12, 2025 09:02
Quarter sine wave look up table synth with various oscillators in Nim
import math
const
SampleRate {.intdefine.} = 44100
SRate* = SampleRate.float
LutSize = 256 # Quarter sine wave
Lut = static:
var arr: array[LutSize, float]
for i in 0..<LutSize:
let angle = (i.float / LutSize.float) * (PI / 2.0)
@ingoogni
ingoogni / _modal synthesis
Last active June 12, 2025 09:02
Nim Modal synthesis
Modal synthesis in Nim with a pool for modes, so one excite fast and they still properly decay. Cheesy bell, gong & mallet modes.
@ingoogni
ingoogni / fftavx.nim
Last active June 10, 2025 13:43
fft: stockham avx, Cooly Tukey, window functions
# FFT Stockham
# http://wwwa.pikara.ne.jp/okojisan/otfft-en/optimization1.html
# original source of scalar Nim version by "Amb" :
# https://gist.github.com/amb/4f70bcbea897024452d683b40d18be1f
# Timings
# === Scalar float64 ===
# FFT/IFFT test on 4096 points
@ingoogni
ingoogni / goertzelfiltergeneral.nim
Created May 24, 2025 12:11
Goertzel generalized filter & filter bank
import strutils
import math
import complex
const
SampleRate = 8000.0 # 8kHz
TargetFrequency = 941.0 # 941 Hz
FFTSize = 205
N = FFTSize # Block size
@ingoogni
ingoogni / _nimscripter_about.txt
Last active April 2, 2025 14:38
scripting in Nim with nimscripter
compile
> nim c -d:release -d:danger renderer.nim
to render image from prompt:
> renderer sincos.nims
Render a function to a grey scale image, using nimscripter https://github.com/beef331/nimscripter for realtime scriptable applications.
@ingoogni
ingoogni / circlespline2d.nim
Created January 19, 2025 16:40
Circle spline 2D in Nim
import vmath
import math
type
ColinearSegmentError* = object of Defect
Input2D = object
dir: Vec2 # tangent vector at first input knot
knot: seq[Vec2]
@ingoogni
ingoogni / 1_sqlite_table_with_history.ddl
Last active January 26, 2025 21:16
Table that keeps its own history, SQLite
/*
Database schema SQLite for a table that keeps its own history and
never deletes data.
On update, historic data is kept under a new id and references the original
creation id. The end of life timestamp (ts_eol) is set so a time line can be
built. The new data is used to update the data under the existing id.
On delete, nothing is deleted. Only the ts_eol timestamp is set to current.
*/
@ingoogni
ingoogni / sseClient.nim
Last active February 26, 2025 14:17
SSE Client Nim experiment Server Sent Events
# Compile:
# nim c --gc:orc --experimental:strictFuncs -d:ssl -d:nimStressOrc --import:std/httpcore sseClient.nim
# based on Harpoon https://github.com/juancarlospaco/harpoon
import std/[net, macros, strutils, times, json, httpcore, uri]
type
SSE = object
comment: string
@ingoogni
ingoogni / avxgoertzeloscbank.nim
Last active May 22, 2025 15:03
Goertzel, Rotating Vector vs. sin() Compare sine wave oscillators for speed and accuracy.
# Goertzel oscillator bank (scalar):
# (seconds: 208, nanosecond: 253406100)
# duration: 4440s samplerate: 44100 samples: 195804000
# 0.0000010635809590202449 seconds per sample @ 1000 oscillators
# Goertzel AVX oscillator bank:
# (seconds: 26, nanosecond: 403254200)
# duration: 4440s samplerate: 44100 samples: 195804000
# 0.00000013484532593818306 seconds per sample @ 1000 oscillators
# Speedup: 7.887414351371886x