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 › ESS hickups while loading soundfiles
Page Index Toggle Pages: 1
ESS hickups while loading soundfiles (Read 963 times)
ESS hickups while loading soundfiles
Feb 23rd, 2006, 3:07am
 
hi,
i'm trying to load a soundfile while playing another and i get dropouts.  even tried in separate threads (see below).  anyone know if this is possible.  i've used various soundfile lengths but always get the same hickups.  (need to use ess library as the files are mp3.)


//make sure you have 4 mono mp3 files called testsnd0.mp3, testsnd1.mp3, testsnd2.mp3, testsnd3.mp3 in data directory
//these files must be longer than dly seconds.  i tried with 5 second files and dly=2

import krister.Ess.*;

int dly= 2;    //delay for loading next mp3 in seconds
int numMp3= 4;
Mp3[] mp3s;
int mp3index= 0;    //currently playing mp3
int counter;    //for delaying loading next mp3 until after dly seconds

void setup() {
 size(400, 400, JAVA2D);
 framerate(12);
 counter= int(dly*framerate);
 noSmooth();
 Ess.start(this);
 mp3s= new Mp3[numMp3];
 for(int i= 0; i<numMp3; i++) {
   mp3s[i]= new Mp3();
 }
 loadNextMp3(0, true);    //load and autostart first mp3
}
void draw() {
 background(100);
 if(counter==0) {
   background(0);    //black flash when start loading thread
   loadNextMp3((mp3index+1)%numMp3, false);    //cycle
   counter--;
 } else if(counter>0) {
   counter--;
 }
}
void loadNextMp3(int index, boolean autostart) {
 new Mp3LoadThread("testsnd"+index+".mp3", index, autostart).start();
}
public class Mp3LoadThread extends Thread {    //thread for loading mp3s
 String mp3path;
 int index;
 boolean autostart;
 public Mp3LoadThread(String _mp3path, int _index, boolean _autostart) {
   super("mp3"+_index);
   mp3path= _mp3path;
   index= _index;
   autostart= _autostart;
 }
 public void run() {
   Mp3 mp3= mp3s[index];
   mp3.load(mp3path);
   mp3.isLoaded= true;
   println("loaded index "+index+" with "+mp3path);
   if(autostart) {
     mp3.play();
   }
 }
}
class Mp3 {    //class for loading mp3s, storing channels and current states
 Channel channel;
 boolean isPlaying;
 boolean isLoaded;
 Mp3() {
   channel= new Channel();
   isPlaying= false;
   isLoaded= false;
 }
 void load(String mp3path) {
   channel.loadSound(mp3path);
   channel.loadSamples();    //for level meters gui later
   isLoaded= true;
 }
 void play() {
   isPlaying= true;
   channel.play();
 }
 void free() {
   isPlaying= false;
   isLoaded= false;
 }
}
void channelDone(Channel ch) {
 int index= findChannel(ch);
 println("done playing channel index "+index);
 mp3s[index].free();
 mp3index= (index+1)%numMp3;    //cycle
 Mp3 newMp3= mp3s[mp3index];
 if(newMp3.isLoaded) {
   newMp3.play();
 } else {
   println("failed to keep up");
 }
 counter= int(dly*framerate);
}
int findChannel(Channel ch) {
 for(int i= 0; i<numMp3; i++) {
   if(mp3s[i].channel==ch) {return i;}
 }
 return -1;
}
public void stop() {
 Ess.stop();
 super.stop();
}
Re: ESS hickups while loading soundfiles
Reply #1 - Mar 24th, 2006, 2:24am
 
yea the same problem is causing me headaches too

whenever Ess is doing anything, it seems to halt PApplet.

i dont see any way around it :  /
Re: ESS hickups while loading soundfiles
Reply #2 - Apr 11th, 2006, 1:45am
 
could you send me a copy of the processing sketch and i'll add it to the pile of things to look at for the next rev? thanks! krister
Re: ESS hickups while loading soundfiles
Reply #3 - Sep 12th, 2006, 11:18pm
 
hi krister,
i just got back to this and still have the same problems.  there's a test sketch here... http://www.fredrikolofsson.com/temp/ess_loading_with_threads.zip
i'm on a mac osx.3.9 using ess r2 with jl1.0, mp3spi1.9.4 and tritonus_share in my library/ess folder.
anyway, many thanks for your lib.
Page Index Toggle Pages: 1