We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, for a party im making a music machine. With the machine you can play 5 different speeds of music. Its controlled with mousebuttons. And it uses lights on an arduino to indicate at which speed it is currently at.
Somehow it does some weird things. Sometimes it starts in the middle of a song and only plays a few seconds. Sometimes it starts a few songs fast after eachother (without the mouse being clicked) and then crashes with just a java issue. Sometimes it crashes at the end of a song and gives this error:
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (0x20474343), pid=27360, tid=0x0000000000007394
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [KERNELBASE.dll+0x17788]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
I cant seem to find out what is doing it, because im not exactly sure how the sound library works.
The code:
import processing.serial.*;
import processing.sound.*;
Serial myPort;
SoundFile file;
int x = 1;
String song ="Slow";
int Durr = 10000;
int m = 0;
int millizero=0;
int low = 10;
int high = 20;
String holder="Medium";
void setup() {
size(1000, 800);
background(255,255,0);
printArray(Serial.list());
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
file = new SoundFile(this,"Medium100.wav");
file.play();
}
void draw() {
if(millis() > (Durr*1000-2000)){
file.stop();
String newsong=holder+int(random(low,high))+".wav";
file = new SoundFile(this,newsong);
file.play();
Durr=int(file.duration());
millizero=millis();
}
}
void mousePressed() {
if (mouseButton == LEFT) {
if (x == 1) {
file.stop();
String str1 ="Slow"+int(random(100,199))+".wav";
println(str1);
myPort.write('1');
file = new SoundFile(this,str1);
file.play();
Durr=int(file.duration());
println(Durr);
high= 199;
low=100;
millizero=millis();
}
else if (x==2){
file.stop();
String str2 ="Mediumslow"+int(random(100,255))+".wav";
println(str2);
myPort.write('2');
file = new SoundFile(this,str2);
file.play();
Durr=int(file.duration());
println(Durr);
high= 255;
low=100;
millizero=millis();
}
else if (x==3){
file.stop();
String holder ="Medium";
String str3 ="Medium"+int(random(100,283))+".wav";
myPort.write('3');
println(str3);
file = new SoundFile(this,str3);
file.play();
println(file.duration() +"seconds");
Durr=int(file.duration());
println(Durr);
high= 283;
low=100;
millizero=millis();
}
else if (x==4){
file.stop();
String str4 ="Mediumfast"+int(random(100,254))+".wav";
println(str4);
myPort.write('4');
file = new SoundFile(this,str4);
file.play();
Durr=int(file.duration());
println(Durr);
high= 254;
low=100;
millizero=millis();
}
else if(x==5){
file.stop();
String str5 ="Fast"+int(random(100,161))+".wav";
println(str5);
myPort.write('5');
file = new SoundFile(this,str5);
file.play();
Durr=int(file.duration());
println(Durr);
high= 161;
low=100;
millizero=millis();
}
}
else if (mouseButton == RIGHT) {
if(x < 5){
x++;
}
else {
x=5;
}
}
else if (mouseButton == CENTER){
if(x > 1){
x--;
}
else {
x=1;
}
}}
Answers
that code appears to need several hundred wav files that we don't have.
it could also do with indenting nicely - ctrl-t in the editor.
this will play a file once. if you stop and start it, calling play again may continue from the current position, which may not even be valid for the new file. try specifying the position to play from.
what's this for? you never check millizero