|
Author |
Topic: quick little audio utility script (Read 818 times) |
|
bsr
|
quick little audio utility script
« on: Aug 10th, 2004, 3:30pm » |
|
quick little script i made while writing something else, i needed to see the values held in the sample array. might be useful for someone. or not. Code: // bpm only makes sense with loops one bar in length Sample mySample; float[] data; int playHead; int a; int b; int aa; void setup() { background(255); fill(100); BFont metaBold; metaBold = loadFont("Meta-Bold.vlw.gz"); textFont(metaBold, 14); size(100,680); Sonia.start(this); mySample = new Sample("kissed.wav"); data = new float[mySample.getNumFrames()]; //creates a new array the length of the sample mySample.read(data); mySample.repeat(); // loop the sample } void loop(){ if (a == 100){ a = 1; aa=1; background(255); line (0, 100, 100, 100); int totalFrames = mySample.getNumFrames(); float len = totalFrames/44100; int bpm = int(len*60); playHead = mySample.getCurrentFrame(); text("frames :" + totalFrames, 2, 115); text("seconds :" + len, 2, 125); text("bpm :" + bpm, 2, 135); text("start frame:" + playHead, 2, 145); } a = a + 1; text(data[mySample.getCurrentFrame()], b, 165+(aa*10)); aa = aa+1; if (aa == 50){ aa = 1; if (b == 50){ b = 2; }else{ b = 50; }} stroke(abs(1000*data[mySample.getCurrentFrame()])); line (a,50, a, 50+(150*(data[mySample.getCurrentFrame()]))); } // safely stop the Sonia engine upon shutdown. public void stop(){ Sonia.stop(); super.stop(); } |
|
|
« Last Edit: Aug 10th, 2004, 3:31pm by bsr » |
|
http://hippocamp.net
|
|
|
bisceglie
|
Re: quick little audio utility script
« Reply #1 on: Aug 17th, 2004, 7:00pm » |
|
hey, i modified your bpm script to work with 2 bar samples, and messed with changing the rate...this upset the math somehow and the calculations got scewed...any ideas?
|
|
|
|
bsr
|
Re: quick little audio utility script
« Reply #2 on: Aug 17th, 2004, 10:02pm » |
|
hmm could you post the code? the code that handles the bpm is these three lines: int totalFrames = mySample.getNumFrames(); float len = totalFrames/44100; int bpm = int(len*60); a 44.1 sample has 44100 samples per second, so dividing the total number of samples by 44100 gives you the length of the sample in seconds. the bpm is calculated by multiplying this by 60. 1 bar = 2 seconds. 2 seconds * 60 gives 120 bpm. for a 2 bar sample you should just be able to change the 60 for a 30.
|
« Last Edit: Aug 17th, 2004, 10:03pm by bsr » |
|
http://hippocamp.net
|
|
|
|