Skip to content

Instantly share code, notes, and snippets.

@ingoogni
ingoogni / box.nim
Last active May 2, 2026 11:36
relay raytracer nim
# shapes/box.nim
# Axis-aligned box — slab method intersection.
# params layout: [minx, miny, minz, maxx, maxy, maxz]
#
# Standardised shape file interface:
# intersectBox*(params, ray) : HitResult
# bboxBox*(params) : BBox
# box*(corner1, corner2, matId): ShapeSpec
import ../types
@ingoogni
ingoogni / julian.nim
Last active March 31, 2026 08:06
julian day and SPA (solar position) in Nim
import std/[times]
# https://en.wikipedia.org/wiki/Julian_day
type
JulianDay* = object
julianDay*: int
julianDayfraction*: float
@ingoogni
ingoogni / goertzelfiltergeneral.nim
Last active March 25, 2026 13:56
Nim Goerzel filters
import strutils
import math
import complex
const
SampleRate = 8000.0 # 8kHz
TargetFrequency = 941.0 # 941 Hz
FFTSize = 205
N = FFTSize # Block size
@ingoogni
ingoogni / audiobase.nim
Created October 14, 2025 15:43
type for audio in Nim
import std/[math]
#import emitters
template fromTyp(typ, base: typedesc) =
proc `$`*(x: typ): string {.borrow.}
proc `+`*(a, b: typ): typ {.borrow.}
proc `-`*(a, b: typ): typ {.borrow.}
proc `*`*(a: typ, b: base): typ {.borrow.}
proc `*`*(a: base, b: typ): typ {.borrow.}
@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 July 16, 2025 07:53
Nim closure iterators for audio synthesis.
import math, sugar
import iterit
const
SampleRate {.intdefine.} = 44100
SRate* = SampleRate.float32
InvRate* = 1.0 / SRate