I am having problem with controlling the playback of my audio files. The sound is somehow slightly chopped when pan and gain values are adjusted, especially if it is happening rapidly. Here is the code to reproduce the issue:
/*
* Single file is played in the loop, when mouse pressed:
* - pan control: horizontally mouse movement
* - gain control: vertical mouse movement
*
* On Ubuntu Linux I can hear cracking sound when these values are changed rapidly.
*/
import ddf.minim.*;
import ddf.minim.ugens.*;
static final String SOUND_LOOP = "https://sampleswap.org/samples-ghost/LOOPING%20AMBIENCE/1648[kb]etheral-chord.wav.mp3";
static final float NON_AUDIBLE_GAIN = -100;
Minim minim;
AudioOutput out;
FilePlayer loopSound;
Pan pan;
Gain gain;
float panValue;
float gainValue;
void setup() {
size(800, 600);
minim = new Minim(this);
pan = new Pan(0);
gain = new Gain(0);
out = minim.getLineOut(Minim.STEREO);
loopSound = new FilePlayer(minim.loadFileStream(SOUND_LOOP));
loopSound.patch(gain).patch(pan).patch(out);
loopSound.loop();
}
void draw() {}
void mouseDragged() {
panValue = map(mouseX, 0, width, -1, 1);
gainValue = map(mouseY, 0, height, 0, NON_AUDIBLE_GAIN);
pan.setPan(panValue);
gain.setValue(gainValue);
}
I also created a github project with challenges like this, which contains this exact code:
Could it be due to the fact that on Linux Processing is running with Oracle JDK, which means it is using ALSA directly, not pulse audio?
I was also thinking about the difference in the sample frequency and the output frequency. Any ideas how to improve it?