Skip to content

Instantly share code, notes, and snippets.

View smoge's full-sized avatar

mago smoge

View GitHub Profile
@smoge
smoge / chain.cpp
Last active July 21, 2024 16:15
vectorized large chain of "ugens" with aligned memory (xsimd) - test
#include <algorithm>
#include <cassert>
#include <cmath>
#include <concepts>
#include <iostream>
#include <memory>
#include <random>
#include <span>
#include <sys/types.h>
#include <vector>
@smoge
smoge / custom.css
Last active July 19, 2024 11:21
scdoc-custom.css
:root {
--color-bg: #1e1e1e;
--color-fg: #d4d4d4;
--color-fg-100: #555555;
--color-fg-200: #646464;
--color-fg-300: #dcdcdc;
--color-fg-400: #9cdcfe;
--color-input-fg: #d4d4d4;
--color-input-bg: #3c3c3c;
--color-link: #3794ff;
@smoge
smoge / checkPoles.hs
Created July 6, 2024 13:40
Check for IIR Bad Coefficients
import Data.Complex (Complex((:+)))
data IIRParams = IIRParams
{ b0 :: Float
, b1 :: Float
, b2 :: Float
, a0 :: Float
, a1 :: Float
, a2 :: Float
}
@smoge
smoge / Check_coeffs.cpp
Last active June 24, 2024 23:53
This should produce the expected normalized polynomial coefficients, avoiding bad coefficients for filters (adapting from scipy BAD COEFFICIENTS)
#include <iostream>
#include <vector>
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ranges>
bool allClose(const std::vector<double>& vec, double value, double rtol) {
return std::ranges::all_of(vec, [=](double v) { return std::abs(v - value) <= rtol; });
@smoge
smoge / filter-nth-order.cpp
Last active June 23, 2024 18:54
nth-order Recursive Infinite Impulse Response Filter - realtime-safe 64bit internal processing, change coeffs (and filter order) at runtime
/*
*
*
* - `nth_order_system` Class: Manages the nth-order filter, including its
* internal state and coefficients.
* - `compute_sample`: Computes a single output sample based on the input and
* current state using Direct Form II Transposed structure.
* - `set_coefficients`: Sets new filter coefficients.
* - `reset`: Resets the internal state variables.
*
@smoge
smoge / autosync.sh
Created June 12, 2024 13:45
autosync.sh
#!/bin/bash
set -e
TARGETDIR="$HOME/org/"
stderr () {
echo "$1" >&2
}
@smoge
smoge / scipy_faust-iir.py
Created June 11, 2024 14:00
scipy_faust-iir.py
import numpy as np
from scipy.signal import iirdesign, freqz
import matplotlib.pyplot as plt
# Define the desired frequency response
def desired_frequency_response(w):
return np.abs(np.sin(2 * np.pi * w) + 0.5 * np.cos(4 * np.pi * w))
# Frequency points
freqs = np.linspace(0, 1, 8000)
@smoge
smoge / llvm-gen-test.hs
Last active June 11, 2024 11:25
llvm-gen-test.hs
{-
import("stdfaust.lib");
freq = hslider("freq", 440, 20, 20000, 0.01);
process = os.osc(freq) <: _, _;
faust -lang llvm sine_wave.dsp -o sine_wave.ll
-}
@smoge
smoge / sum7.cpp
Last active May 21, 2024 10:50
sum7.cpp
#include <algorithm>
#include <chrono>
#include <cmath>
#include <execution>
#include <iostream>
#include <numeric>
#include <random>
#include <stdexcept>
#include <vector>
@smoge
smoge / sum6.cpp
Last active May 21, 2024 10:23
sum6.cpp
#include <algorithm>
#include <chrono>
#include <execution>
#include <iostream>
#include <numeric>
#include <random>
#include <vector>
class RandomNumberGenerator {
public: