We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › speeding up process(sound and video)
Page Index Toggle Pages: 1
speeding up process(sound and video) (Read 441 times)
speeding up process(sound and video)
Mar 30th, 2008, 4:29pm
 
hello there, this is my first message on this board, so please forgive any errors i make etc. I am creating a project that captures sound and uses this to alter the image of a live input (web cam)using the video library and sonia

Here is the code-
-----------------------------------------------------------

import pitaru.sonia_v2_9.*;
import processing.video.*;

Capture cam;

void setup(){
 size(640,480);
 background(0);
   cam = new Capture(this, 640, 480);
   loadPixels();
 
 frameRate(10);
 Sonia.start(this);
 LiveInput.start(32);
 
}

void draw(){
 background(0);
 LiveInput.getSpectrum();
 
   for(int a=1;a<32;a+=1){
circleStrip(a*20, LiveInput.spectrum[a]);

   }
}

void circleStrip(int stripLoc, float spectrumData){
   
   for (int i = -20; i < height ; i+=20){
int j = stripLoc;
   
noStroke();

int intspectrumdata = int(spectrumData);
 
noStroke();

cam.read();
color d = cam.get(j, i);
 
 fill(d, 50);
 rectMode(CENTER);
rect (j, i , 30 + intspectrumdata, 30 + intspectrumdata);
   
   }
}
-----------------------------------------------------------

My major problem is that it i am only receiving an image every 7 seconds, and i would preferably have two every second, in order to speed it up i can use less channels (16 instead of 32), or use a faster computer, but i was wandering if anybody knew of a way to speed it up in other ways such as code structure, retaining the image quality,  any help would be greatly appreciated ,

many thanks

(i posted this message in the sound folder and the video folder, sorry if thats frowned upon, i wasn't sure which one to put the message in and am quite needy for the help, sorry again)
Re: speeding up process(sound and video)
Reply #1 - Mar 30th, 2008, 8:27pm
 
Try putting cam.read() after background(0).  You only need to read the cam once, then use that image for the circleStrips.  You were reading it 32 times.  Tongue

BTW, if you take out the frameRate call, you should be getting frame rates upwards of 30+ fps.
Re: speeding up process(sound and video)
Reply #2 - Mar 31st, 2008, 12:01am
 
Oh my days,
thats been bugging me for ages and now its working far faster,
your better than an iced gem,
thank you very much, because now i can use it live,
cheers
Re: speeding up process(sound and video)
Reply #3 - Mar 31st, 2008, 2:32am
 
Also, you could try taking out all of the stuff that doesn't need to be in the FOR loop (like setting the variables and setting noStroke). Might not make much difference at all, but doing those things once a frame has gotta be a bit better than doing them a whole bunch of times, right? Smiley
Re: speeding up process(sound and video)
Reply #4 - Mar 31st, 2008, 5:41am
 
cheers, that sounds about right, its all making a massive improvement, there one more thing, and that is that when the sound gets too loud it chokes the video, and makes it slow down, i'm not sure if theres a way of stopping that happening, but if anybody knows what the problem is or how to fix it that, tips would be ace,

thanks for all the help

adam
Page Index Toggle Pages: 1