We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm using Beads to play mp3s and affect their playback rate. Beads 1.01, Processing 3.3, Windows 10.
X-Posted here
I've encountered an issue when loading mp3s that some will be unable to play and throw the error below.
I've uploaded an mp3 that doesn't work here: r&s and here: movieaudio The movieaudio doesn't throw the error, it just gets stuck on line 23 or 25 in the code.
The code is a manipulation of the sampling_03.pde example from Sonifying Processing.
Any light that can be shed on this would be immensely appreciated. Thanks.
Error:
AudioContext : no AudioIO specified, using default => beads.JavaSoundAudioIO.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet.selectCallback(PApplet.java:6529)
at processing.core.PApplet.access$0(PApplet.java:6522)
at processing.core.PApplet$3.run(PApplet.java:6434)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.NullPointerException
at beads.SamplePlayer.<init>(Unknown Source)
at Sound_BeadsII.fileSelected(Sound_BeadsII.java:47)
... 21 more
Code:
import beads.*;
import java.util.Arrays;
AudioContext ac;
SamplePlayer sp1;
PowerSpectrum ps;
Gain sampleGain;
Glide gainValue;
Glide rateValue;
color fore = color(255, 102, 204);
float rangeAvg = -1, timeValue = 2;
void setup() {
size(800, 600);
ac = new AudioContext();
selectInput("Select an audio file:", "fileSelected");
background(0);
//1440 frames / 60 seconds = 0.0625 seconds/frame
}
void fileSelected(File selection) {
println("here fileselection");
String audioFileName = selection.getAbsolutePath();
println("here loaded from absolutepath");
Sample sample = SampleManager.sample("2048", audioFileName);
println("here loaded selected file");
//SamplePlayer player = new SamplePlayer(ac, sample);
//Gain g = new Gain(ac, 2, 0.2);
//g.addInput(player);
//ac.out.addInput(g);
sp1 = new SamplePlayer(ac, sample);
println("here initialising sp1");
//try {
// sp1 = new SamplePlayer(ac, sample);
// //sp1 = new SamplePlayer(ac, new Sample(sketchPath("") + "/data/Hellboy_audio.mp3"));
//}
//catch(Exception e) {
// println("Exception while attempting to load sample!");
// e.printStackTrace(); //print a technical description of the error
//}
// note that we want to play the sample multiple times
sp1.setKillOnEnd(false);
println("here to killonend");
rateValue = new Glide(ac, 1, 30); // initialize our rateValue Glide object
sp1.setRate(rateValue); // connect it to the SamplePlayer
println("here setting sp1.ratevalue");
// volume of our sample player
gainValue = new Glide(ac, 0.7, 30);
sampleGain = new Gain(ac, 1, gainValue);
sampleGain.addInput(sp1);
ac.out.addInput(sampleGain); // connect the Gain to the AudioContext
//analysis chain
ShortFrameSegmenter sfs = new ShortFrameSegmenter(ac);
sfs.addInput(ac.out);
FFT fft = new FFT();
ps = new PowerSpectrum();
sfs.addListener(fft);
fft.addListener(ps);
ac.out.addDependent(sfs);
ac.start();
}
void draw() {
//float halfWidth = width / 2.0;
//gainValue.setValue((float)mouseY / (float)height); // set the gain based on mouse position along the Y-axis
//rateValue.setValue((((float)mouseX - halfWidth)/halfWidth)+1); // set the rate based on mouse position along the X-axis
background(0);
stroke(fore);
if (ps == null) return;
float[] features = ps.getFeatures();
if (features != null) {
for (int i = 0; i < width; i++) {
int featureIndex = i * features.length / width/2;
int vOffset = height - Math.min((int)(features[featureIndex] * height), height);
rangeAvg += vOffset;
//println("rangeAvg: " + rangeAvg);
line(i, 0, i, vOffset);
}
rangeAvg = rangeAvg / width;
println("rangeAvg Avg: " + rangeAvg);
if (rangeAvg > 0 && rangeAvg < 100) {rateValue.setValue(timeValue/4); println("1/4x");}
else if (rangeAvg > 100 && rangeAvg < 200) {rateValue.setValue(timeValue/2); println("1/2x");}
else if (rangeAvg > 200 && rangeAvg < 300) {rateValue.setValue(timeValue); println("1x");}
else if (rangeAvg > 300 && rangeAvg < 400) {rateValue.setValue(timeValue*2); println("2x");}
else if (rangeAvg > 400 && rangeAvg < 500) {rateValue.setValue(timeValue*3); println("3x");}
else if (rangeAvg > 500 && rangeAvg < 600) {rateValue.setValue(timeValue*4); println("4x");}
}
}