I'm trying to make a simple sketch that pauses and then restarts an audio file at the same place. I can do it with Minim but its very slow. I'm trying to use setOffset() but it doesn't seem to do anything. Suggestions?
import toxi.audio.*;
import toxi.geom.*;
JOALUtil audio;
AudioSource erhu;
int eff = 0;
void setup() {
size(1000, 400);
// JOALUtil is implemented as singleton, so get an instance like this & initialize it
audio = JOALUtil.getInstance();
audio.init();
// load a sample and initialize an audio source using it
// NOTE: path to file needs to be absolute, hence we use the dataPath() wrapper
AudioBuffer eBuffer = audio.loadBuffer(dataPath("erhu41-16.wav"));
erhu = audio.generateSource();
erhu.setBuffer(eBuffer);
erhu.play();
erhu.setLooping(true);
}
// needed because else Processing is calling stop() prematurely
void draw() {
erhu.setGain(mouseX);
}
void keyPressed() {
erhu.stop();
println(erhu.setOffset());
// println(erhu.length());
// println(erhu.getOffset());
// erhu.setOffset(erhu.getOffset());
}
void mouseClicked() {
erhu.play();
//eff = erhu.getOffset();
//erhu.setOffset(eff);
}
// release all audio resources
public void stop() {
audio.shutdown();
}
1