Skip to content

Instantly share code, notes, and snippets.

View SpotlightKid's full-sized avatar

Christopher Arndt SpotlightKid

View GitHub Profile
@ingoogni
ingoogni / fftavx.nim
Created May 24, 2025 12:14
fft: stockham avx, cooly turkey, 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
moved to https://github.com/jean-emmanuel/lua_scripts/
@SpotlightKid
SpotlightKid / pmstring.dsp
Created August 6, 2024 11:26
A simple physical model of a guitar-like plucked string implemented in FAUST (Work in progress!)
declare name "PM String";
declare version "0.1";
declare author "Christopher Arndt";
declare license "MIT License";
declare description "A simple physical model of a guitar-like plucked string";
// Create a JACK/Qt app with:
//
// faust2jaqt -nvoices 6 -midi pmstring.dsp
@SpotlightKid
SpotlightKid / fbnfm_drumvoice.dsp
Last active November 19, 2024 13:42
A FAUST-based drum and percussion synth with three components: band-limited noise through a feedback delay, noise and FM
// NOTE: as-is, this does NOT work correctly with faust2lv2, since it does not support MIDI input via the "key" parameter.
// It does work with the FAUST web IDE and Faust Live, though.
declare name "FB / Noise / FM Drum Voice";
declare version "0.1";
declare author "Christopher Arndt";
declare license "MIT License";
declare description "A drum and percussion synth with three components: band-limited noise through a feedback delay, noise and FM";
@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
@amb
amb / fft.nim
Created May 12, 2022 12:43
Simple Nim FFT
# OTFFT library
# http://wwwa.pikara.ne.jp/okojisan/otfft-en/optimization1.html
# This is +20-50% improvement
const thetaLutSize = 2048
const thetaLut = static:
var arr: array[thetaLutSize, Complex[float]]
let step = 2.0*PI/float(thetaLutSize)
for k, v in mpairs(arr):
v = complex(cos(step * float(k)), -sin(step * float(k)))
@geraintluff
geraintluff / unit-range-reciprocal.hpp
Last active January 8, 2025 20:39
A map from [0-1] to an arbitrary range, specified using low/mid/high values. Pulled out from some Signalsmith Audio internal code.
class UnitRangeMapReciprocal {
double vMin, vTopFactor, vBottomFactor;
public:
UnitRangeMapReciprocal() : UnitRangeMapReciprocal(0, 0.5, 1) {}
UnitRangeMapReciprocal(double min, double mid, double max) {
vMin = min;
double k = (mid - min)/(max - mid);
vTopFactor = max*k - min;
vBottomFactor = k - 1;
}
@Michal-Szczepaniak
Michal-Szczepaniak / client.nim
Created October 20, 2021 18:17
Nim async UDP server discovery and TCP server connection
import asyncnet, asyncdispatch, nativesockets
proc discover(): Future[string] {.async.} =
let socket = newAsyncSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
socket.setSockOpt(OptReuseAddr, true)
socket.setSockOpt(OptReusePort, true)
socket.setSockOpt(OptBroadcast, true)
await socket.sendTo("255.255.255.255", Port(12346), $0b10)
var data = await socket.recvFrom(15)
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
<head>
<title><xsl:value-of select="/rss/channel/title"/> RSS Feed</title>
<meta charset="UTF-8" />
<meta http-equiv="x-ua-compatible" content="IE=edge,chrome=1" />
<meta http-equiv="content-language" content="en_US" />