Minim library, trying to synchronize waveforms

Hi everyone, I want to create a synth that constantly changes the waveform for a new one each draw() call. The problem is that the waveform will change whenever the array is filled with new values, so there will be a cracking noise when the waveform has to “jump” to the new values. Let me show this example:

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim       minim;
AudioOutput out;
Oscil       wave;
Wavetable   table;

int siz=512;
float [] buffer=new float [siz];

void setup()
{
  size(600, 300, P3D);
  
  minim = new Minim(this);
  out = minim.getLineOut();
  
  // create wavetable and set buffer array as waveform
  table = new Wavetable(siz);
  table.setWaveform(buffer);
  
  wave  = new Oscil( 440, 0.5f, table );

  // patch the Oscil to the output
  wave.patch( out );
  
  //create a simple waveform with zero-crossing at the beginning and at the end
  for (int i=0;i<siz;i++){
    float ang=map(i,0,siz,0,TWO_PI);
    buffer[i]=cos(ang+PI)+1;
  }
}

void draw()
{
  background(0);
  
  //each time we call draw we swap the waveform
  table.invert();
  
  // draw the waveform we are using in the oscillator
  stroke( 200, 0, 0 );
  strokeWeight(4);
  for( int i = 0; i < width-1; ++i )
  {
    point( i, height/2 - (height*0.2) * table.value( (float)i / width ) );
  }
  
}

If you run this you will hear a popping sound each time the waveform is inverted, even if it has 0 value at its beginning and end. This happens because the swap can happen right in the middle of the waveform, so for this problem to be solved, I need to change the waveform only when it has finished playing. I didn’t find anything on Minim that allows me to do that, or any method that gives me the current index of the playing waveform… I’ve tried with an Audiolistener object but without any luck. Maybe I can add a function like “setWaveform(float waveform, boolean sync)” to the Waveform class that waits for the current waveform to finish before updating to the new one? I think it would be quite difficult. Maybe there is a library that allows me to do that?
Thanks for your help