Skip to content

Instantly share code, notes, and snippets.

View multivac61's full-sized avatar
🎯
Focusing

multivac61 multivac61

🎯
Focusing
View GitHub Profile
# A script to remind me how to check if an
# array contains a zero. If it does
# we should mask it with some tiny number
from sys import float_info
epsilon = float_info.epsilon
# X is input variable, f.x. FFT
X[X == 0] = epsilon
def freq_from_ZCR(sig, fs):
# Find all indices right before a rising-edge zero crossing
indices = find((sig[1:] >= 0) & (sig[:-1] < 0))
crossings = interpolate(indices, sig)
return fs / np.mean(np.diff(crossings))
def freq_from_AC(sig, fs):
corr = np.correlate(sig, sig, mode='full')
corr = corr[corr.size/2:]
# Find the first low point
d = diff(corr)
# first point with pos.
start = find(d > 0)
def freq_from_FFT(sig, fs):
# Compute Fourier transform of windowed signal
N = len(sig)
windowed = sig * blackmanharris(N)
X = np.abs(np.fft.rfft(windowed))
# Find the peak and interpolate
i = np.argmax(abs(X)) # Just use this for less-accurate, naive version
X[X == 0] = epsilon # Circumvent division by 0
def freq_from_HPS(sig, fs):
N = len(sig)
windowed = sig * blackmanharris(N)
X = np.abs(rfft(windowed))
hps = X
n_harmonic_partials = 6
for h in range(2, n_harmonic_partials):
# downsample the spectra
dec = scipy.signal.decimate(X, h)
def freq_from_CEPS(sig, fs):
N = len(sig)
windowed = sig * blackmanharris(N)
spectrum = np.fft.rfft(windowed, fs)
spectrum[spectrum == 0] = EPSILON
log_spectrum = np.log(np.abs(spectrum))
ceps = np.fft.irfft(log_spectrum)
start = int(fs / HIGH_FREQ)
# swampme.sh
# Create a 16GB swap space in current file system
dd if=/dev/zero of=/var/myswap bs=1M count=16384
mkswap /var/myswap
swapon /var/myswap
echo "/var/myswap swap swap defaults 0 0" >> /etc/fstab
# Supercollider and jack2 install script
# made for Raspberry Pi 3
# run script as root?
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt-get update && apt-get upgrade
// A code snippet to show how one way to
// seperate incoming MIDI CC signals and the
// server side.
(
MIDIIn.connectAll;
a = Bus.control(s);
MIDIdef.cc(\cc_test, { |src, chan, num, value|
[src, chan, num, value, src.linexp(0, 127, 10, 10000)].postln;
// http://stackoverflow.com/questions/38515708
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char argv[]){
char *filename = "test.db";
int my_int = 42;
// First we open file and write to it