[Openal] Using stereo sounds
Chris Robinson
chris.kcat at gmail.com
Mon May 28 17:33:03 PDT 2007
On Monday 28 May 2007 05:08:32 pm Kieran Hayes wrote:
> Sound files that are stereo will not respond correctly when applying
> orientation and position. All mono files work perfectly, and I suppose
> this is because the stereo files have multiple channels and work against
> what OpenAL is trying to do with them, but it seems as though this
> limitation should not be there.
Non-mono sources aren't affected by 3D spatialization. According to the spec:
"Buffers containing audio data with more than one channel will be played
without 3D spatialization features – these formats are normally used for
background music."
Panning multi-channel sources is a bit ambiguous (do the channels blend to one
side? do the other channels just go quiet?), so I guess they didn't want to
worry about such implementation details.
> Should I write a converter myself so that
> any sound files that are used are converted to mono, or is there a special
> way of loading or playing stereo WAVEs? Thanks for the help.
Something you could try to do is just supply the stereo data, specify a
single-channel format and double the reported frequency. Though I suppose
converting stereo data to mono would be a safer choice. It's not really hard:
for(i = 0;i < num_frames;++i)
data[i] = (int)(data[i*2]+data[i*2+1])/2;
Where num_frames is the number of left-right sample pairs, and 'data' is the
correct pointer type (short* for 16-bit, unsigned char* for 8-bit).
More information about the Openal
mailing list