FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Sound
(Moderators: pitaru, REAS)
   wavs,fullscreen and threads
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: wavs,fullscreen and threads  (Read 768 times)
MrHunt

Email
wavs,fullscreen and threads
« on: Nov 21st, 2004, 3:07pm »

I am still implementing my project and I came to a point where I need to quit sonia and processing and go on java maybe.
Here are my latest problems any suggestions:
 
First I wrote a code that play wav files using threads.However there are still some minor timing problems.I don't imagine anything beyond threads.Is there anyone who thinks if I use java same problem will occur?
 
Second I used the fullscreen code that is given in processing discourse.And that reaaly made my code work very unscynchronized.Is there a way to use full screen and not to lose performance.
 
 
Third,the first thread just fails to start at the time it should start.Why is that?I just solve that problem just associating the first thread with a silent wav.
 
for last my code for those who want to look at:
------------------------------------------------------
 
 
int fileno=8;
Ses[] sesler=new Ses[fileno+1];
Thread t[] = new Thread[fileno+1];
 
BFont font;
 
 
int[] bpm= {1600,400,400,400,800,800,200,200,300};
 
 
//------------------------------------------------
 
//----------------------------------------------------------------------  
 
static public void main(String args[]){
 
  try{
     
    Frame frame = new Frame();
    Class c = Class.forName("play_multithread2");
    BApplet applet = (BApplet) c.newInstance();
    applet.init();
    applet.start();
     
    GraphicsDevice gd= GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice ();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
     
    frame.setUndecorated(true);
    frame.setBackground(Color.black);
    frame.setLayout(new GridBagLayout());
    frame.add(applet);
    frame.pack();
     
     
    if(gd.isFullScreenSupported()){
 gd.setFullScreenWindow(frame);
     
    }
    if(gd.isDisplayChangeSupported()){
 gd.setDisplayMode(new DisplayMode(applet.g.width,applet.g.height,32,0));
    }
     
    frame.setLocation(0,0);
    frame.show();
    applet.requestFocus();
     
     
    frame.addWindowListener(new WindowAdapter(){public void windowClosing  (WindowEvent e){
 System.exit(0);
 }});
 
  }
  catch (Exception e){
    e.printStackTrace();
    System.exit(1);
  }
   
 
}
void setup() {  
  ellipseMode(CENTER_DIAMETER);
  size(1400,1050);
  font = loadFont("BauerBodoni.vlw.gz");
  textFont(font,20);
   
//----------------------------------------------
  Sonia.start(this);
   
for (int i=0;i<=fileno;i++){
   
    sesler[i] = new Ses(i*40,120,bpm[i],i);
 
  }
 
  for(int i=0;i<=fileno;i++){
    t[i] = new Thread(sesler[i]);
   
  }
 
 for(int i=0;i<=fileno;i++)
  t[i].start();
   
   
     
}
void loop(){
    background(255,255,255);
    for(int i=1;i<=fileno;i++){
 sesler[i].draw();
 sesler[i].update();
     
     
    }
 
 
 
}
 
 
public void stop(){      
   Sonia.stop();      
   super.stop();    
 
}  
 
 
//////////////////////////////////////////////
 
 
class Ses implements Runnable{
////////////////////////////7
 
 
 
///////////////
int starttime=0;
int x,y;
int rad,low_rad;
int dtime ;
Sample _sample;
boolean _draw;
float volumerate;
  Ses(int x1,int y1,int dtime1,int fname){
    x=x1;
    y=y1;
    dtime=dtime1;
    low_rad=10*(dtime1/100);
     rad=low_rad;
    _sample= new Sample(fname + ".wav");
   
    _draw=false;
    volumerate=1.0;
  }
 
 
 public void draw(){
   if(_draw){
     fill(0,0,0);
     ellipse(x,y,rad,rad);
     fill(0,0,0);
     text(dtime + "." ,x,y);
   }
 
 
 }
 public void update(){
   if(_draw)
     rad++;
 }
 public void run(){
   delay(starttime);
   int next=starttime;
   _draw=true;
   while (true){
     
     _sample.play();
     rad=low_rad;
     next += dtime;
     int now=millis();
     delay(next-now);
     
     //repaint();
   }
 
 
 }
 
 
 
 
 }
 
Pages: 1 

« Previous topic | Next topic »