bdutta74
bdutta74

Reputation: 2860

Polyphonic audio playback with Processing

Is there a way to playback multiple audio files, simultaneously (i.e. polyphony) using Processing, somehow. My understanding is that the standard Sound library for Processing is essentially monophonic.

What I'd like to do is Processing to play an audio file, and before the playback ends, would like Processing to play another audio file. Any workarounds with Processing ?

Upvotes: 0

Views: 181

Answers (1)

Kevin Workman
Kevin Workman

Reputation: 42174

This question is too broad for Stack Overflow. It's hard to answer general "how do I do this" type questions. It's much easier to answer specific "I tried X, expected Y, but got Z instead" type questions. That being said, I'll try to help in a general sense:

Yes, you can play multiple audio files at the same time. For example I've had programs that played background music and sound effects.

You should look into using the Minim library, which makes it pretty easy to play audio in Processing. Googling "Processing Minim" also returns a ton of results.

Here is a very simple example:

Minim minim;
AudioPlayer soundOne;
AudioPlayer soundTwo;

void setup()
{

  minim = new Minim(this);
  soundOne = minim.loadFile("soundOne.mp3");
  soundTwo = minim.loadFile("soundTwo.mp3");
}

void draw(){}

void keyPressed(){
  soundOne.play();
}

void mousePressed(){
  soundTwo.play();
}

Upvotes: 2

Related Questions