Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenAL: how to play multiple sounds at the same time and mix them?

Tags:

c++

openal

I have used SDL_Mixer before, and it does this job correctly: when i play one sound with one single function call 10 times in sequence, all the sounds will get mixed together. But in OpenAL when i play a sound with alSourcePlay(), it just plays one sound without mixing into the previous sounds.

So, how can i play more than 1 sound at the same time?

like image 890
Rookie Avatar asked Apr 22 '11 22:04

Rookie


1 Answers

You need one source per sound.

A buffer holds the raw sound samples, and can feed one or several sources (at a time and simultaneously). A listener defines where your "ear" is (there is only ever one!). A source is a single instance of a sound, given a location in space, a volume, a buffer to pull samples from, and so on.

So, for 2 sounds to play simultaneously, you need 2 sources.

like image 137
Damon Avatar answered Oct 06 '22 00:10

Damon