Skip to content

Instantly share code, notes, and snippets.

@ingoogni
ingoogni / iteradsr.nim
Created June 18, 2025 10:20
ADSR in Nim (after Nigel Redmon)
# Original C++ code:
#
# Created by Nigel Redmon on 12/18/12.
# EarLevel Engineering: earlevel.com
# Copyright 2012 Nigel Redmon
#
# For a complete explanation of the ADSR envelope generator and code,
# read the series of articles by the author, starting here:
# http://www.earlevel.com/main/2013/06/01/envelope-generators/
#
@ingoogni
ingoogni / itersequencer.nim
Created June 18, 2025 07:44
iterative drum sequencer (deconstructed) in Nim.
import std/[math, random]
import iterit, iterkspercussion
const
SampleRate {.intdefine.} = 44100
SRate* = SampleRate.float
type
Trigger* = object
@ingoogni
ingoogni / iterkspercussion.nim
Last active June 19, 2025 12:19
Iterative Karplus-Strong percussion in Nim
import os, random, math
import iterit
const
SampleRate {.intdefine.} = 44100
SRate* = SampleRate.float
MaxKSDelay* = (SampleRate / 20.0).int #Hz delay line length: SampleRate / Frequency
type
Ticker* = object
tick: uint
@ingoogni
ingoogni / ksiter.nim
Last active June 19, 2025 12:20
Iterative Karplus Strong in Nim
import math, random
import iterit
const
SampleRate {.intdefine.} = 44100
SRate* = SampleRate.float
MaxKSDelay* = (SampleRate / 20).int #Hz delay line length: SampleRate / Frequency
proc iterKS[Tf: float or iterator:float](
@ingoogni
ingoogni / foogle.nim
Last active June 14, 2025 06:47
Nim Foogle filter
# https://www.musicdsp.org/en/latest/Synthesis/11-weird-synthesis.html
# "Karplus-Strong-inspired comb filter effect?"
# Processes incoming audio continuously, not just initial excitation
import std/[math, random]
import iterit
import iteroscillator
const
SampleRate {.intdefine.} = 44100
@ingoogni
ingoogni / _iteroscillator.nim
Last active June 25, 2025 06:37
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