[Openal] Play mono as "stereo"

Daniel PEACOCK dpeacock at creativelabs.com
Fri Oct 19 11:11:37 PDT 2007





Hi Andrew,

If you want to play a mono sound as 2D then you should enable Head Relative
mode using :-

alSourcei(SourceID, AL_SOURCE_RELATIVE, AL_TRUE);

The position you specify for the Source will now be relative to the
Listener rather than a world co-ordinate.   If you want the sound to play
from all speakers set the Source position to 0,0,0.  If you want the sound
to play from in-front of the listener (like a 2D mono would) you can set
the Source position to 0,0,-1.   I would also set the Source Reference
Distance parameter to 1.

Dan
Creative Labs, Inc.

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.




                                                                           
             Jason Daly                                                    
             <jdaly at ist.ucf.ed                                             
             u>                                                         To 
             Sent by:                  Andrew Kerkel                       
             openal-bounces at op         <andrew.kerkel at b-alive.de>          
             ensource.creative                                          cc 
             .com                      OpenAL                              
                                       <openal at opensource.creative.com>    
                                                                   Subject 
             10/19/2007 10:53          Re: [Openal] Play mono as "stereo"  
             AM                                                            
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




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"
_______________________________________________
Openal mailing list
Openal at opensource.creative.com
http://opensource.creative.com/mailman/listinfo/openal

ForwardSourceID:NT0004C512



More information about the Openal mailing list