This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
NewerOlder