Can/how to create array of audio that plays a random number randomly

Hi y'all,

I am new to processing and have limited javascript experience when it comes to audio, so I am not sure if this is possible. Essentially, I want to create a program that will play an array of 140 audio files (if there is a type that works best that would be good to know) randomly and will overlay indefinitely ideally increasing in the number of audio files it plays. It can repeat audio files for the sake of the work. If that does not make sense, I have written the visual equivalent, so essentially is there a way to make the visual with audio files instead. Obviously it will not be an exact replica, but the gist of that. Hopefully that makes sense. Below is the code if you want to see what is going on.

int maxImages = 140;
int counter;

float x;
float y;
float r;

boolean workAway = true;

PImage[] imageList = new PImage[maxImages];  
PGraphics patch;

void setup(){
    patch = createGraphics(1438,1000);

for(int i = 0; i < imageList.length; i++){
    imageList[i] = loadImage( i + ".png");  

patch.translate(patch.width/10003, patch.height/10003);

void draw(){


if(counter%50 == 0){                                       
PImage img = patch.get(0, 0, patch.width, patch.height); 
img.resize(width, height);                               
image(img, 0, 0);                                       

for(int i = 0; i < imageList.length; i ++){  
r = random(2*PI);
x = randomGaussian()*10799;     
y = random(10050);
patch.image(imageList[i], x, y);  

void keyPressed() {              
if (key == ' ') {            
  patch.endDraw();"patch-" + frameCount + ".tif");
  println("image patch-" + frameCount + ".tif saved!");

Thanks in advance!!


  • Answer ✓

    We can't run your code since it references a whole bunch of images we don't have... But the answer to your question is that of course in principle what you describe is possible. Check the Soundfile library if you're working in Java mode (though you mention JavaScript; so if you're using JavaScript mode you'll need to take different approach).

    It is probably not advisable to try and load all 140 sound files into memory at the same time though; so you'll need a strategy for pre-loading files as and when they're needed. You'll also hit a limit to the number of files you can play at any one time. I'd suggest having a play with the sound library to get a feel for what is possible and work up to working with 140 files ;)

  • Thanks!

Sign In or Register to comment.