09 July 2005

I Got Rhythm

For all those who want to play a musical instrument and a) have a copy of matlab, but b) have no ability to keep a beat (surely these must go together often enough) here is some useful code.
function metronome(persec)
blip = sin(1:82 * 2 * pi * 1000 / 8192);
while (1)
   soundsc(blip);
   pause(60/persec);
end
And in stereo!
function metronome2(persec)
len = 500;
blip = sin((1:len) * 2 * pi * 1000 / 8192)';
blip1 = [blip zeros(len,1)];
blip2 = [zeros(len,1) blip];
while (1)
    sound(blip1);
    pause(60/persec);
    sound(blip2);
    pause(60/persec);
end
Matlab is good for tuning too - all you need to know is that a violin's A is 440Hz and a fifth (interval between violin strings) is seven half-steps, so the frequencies are separated by 2^(7/12).

3 comments:

ahren said...

you and ilya should start using matlab to build effects.

can the signal be processed by matlab quickly enough to be real-time? (i guess that depennds on how you process it, but you know what i mean)

i've delved into the hardware side of effects a tiny bit and have a box of electronic components-- we could actually build effects boxes if we ever came up with something new and cool.

also, i saw a band play, where the chick played electric violin-- you need one of those.

aram harrow said...

yeah, i definitely need to do electric violin sometime.

realtime effects processing is tricky. jeff did a realtime quantizer, which you can read about at
http://bea.st/text/iq/

(he says that he'd like to know if you use it for anything - follow links on that page for his contact info.)

also, ben made a hardware DSP box and put some descriptions of it at
http://www.dsperado.com/chiclet.

ahren said...

i have a quantizer on my drum machine, which can be useful for making loops, though its smallest "basket" is 1/32, which doesn't quite do it for me, since i like to use the tablas and bongos and make a bunch of really quick successive strikes that straddle around the primary downbeat...

... a further problem i have is that i run my drum machine through my pedal controlled looper, then to the amp, so if i have a drum loop and a loop on the pedal, and want to line them up, it's hard to do it perfectly, because i'm hitting 2 buttons at once (twice), and with a small margin for error i'm bound to miss by enough to make it noticable more often than i'd like.

it seems like a quantizer could somehow be used to reconcile the difference between the 2 devices, and get rid of the error caused by the stupid human.