[Openal] How can I play mono wav sound in specific channel?

Chris Robinson chris.kcat at gmail.com
Thu Apr 16 01:49:38 PDT 2009


On Thursday 16 April 2009 12:41:38 am Ümit Uzun wrote:
> I have an project and in this project I have an SoundServer application. I
> have implemented by OpenAL. But as I have realized that, there is no
> channel controlling chance indirectly. OpenAL takes all controls about the
> sound in its hands.
>
> But I have an 7.1 speaker and 2 of them (Side Left and Side Right) are
> different room and the others are different room where each room sound
> isolated from each other. I have kind oe sounds and some of them could be
> heard from only room1 and some of them could be heard from only room2.
> So how can achive play different wav sound from different channel to direct
> each related rooms?

Hi.

I think the best way to play mono data on specific channels would be to use a 
multi-channel buffer format. So if you have your mono data:

ALshort monodata[samples];

you can fill it into a 7.1 buffer like this:

ALshort data71[samples*8];
for(int i = 0;i < samples;i++) {
    data71[i*8 + 0] = 0; // front-left
    data71[i*8 + 1] = 0; // front-right
    data71[i*8 + 2] = 0; // front-center
    data71[i*8 + 3] = 0; // lfe (sub-woofer)
    data71[i*8 + 4] = 0; // back-left
    data71[i*8 + 5] = 0; // back-right
    data71[i*8 + 6] = monodata[i]; // side-left
    data71[i*8 + 7] = monodata[i]; // side-right
}
alBufferData(bID, alGetEnumValue("AL_FORMAT_71CHN16"), data71,
             samples*8*sizeof(ALshort), frequency);

That would store the data so it will play on the two side speakers only. 
However, this will only work on implementations that can do 7.1 output and 
support the AL_EXT_MCFORMATS extension (hardware Windows drivers can, I 
believe, as does OpenAL Soft; I'm not sure about OSX). Without the extension, 
the 7.1 buffer format won't be available, and if there's no 7.1 output, the 
two speakers will be virtualized (the sound will play out the other available 
speakers to try and simulate side speakers).



More information about the Openal mailing list