Skip to content

Instantly share code, notes, and snippets.

View analoq's full-sized avatar

A. P. Matthews analoq

  • Southern California
View GitHub Profile
@analoq
analoq / songs_keys_bpm.py
Last active April 19, 2022 15:16
Find songs with keys that are reasonably in tune with their tempo, from Billboard/Spotify dataset.
"""
Find songs with keys that are reasonably in tune (less than 1 semitone apart)
with their tempo. Uses dataset from:
https://data.world/kcmillersean/billboard-hot-100-1958-2017
"""
from math import sqrt
import numpy as np
@analoq
analoq / rando.cpp
Created February 25, 2022 04:53
RP2040 program which echos MIDI over UART but creates a random patch event before each note.
#include <stdio.h>
#include <stdlib.h>
#include "hardware/gpio.h"
#include "hardware/uart.h"
#include "hardware/irq.h"
#include "../lib/lcd.hpp"
// globals
#include <SD.h>
File lg;
void setup()
{
// Set MIDI baud rate
Serial1.begin(31250);
Serial.begin(9600);
Sequencer Min (us) Max (us) Range (us) Std. Dev (us)
MC50 122192 128088 5896 941
Ubuntu/Reaper 123340 126302 2962 614
E6400 Ultra 123794 124972 1178 507
MPC2500 122850 127018 4168 475
Surface/Reaper 123940 125984 2044 427
BeatStep Pro 119712 125002 5290 343
DOS/Voyetra 123800 125856 2056 279
QY100 124572 125492 920 231
macOS/Reaper 124602 125106 504 205
import sys
import wave
import struct
THRESHOLD = 0.3
DECAY = 0.100
def getsamples(w):
assert(w.getnchannels() == 1)
assert(w.getsampwidth() == 3)
import random
class hlist(list):
def __hash__(self):
return ','.join(self).__hash__()
def IPMotif(text):
d = {}
motif = hlist()
@analoq
analoq / puckette_3_5.py
Created June 7, 2014 06:29
Miller Puckette's Theory and Technique of Electronic Music. Chapter 3, Exercise 5 graphical solution.
import math
from pylab import *
def f(t):
omega = 200.0 * 2 * math.pi
return math.fmod(omega*t, 2*math.pi)/(2*math.pi)
def g(t):
omega = 300.0 * 2 * math.pi
return math.fmod(omega*t, 2*math.pi)/(2*math.pi)
@analoq
analoq / puckette_3_8.py
Last active January 4, 2016 05:09
Miller Puckette's Theory and Technique of Electronic Music. Chapter 3, Exercise 8 graphical solution.
import math
from pylab import *
R = 44100
f = 44000
def y(t):
value = 0.0
for n in range(1, 100):
# convert f*n to angular speed
@analoq
analoq / tapb_1_2_6.c
Created January 9, 2011 03:35
The Audio Programming Book: Exercise 1.2.6 solution
#include <stdio.h>
#include <math.h>
int main()
{
const double semitone_ratio = pow(2.0, 1.0/12.0);
const double c5 = 220.0 * pow(semitone_ratio, 3);
const double c0 = c5 * pow(0.5, 5);
double frequency, fracmidi, difference;
int midinote;