Skip to content

Instantly share code, notes, and snippets.

import librosa
y, sr = librosa.load("YoutubeIntro.m4a")
hop = 512
X = librosa.feature.mfcc(y=y[0:sr*10], sr=sr, hop_length=hop, n_mfcc=13)
# Perform a sliding window embedding of length 20 to emphasize diagonals
X = librosa.feature.stack_memory(X, n_steps=20).T
D = get_distmat(X)
def get_distmat_psd(D, sr):
"""
Compute the power spectral density of the diagonals of
a distance matrix
Parameters
----------
D: ndarray(N, N)
Distance matrix
sr: int
import cv2
cap = cv2.VideoCapture("Circle.webm")
ret = True
frames = []
while ret and cap.isOpened():
ret, frame = cap.read()
if ret:
frames.append(frame / 255.0)
frames = np.array(frames)
print(frames.shape)
def get_distmat(X, eps=1e-7):
"""
A fast method for computing the distance matrix of a Euclidean
point cloud
Parameters
----------
X: ndarray(N, d)
Point cloud
eps: float
N = 101
ts = 2*np.pi*(np.linspace(0, 1, N+1))[0:N]
X = np.zeros((N, 2))
X[:, 0] = np.cos(ts)
X[:, 1] = np.sin(2*ts)
X2 = np.linspace(2, 4, 50)
X2 = X2[:, None]*np.ones((1, 2))
X = np.concatenate((X, X2), axis=0)
# Find two points that achieve the diameter
i1, j1 = np.unravel_index(np.argmax(D), (N, N))
# Find the closest pair of points are at least 5 apart from the diagonal
I, J = np.meshgrid(np.arange(N), np.arange(N), indexing='ij')
i2, j2 = np.unravel_index(np.argmin(D + np.max(D)*(J - I < 5)), (N, N))
N = X.shape[0]
d = X.shape[1]
D = np.zeros((N, N))
for i in range(N):
Xi = X[i, :]
for j in range(N):
Xj = X[j, :]
D[i, j] = np.sqrt(np.sum((Xi - Xj)**2))
N = 101
ts = 2*np.pi*(np.linspace(0, 1, N+1))[0:N]
X = np.zeros((N, 2))
X[:, 0] = np.cos(ts)
X[:, 1] = np.sin(2*ts)
@ctralie
ctralie / audioioworklet.js
Last active August 8, 2025 16:39
Messy Prototype for Mp3 Audio Streaming To Server As Base64
class AudioIOWorklet extends AudioWorkletProcessor {
constructor() {
super();
this.port.postMessage({"action":"setSampleRate", "sampleRate":sampleRate});
}
process(inputList, outputList, parameters) {
const input = inputList[0][0]; // First channel of the first stream
const samples = new Int16Array(input.length);
for (let i = 0; i < input.length; i++) {
samples[i] = Math.round(32767*input[i]); // We're expecting 16-bit signed integers for the samples
import torch
import numpy as np
import matplotlib.pyplot as plt
offsets = [torch.zeros(3), torch.tensor([1, 0, 0]), torch.tensor([1, 0, 0]), torch.tensor([1, 0, 0])]
Rs = [torch.eye(3)[:, 0:2] for _ in range(len(offsets))]
for i in range(len(Rs)-1):
Rs[i] = Rs[i].requires_grad_()
def get_positions(offsets, Rs):