I have been bombarding this post with many questions and I’m sorry that I have to rely so much on the help of you guys, I may assure that everything I’m asking it took me at least 1-2 hours of attempt and failure by myself until the point that I realized i better ask people who know more than me, that being said, my objective is the following
SOUND PLAYED #TIMES DECIDED BY ACCELERATION
ACCELERATION+ AMOUNT OF TIMES +
ACCELERATION- AMOUNT OF TIMES -
my issue is that I’m able to control it through the acceleration, but the amount of times played is too many, would it be possible to limit the number of times played for a given amount of times ( for example every 500 milliseconds or 1000 milliseconds) again thank you for your time, and i hope one day my coding skills are high enough to either give you guys the help back , or to help others who need it, thanks in advance!.
import processing.sound.*;
float x;
float playbackSpeed;
float x_po, pr_x, pa_x, x_d;
SoundFile soundfile;
Delay delay;
float currTime, prevTime, dt, velocity = 1,sound_time;
void setup() {
size(640, 360);
background(255);
soundfile = new SoundFile(this, "sound_0.mp3");
currTime = prevTime = millis();
delay = new Delay(this);
delay.process(soundfile,10);
delay.time(10);
//soundfile.loop();
}
void draw() {
//ACCELERATION TEST CODE//
background(255);
x_po=mouseX;
x_d = abs((pa_x-x_po));
println("x_po = "+x_po);
println("pa_x = "+ pa_x);
println("x_d = "+x_d);
pa_x = x_po;
println("");
currTime = millis();
if (x_d != 0) {
dt = abs(prevTime-currTime);
} else if (x_d == 0) {
dt = 0.1;
}
println("currTime"+currTime);
println("prevTime"+prevTime);
println("dt ="+dt);
velocity =x_d/(dt/1000);
println("Velocity= "+velocity);
prevTime = currTime;
float velocity_c = map(velocity, 0, 250,0,100);
velocity_c = constrain(velocity_c, 0,100);
println("velocity_c"+velocity_c);
fill(255, 0, 0);
ellipse(x_po, height/2, 45, 45);
println("");
x = width/10;
if (x_d <= 20) {
if (velocity_c >= 15) {
playbackSpeed = 0.9;
fill(0, 255, 0, 30);
rect(0, 0, x, height, 25);
soundfile.rate(playbackSpeed);
soundfile.play();
} else if (velocity_c >= 15 && velocity_c < 50) {
playbackSpeed = 1.5;
fill(255, 0, 0, 30);
rect(x, 0, x, height, 25);
soundfile.rate(playbackSpeed);
}
/* } else if (velocity_c >= 20 && velocity_c < 30) {
playbackSpeed = 3;
fill(0, 0, 255, 30);
rect(x*2, 0, x, height, 25);
soundfile.rate(playbackSpeed);
} else if (velocity_c >= 30 && velocity_c < 40) {
playbackSpeed = 4;
fill(255, 0, 0, 30);
rect(x*3, 0, x, height, 25);
soundfile.rate(playbackSpeed);
} else if (velocity_c >= 40 && velocity_c < 50) {
playbackSpeed = 5;
fill(0, 255, 0, 30);
rect(x*4, 0, x, height, 25);
soundfile.rate(playbackSpeed);
} else if (velocity_c >= 50 && velocity_c < 60) {
playbackSpeed = 6;
fill(0, 0, 255, 30);
rect(x*5, 0, x, height, 25);
soundfile.rate(playbackSpeed);
} else if (velocity_c >= 60 && velocity_c < 70) {
playbackSpeed = 7;
fill(255, 0, 0, 30);
rect(x*6, 0, x, height, 25);
soundfile.rate(playbackSpeed);
} else if (velocity_c >= 70 && velocity_c < 80) {
playbackSpeed = 8;
fill(0, 255, 0, 30);
rect(x*7, 0, x, height, 25);
soundfile.rate(playbackSpeed);
} else if (velocity_c >= 80 && velocity_c < 90) {
playbackSpeed = 9;
fill(0, 0, 255, 30);
rect(x*8, 0, x, height, 25);
soundfile.rate(playbackSpeed);
} else if (velocity_c >= 90 && velocity_c < 100) {
playbackSpeed = 10;
fill(255, 0, 0, 30);
rect(x*9, 0, x, height, 25);
soundfile.rate(playbackSpeed);
}
*/
}
//FINNISH//
}