[Openal] Play mono as "stereo"
Jason Daly
jdaly at ist.ucf.edu
Fri Oct 19 10:53:01 PDT 2007
Andrew Kerkel wrote:
> Hi,
> According to the programming guide the number of channels in buffer >
> 1 is valid but it won't be positioned when played. That's ok so far
> but in a special (inverse) case (exactly: speech - which is mono in
> our project) I need to use a mono sound as a non 3D sound so it should
> behave as a stereo (2D) sound.
> I didn't find any possibility to accomplish this so I tried this blunt
> trick:
>
> ("file" is a wrapper for a wave file)
>
> if (eFormat == AL_FORMAT_MONO8)
> {
> char* c = new char[file.GetDataSize()*2];
> memcpy(c, file.GetData(), file.GetDataSize()); // left chan
> memcpy(c+file.GetDataSize(), file.GetData(), file.GetDataSize());
> // right chan
> alBufferData(m_uiBuffer, AL_FORMAT_STEREO8, c,
> file.GetDataSize()*2, file.GetFrequency()/2);
> delete[] c;
> }
First of all, stereo audio needs its samples to be interleaved. That is
it needs to be formatted as LRLRLRLRLRLR instead of LLLLLLRRRRRR.
Second, an easier way to accomplish this would be to use two sources
with the same buffer and just position them on either side of the listener.
--"J"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://opensource.creative.com/pipermail/openal/attachments/20071019/3fe51a31/attachment.html
More information about the Openal
mailing list