[Openal] Using stereo sounds

Daniel PEACOCK dpeacock at creativelabs.com
Mon Jun 4 16:45:43 PDT 2007





Hi,

>> Though I suppose converting stereo data to mono would be a safer choice.

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

There are a few gotchas here ... you shouldn't divide the total of the left
and right samples by 2 ... just add the two values together, but be sure to
prevent the values from going out of range (e.g -32768 to +32767 for 16bit)
by casting and then clamping.  Also note that this only works for 16bit
samples (for 8bit samples, which are normally stored as unsigned values,
you need to convert the samples to signed values before adding them
together).

Dan
Notice
The information in this message is confidential and may be legally
privileged.  It is intended solely for the addressee.  Access to this
message by anyone else is unauthorized.  If you are not the intended
recipient,  any disclosure,  copying or distribution of the message,  or
any action taken by you in reliance on it,  is prohibited and may be
unlawful.  If you have received this message in error,  please delete it
and contact the sender immediately.  Thank you.




                                                                           
             Chris Robinson                                                
             <chris.kcat at gmail                                             
             .com>                                                      To 
             Sent by:                  openal at opensource.creative.com      
             openal-bounces at op                                          cc 
             ensource.creative                                             
             .com                                                  Subject 
                                       Re: [Openal] Using stereo sounds    
                                                                           
             05/28/2007 05:33                                              
             PM                                                            
                                                                           
                                                                           
                                                                           




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

_______________________________________________
Openal mailing list
Openal at opensource.creative.com
http://opensource.creative.com/mailman/listinfo/openal

ForwardSourceID:NT00041E5A



More information about the Openal mailing list