Export sketch as audio?

so I made the following sketch to scramble audio, and I’m wondering how to export the audio I get from it. Currently I’m just using audacity to record desktop audio while the sketch is running, but that takes long as I must record for however long I want the scrambled output to be. How do I export sketches as audio so I don’t have to do this?

import processing.sound.*;
//SETTINGS
int minSegLength = 5; //Minimum length of segments (in 10ths of a second)
int maxSegLength = 30; //Maximum length of segments (in 10ths of a second)
//NOT SETTINGS
SoundFile source; //File to scramble
int curSegLength; //Length of current segment (in 10ths of a second)
int segTime; //Time when the current segment started playing
void setup() {
  source = new SoundFile(this, "source.mp3");
  segTime = getTimeIn10thsOfSecond();
  curSegLength = floor(random(minSegLength, maxSegLength));
  source.loop();
}
void draw() {
  if(getTimeIn10thsOfSecond() > segTime+curSegLength) { 
    //Start new segment
    curSegLength = floor(random(minSegLength, maxSegLength));
    segTime = getTimeIn10thsOfSecond();
    source.jump(random(source.duration()));
  }
}

int getTimeIn10thsOfSecond() {
  return (millis()/100)+(second()*10)+(minute()*60*10)+(hour()*60*60*10)+(day()*60*60*24*10);
}

Hi,

Maybe this can help :wink: :