# Playing +6 Audio Files Simultaneously, Without Delay or Lag

**URL:** https://discourse.processing.org/t/playing-6-audio-files-simultaneously-without-delay-or-lag/25034
**Category:** Libraries
**Created:** [October 29, 2020, 11:06pm UTC](https://discourse.processing.org/t/playing-6-audio-files-simultaneously-without-delay-or-lag/25034 "2020-10-29T23:06:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dgoren1](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@dgoren1](https://discourse.processing.org/u/dgoren1)
#### Post date: [October 29, 2020, 11:06pm UTC](https://discourse.processing.org/t/playing-6-audio-files-simultaneously-without-delay-or-lag/25034/1 "2020-10-29T23:06:20Z")

</div>

Hello! Quick Question:

I’m building a program that visualizes multiple audio files together at once.

My program was working fine with just 3 audio files, but now that I’m loading and playing 7 audio files at once, the program fails to play all of my audio files simultaneously. Instead, some audio files start playing slightly earlier/later than others which disrupts the song.

For context, each audio file is a part of one song i.e. the drums, bass, vocals, etc. so if one file is off beat then the whole song sounds off.

Any clues as to how I can work around this? Does Processing have some limitation to the number of files that I can start playing at once? And if so, should I process the visualizer in batches and then combine after (complex)? Or, am I missing some easier way to load and play the audio files simultaneously in the `setup()` function?

Happy to clarify and thank you in advance for any help!  
Dylan

How I’m loading and playing audio files:

```auto
void setup(){
  size(800,800);
  
  file = new SoundFile[numsounds];
  amp = new Amplitude[numsounds];
  
//for loop to load files named 1.wav, 2.wav, etc.
  for (int i = 0; i < numsounds; i++) {
    file[i] = new SoundFile(this, (i+1) + ".wav");
    amp[i] = new Amplitude(this);
    amp[i].input(file[i]);
    
  }
 
 //I've found playing each file individually like this to be 
// more effective than the for loop method like above.
  file[0].play();
  file[1].play();
  file[2].play();
  file[3].play();
  file[4].play();
  file[5].play();
  file[6].play();
}

```

---

<div class="post-metadata">

### Author: ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)
#### Post date: [October 30, 2020, 5:22am UTC](https://discourse.processing.org/t/playing-6-audio-files-simultaneously-without-delay-or-lag/25034/2 "2020-10-30T05:22:19Z")

</div>

> [@Optimizing for a CPU-Intensive Music Visualizer](https://discourse.processing.org/t/optimizing-for-a-cpu-intensive-music-visualizer/22358/5):
>
> That’s fine. Setup should be used to load files, because it may take a lot of time. Draw() cycle starts after that prep works has been done. So to get the audio in sync load files in setup. Do all the time consuming stuff there start audio in draw(). Then they’ll start at more or less same time. You can stop looping of draw()-function with [noLoop()](https://processing.org/reference/noLoop_.html)

---

<div class="post-metadata">

### Author: ![dgoren1](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@dgoren1](https://discourse.processing.org/u/dgoren1)
#### Post date: [November 12, 2020, 11:00pm UTC](https://discourse.processing.org/t/playing-6-audio-files-simultaneously-without-delay-or-lag/25034/3 "2020-11-12T23:00:17Z")

</div>

It ended up that I actually created the mistake in the audio file, not in the program. I was able to resolve it my re-exporting my .wav file. 😅

Happy that Processing can run dozens of audio files simultaneously without any issue. Pretty cool! 😁
