Hi,
I wrote a program with which I can record 6 different sounds, save them and play them on demand.
If I play them together and for a while, processing becomes slower and I get an error message:
Code:Exception in thread "Animation Thread" java.lang.NullPointerException
at ddf.mimin.javasound.JSMinim.getAudioInputStream(JSMinim.java:543)
at ddf.mimin.javasound.JSMinim.getAudioSample(JSMinim.java:285)
at ddf.minim.Minim.loadSample(Minim.java:210)
at Sampler_1538.keyReleased(Sampler_1538.java:156)
at processing.core.PApplet.handleKeyEvent(PApplet.java:1756)
at processing.core.PApplet.dequeueKeyEvents(PApplet.java:1735)
at processing.core.PApplet.handleDraw(PApplet.java:1437)
at processing.core.PApplet.run(PApplet.java:1327)
at java.lang.Thread.run(Thread.java:637)
Here's the programs code:
Code:// SELF-SAMPLER
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioInput in;
AudioRecorder recorder1;
AudioRecorder recorder2;
AudioRecorder recorder3;
AudioRecorder recorder4;
AudioRecorder recorder5;
AudioRecorder recorder6;
AudioSample sound1;
AudioSample sound2;
AudioSample sound3;
AudioSample sound4;
AudioSample sound5;
AudioSample sound6;
int pad = 0;
void setup() {
background(0);
size(600, 400);
// Line In einfangen
minim = new Minim(this);
in = minim.getLineIn(Minim.STEREO, 2048);
recorder1 = minim.createRecorder(in, "sound1.wav", true);
recorder2 = minim.createRecorder(in, "sound2.wav", true);
recorder3 = minim.createRecorder(in, "sound3.wav", true);
recorder4 = minim.createRecorder(in, "sound4.wav", true);
recorder5 = minim.createRecorder(in, "sound5.wav", true);
recorder6 = minim.createRecorder(in, "sound6.wav", true);
// Pads farbig
noStroke();
fill(255, 85, 0);
rect(0, 0, 200, 200);
fill(255, 128, 66);
rect(200, 0, 200, 200);
fill(254, 170, 128);
rect(400, 0, 200, 200);
fill(255, 150, 0);
rect(0, 200, 200, 200);
fill(254, 180, 73);
rect(200, 200, 200, 200);
fill(254, 203, 128);
rect(400, 200, 200, 200);
// Anweisung in print-Fenster
println("Zum Aufnehmen muss der Mauszeiger über einem der 6 Pads schweben.");
println("r = Aufnahme Start/Stop, s = Aufnahme speichern, 1-6 = Aufnahme spielen");
}
void draw() {
float ms = millis() % 10000;
// Pad bestimmen
if (mouseX > 0 && mouseX < 200 && mouseY > 0 && mouseY < 200) {
pad = 1;
}
if (mouseX > 200 && mouseX < 400 && mouseY > 0 && mouseY < 200) {
pad = 2;
}
if (mouseX > 400 && mouseX < 600 && mouseY > 0 && mouseY < 200) {
pad = 3;
}
if (mouseX > 0 && mouseX < 200 && mouseY > 200 && mouseY < 400) {
pad = 4;
}
if (mouseX > 200 && mouseX < 400 && mouseY > 200 && mouseY < 400) {
pad = 5;
}
if (mouseX > 400 && mouseX < 600 && mouseY > 200 && mouseY < 400) {
pad = 6;
}
}
// Aufnahme
void keyReleased() {
// Checken ob Mauszeiger über Pad1
if (pad == 1) {
if (key == 'r') {
// Mit 'r' Aufnahme starten/beenden
if (recorder1.isRecording()) {
recorder1.endRecord();
}
else {
recorder1.beginRecord();
}
}
// Mit 's' Aufnahme speichern
if (key == 's') {
recorder1.save();
println("Pad1 mit Sound belegt.");
}
}
// Pad1 abspielen
if ( key == '1' ) {
sound1 = minim.loadSample("sound1.wav", 2048);
sound1.trigger();
}
if (pad == 2) {
if (key == 'r') {
if (recorder2.isRecording()) {
recorder2.endRecord();
}
else {
recorder2.beginRecord();
}
}
if (key == 's') {
recorder2.save();
println("Pad2 mit Sound belegt.");
}
}
if ( key == '2' ) {
sound2 = minim.loadSample("sound2.mp3", 2048);
sound2.trigger();
}
if (pad == 3) {
if (key == 'r') {
if (recorder3.isRecording()) {
recorder3.endRecord();
}
else {
recorder3.beginRecord();
}
}
if (key == 's') {
recorder3.save();
println("Pad3 mit Sound belegt.");
}
}
if ( key == '3' ) {
sound3 = minim.loadSample("sound3.wav", 2048);
sound3.trigger();
}
if (pad == 4) {
if (key == 'r') {
if (recorder4.isRecording()) {
recorder4.endRecord();
}
else {
recorder4.beginRecord();
}
}
if (key == 's') {
recorder4.save();
println("Pad4 mit Sound belegt.");
}
}
if ( key == '4' ) {
sound4 = minim.loadSample("sound4.wav", 2048);
sound4.trigger();
}
if (pad == 5) {
if (key == 'r') {
if (recorder5.isRecording()) {
recorder5.endRecord();
}
else {
recorder5.beginRecord();
}
}
if (key == 's') {
recorder5.save();
println("Pad5 mit Sound belegt.");
}
}
if ( key == '5' ) {
sound5 = minim.loadSample("sound5.wav", 2048);
sound5.trigger();
}
if (pad == 6) {
if (key == 'r') {
if (recorder6.isRecording()) {
recorder6.endRecord();
}
else {
recorder6.beginRecord();
}
}
if (key == 's') {
recorder6.save();
println("Pad6 mit Sound belegt.");
}
}
if ( key == '6' ) {
sound6 = minim.loadSample("sound6.wav", 2048);
sound6.trigger();
}
if ( key == '0' ) {
in.close();
minim.stop();
super.stop();
}
}
// Bei Schließen des Programmes aller Ton aus
void stop()
{
in.close();
minim.stop();
super.stop();
}
I think it's a buffer problem or something like this.
Thx in advance!