Skip to content

Instantly share code, notes, and snippets.

@rjhall
Last active December 18, 2015 10:49
Show Gist options
  • Save rjhall/5771048 to your computer and use it in GitHub Desktop.
Save rjhall/5771048 to your computer and use it in GitHub Desktop.
library(tuneR);
rate = 24000;
width = 6000;
play_vec = function(v) {
wnew = Wave(v * 32760/max(abs(v)), right = numeric(0), samp.rate = rate, bit = 16);
play(wnew, '/Users/rhall/Downloads/playRWave');
}
load_track = function(name) {
w = readWave(name);
x = w@left[1:(floor(length(w@left)/width)*width)];
return(t(matrix(data=x, nr=width, nc=length(x) / width)));
}
M = load_track("dubstep24k.wav")
n = dim(M)[1]
p = dim(M)[2]
x = rep(0, n)
for(i in 0:16) {
x = x + 2^i * (M %*% rnorm(p) < 0)
}
Y = matrix(data = 0, nr = 1000, nc = p)
state = x[50]
for(i in 1:1000) {
ind = which(x == state);
if(length(ind) == 1){
Y[i,] = M[ind,]
state = x[ind + 1]
} else {
Y[i,] = colMeans(M[ind,])
state = sample(x[ind+1], 1)
}
}
play_vec(as.vector(t(Y)))
@rjhall
Copy link
Author

rjhall commented Jun 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment