The piece that I'm working on is designed so that certain sounds are played depending on a sonic range finder input. My current problem is that I'm not sure how prevent overlaying and letting one sound file finish before starting another sound file begins. Does anyone have advice on how to go about this?
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.AudioSample.*;
import processing.serial.*;
Minim minim;
AudioSample [] sounds = new AudioSample [3];
// width and height should be set here
int xWidth = 600;
int yHeight = 600;
// set framerate
int fr = 24;
// set up the display items you want by choosing true
boolean bck = true;
boolean grid = true;
boolean g_vert = true;
boolean g_horiz = true;
boolean g_values = true;
boolean output = true;
// these variables are for the serial port connection object
Serial port;
String portname = "COM8"; // find the name of your serial port in your system setup!
int baudrate = 9600; // set baudrate here
int value; // variables used to store value from serial port
String buf=""; // String buffer to store serial values
int value1; // value1 is the read value
// the serial event function takes the value of the event and store it in the corresponding variable
void serialEvent(int serial){
if(serial!=10) {
buf += char(serial);
} else {
//extract the value from the string 'buf'
buf = buf.substring(1,buf.length());
//cast the value to an integer
value1 = int(buf);
buf="";
}
}
// setup initializes displayItems and serial port objects
void setup(){
size(500, 400);
frameRate(fr);
minim = new Minim(this);
sounds [0] = minim.loadSample("sound0.mp3");
sounds [1] = minim.loadSample("sound1.mp3");
sounds [2] = minim.loadSample("sound2.mp3");
port = new Serial(this, portname, baudrate);
println(port);
}
void createSounds(){
//////////////////////////////////////////////
//closest to arduino 4
//Adding constraints to keep the circle within the framesize