Minim: sound cracks on Pan and Gain

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 = "[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));  

void draw() {}

void mouseDragged() {
  panValue = map(mouseX, 0, width, -1, 1);
  gainValue = map(mouseY, 0, height, 0, NON_AUDIBLE_GAIN);

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?

i have here ( win7 ) no problem, but use like:

float vol=-34.4;                                        // 6 .. -48 / 100 .. 0 %
//... in setup
  out = minim.getLineOut();
//... in draw..
  vol   = map(mouseX, 0, width, -48, 6);
  out.setGain(vol);                   // master vol slider

where you see that


Thanks, but it didn’t help, on Linux I can hear even more cracks. Especially when I move the mouse rapidly. :frowning: I think it might be some ALSA problem. I will try to switch to pulseaudio. In my original code I have to control pan and gain of multiple samples separately, therefore master volume wouldn’t work for me.

for individual sounds i use sliders and


range 0…1.0 // float

you want just test my code?
download link

What happens if you use the Processing Sound library and run the examples at Libraries > Sound > Oscillators? In my case those are unbearably glitchy, but the Minim example you posted sounds ok. Just wondering if it is like when one works, then the other doesn’t.

I tried on ArchLinux. I can try on Ubuntu later.

Most likely. You can delete the Java directory inside Processing and replace with a symlink to a system installed OpenJDK 8.

I tried, without much improvement. So I checked with pavucontrol what is providing sound from the java process, and it says alsa plugin. It seems that even openjdk is falling back to ALSA :frowning: I am giving up for now. It will be used on mac and I hope the sound won’t be an issue there.