Search code examples
c++openal

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


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?


Solution

  • 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.