From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a02297.html | 1292 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1292 insertions(+) create mode 100644 docs/doxygen/nel/a02297.html (limited to 'docs/doxygen/nel/a02297.html') diff --git a/docs/doxygen/nel/a02297.html b/docs/doxygen/nel/a02297.html new file mode 100644 index 00000000..f30af82b --- /dev/null +++ b/docs/doxygen/nel/a02297.html @@ -0,0 +1,1292 @@ + + +NeL: NLSOUND::CBufferAL class Reference + + + +
+

NLSOUND::CBufferAL Class Reference

#include <buffer_al.h> +

+

Inheritance diagram for NLSOUND::CBufferAL: +

+ +NLSOUND::IBuffer + +

Detailed Description

+OpenAL buffer

+A buffer can be filled with data. An OpenAL buffer cannot be streamed in, i.e. isFillMoreSupported() returns false (instead, streaming would be implemented by buffer queueing).

+

Author:
Olivier Cado

+Nevrax France

+
Date:
2001
+ +

+ +

+Definition at line 49 of file buffer_al.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

ALuint bufferName ()
 Return the buffer name (as an int).

 CBufferAL (ALuint buffername=0)
 Constructor.

virtual bool fillBuffer (void *src, uint32 bufsize)
 Set the buffer size and fill the buffer. Return true if ok. Call setFormat() first.

virtual bool fillMore (void *src, uint32 srcsize)
virtual uint32 getBufferADPCMEncoded (std::vector< uint8 > &result)
virtual uint32 getBufferMono16 (std::vector< sint16 > &result)
virtual float getDuration () const
 Return the duration (in ms) of the sample in the buffer.

virtual void getFormat (TSampleFormat &format, uint &freq) const
 Return the format and frequency.

virtual const NLMISC::TStringIdgetName ()
 Return the name of the buffer (as a string).

virtual uint32 getSize () const
 Return the size of the buffer, in bytes.

virtual bool isBufferLoaded ()
 Return true if the buffer is loaded. Used for async load/unload.

virtual bool isFillMoreSupported () const
virtual bool isStereo () const
 Return true if the buffer is stereo, false if mono.

virtual void presetName (const NLMISC::TStringId &bufferName)
virtual void setFormat (TSampleFormat format, uint freq)
 Set the sample format. Example: freq=44100.

virtual void setName (NLMISC::TStringId &name)
 Set the name of the buffer.

virtual void setSize (uint32 size)
 Force the buffer size without filling data (if isFillMoreSupported() only).

virtual ~CBufferAL ()
 Destructor.


Private Attributes

ALuint _BufferName
ALuint _Frequency
NLMISC::TStringId _Name
ALenum _SampleFormat
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + + +
NLSOUND::CBufferAL::CBufferAL ALuint  buffername = 0  ) 
+
+ + + + + +
+   + + +

+Constructor. +

+ +

+Definition at line 36 of file buffer_al.cpp. +

+

00036                                         :
+00037         IBuffer(), _BufferName(buffername), _SampleFormat(AL_INVALID), _Frequency(0)
+00038 {
+00039 }
+
+
+

+ + + + +
+ + + + + + + + + +
NLSOUND::CBufferAL::~CBufferAL  )  [virtual]
+
+ + + + + +
+   + + +

+Destructor. +

+ +

+Definition at line 45 of file buffer_al.cpp. +

+References NLSOUND::CSoundDriverAL::removeBuffer(). +

+

00046 {
+00047         CSoundDriverAL *sdal = CSoundDriverAL::instance();
+00048         //nlinfo( "Deleting buffer (name %u)", _BufferName );
+00049         sdal->removeBuffer( this );
+00050 }
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + +
ALuint NLSOUND::CBufferAL::bufferName  )  [inline]
+
+ + + + + +
+   + + +

+Return the buffer name (as an int). +

+ +

+Definition at line 88 of file buffer_al.h. +

+References _BufferName. +

+Referenced by NLSOUND::CSoundDriverAL::removeBuffer(), and NLSOUND::CSourceAL::setStaticBuffer(). +

+

00088 { return _BufferName; }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLSOUND::IBuffer::decodeADPCM uint8 indata,
sint16 outdata,
uint  nbSample,
TADPCMState state
[static, inherited]
+
+ + + + + +
+   + + +

+Unoptimized utility function designed to build ADPCM encoded sample bank file. Return the number of sample in the buffer. +

+Definition at line 164 of file buffer.cpp. +

+References NLSOUND::IBuffer::_IndexTable, NLSOUND::IBuffer::_StepsizeTable, index, NLSOUND::IBuffer::TADPCMState::PreviousSample, sint16, NLSOUND::IBuffer::TADPCMState::StepIndex, uint, and uint8. +

+

00165 {
+00166     uint8 *inp;         /* Input buffer pointer */
+00167     sint16 *outp;               /* output buffer pointer */
+00168     int sign;                   /* Current adpcm sign bit */
+00169     int delta;                  /* Current adpcm output value */
+00170     int step;                   /* Stepsize */
+00171     int valpred;                /* Predicted value */
+00172     int vpdiff;                 /* Current change to valpred */
+00173     int index;                  /* Current step change index */
+00174     int inputbuffer;            /* place to keep next 4-bit value */
+00175     int bufferstep;             /* toggle between inputbuffer/input */
+00176         
+00177     outp = outdata;
+00178     inp = indata;
+00179         
+00180     valpred = state.PreviousSample;
+00181     index = state.StepIndex;
+00182     step = _StepsizeTable[index];
+00183         
+00184     bufferstep = 0;
+00185     
+00186     for ( ; nbSample > 0 ; nbSample-- ) 
+00187         {
+00188                 
+00189                 /* Step 1 - get the delta value */
+00190                 if ( bufferstep ) 
+00191                 {
+00192                         delta = inputbuffer & 0xf;
+00193                 }
+00194                 else 
+00195                 {
+00196                         inputbuffer = *inp++;
+00197                         delta = (inputbuffer >> 4) & 0xf;
+00198                 }
+00199                 bufferstep = !bufferstep;
+00200                 
+00201                 /* Step 2 - Find new index value (for later) */
+00202                 index += _IndexTable[delta];
+00203                 if ( index < 0 )
+00204                         index = 0;
+00205                 if ( index > 88 )
+00206                         index = 88;
+00207                 
+00208                 /* Step 3 - Separate sign and magnitude */
+00209                 sign = delta & 8;
+00210                 delta = delta & 7;
+00211                 
+00212                 /* Step 4 - Compute difference and new predicted value */
+00213                 /*
+00214                 ** Computes 'vpdiff = (delta+0.5)*step/4', but see comment
+00215                 ** in adpcm_coder.
+00216                 */
+00217                 vpdiff = step >> 3;
+00218                 if ( delta & 4 )
+00219                         vpdiff += step;
+00220                 if ( delta & 2 )
+00221                         vpdiff += step>>1;
+00222                 if ( delta & 1 )
+00223                         vpdiff += step>>2;
+00224                 
+00225                 if ( sign )
+00226                         valpred -= vpdiff;
+00227                 else
+00228                         valpred += vpdiff;
+00229                 
+00230                 /* Step 5 - clamp output value */
+00231                 if ( valpred > 32767 )
+00232                         valpred = 32767;
+00233                 else if ( valpred < -32768 )
+00234                         valpred = -32768;
+00235                 
+00236                 /* Step 6 - Update step value */
+00237                 step = _StepsizeTable[index];
+00238                 
+00239                 /* Step 7 - Output value */
+00240                 *outp++ = valpred;
+00241     }
+00242         
+00243     state.PreviousSample = valpred;
+00244     state.StepIndex = index;
+00245 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLSOUND::IBuffer::encodeADPCM sint16 indata,
uint8 outdata,
uint  nbSample,
TADPCMState state
[static, inherited]
+
+ + + + + +
+   + + +

+Unoptimized utility function designed to build ADPCM encoded sample bank file. Return the number of sample in the buffer. +

+Definition at line 51 of file buffer.cpp. +

+References NLSOUND::IBuffer::_IndexTable, NLSOUND::IBuffer::_StepsizeTable, index, NLSOUND::IBuffer::TADPCMState::PreviousSample, sint16, NLSOUND::IBuffer::TADPCMState::StepIndex, uint, and uint8. +

+Referenced by NLSOUND::CBufferDSound::getBufferADPCMEncoded(). +

+

00052 {
+00053     sint16 *inp;                        /* Input buffer pointer */
+00054     uint8 *outp;                /* output buffer pointer */
+00055     int val;                    /* Current input sample value */
+00056     int sign;                   /* Current adpcm sign bit */
+00057     int delta;                  /* Current adpcm output value */
+00058     int diff;                   /* Difference between val and valprev */
+00059     int step;                   /* Stepsize */
+00060     int valpred;                /* Predicted output value */
+00061     int vpdiff;                 /* Current change to valpred */
+00062     int index;                  /* Current step change index */
+00063     int outputbuffer;           /* place to keep previous 4-bit value */
+00064     int bufferstep;             /* toggle between outputbuffer/output */
+00065         
+00066     outp = outdata;
+00067     inp = indata;
+00068         
+00069     valpred = state.PreviousSample;
+00070     index = state.StepIndex;
+00071     step = _StepsizeTable[index];
+00072     
+00073     bufferstep = 1;
+00074         
+00075     for ( ; nbSample > 0 ; nbSample-- ) 
+00076         {
+00077                 val = *inp++;
+00078                 
+00079                 /* Step 1 - compute difference with previous value */
+00080                 diff = val - valpred;
+00081                 sign = (diff < 0) ? 8 : 0;
+00082                 if ( sign ) diff = (-diff);
+00083                 
+00084                 /* Step 2 - Divide and clamp */
+00085                 /* Note:
+00086                 ** This code *approximately* computes:
+00087                 **    delta = diff*4/step;
+00088                 **    vpdiff = (delta+0.5)*step/4;
+00089                 ** but in shift step bits are dropped. The net result of this is
+00090                 ** that even if you have fast mul/div hardware you cannot put it to
+00091                 ** good use since the fixup would be too expensive.
+00092                 */
+00093                 delta = 0;
+00094                 vpdiff = (step >> 3);
+00095                 
+00096                 if ( diff >= step ) 
+00097                 {
+00098                         delta = 4;
+00099                         diff -= step;
+00100                         vpdiff += step;
+00101                 }
+00102                 step >>= 1;
+00103                 if ( diff >= step  )
+00104                 {
+00105                         delta |= 2;
+00106                         diff -= step;
+00107                         vpdiff += step;
+00108                 }
+00109                 step >>= 1;
+00110                 if ( diff >= step ) 
+00111                 {
+00112                         delta |= 1;
+00113                         vpdiff += step;
+00114                 }
+00115                 
+00116                 /* Step 3 - Update previous value */
+00117                 if ( sign )
+00118                         valpred -= vpdiff;
+00119                 else
+00120                         valpred += vpdiff;
+00121                 
+00122                 /* Step 4 - Clamp previous value to 16 bits */
+00123                 if ( valpred > 32767 )
+00124                 {
+00125                         printf("over+ %d\n",valpred);
+00126                         valpred = 32767;
+00127                 }
+00128                 else if ( valpred < -32768 )
+00129                 {
+00130                         printf("over- %d\n",valpred);
+00131                         valpred = -32768;
+00132                 }
+00133                 
+00134                 /* Step 5 - Assemble value, update index and step values */
+00135                 delta |= sign;
+00136                 
+00137                 index += _IndexTable[delta];
+00138                 if ( index < 0 ) 
+00139                         index = 0;
+00140                 if ( index > 88 ) 
+00141                         index = 88;
+00142                 step = _StepsizeTable[index];
+00143                 
+00144                 /* Step 6 - Output value */
+00145                 if ( bufferstep ) 
+00146                 {
+00147                         outputbuffer = (delta << 4) & 0xf0;
+00148                 } 
+00149                 else 
+00150                 {
+00151                         *outp++ = (delta & 0x0f) | outputbuffer;
+00152                 }
+00153                 bufferstep = !bufferstep;
+00154     }
+00155         
+00156     /* Output last step, if needed */
+00157     if ( !bufferstep )
+00158                 *outp++ = outputbuffer;
+00159     
+00160     state.PreviousSample = valpred;
+00161     state.StepIndex = index;
+00162 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
bool NLSOUND::CBufferAL::fillBuffer void *  src,
uint32  bufsize
[virtual]
+
+ + + + + +
+   + + +

+Set the buffer size and fill the buffer. Return true if ok. Call setFormat() first. +

+ +

+Implements NLSOUND::IBuffer. +

+Definition at line 138 of file buffer_al.cpp. +

+References _BufferName, _Frequency, _SampleFormat, nlassert, src, and uint32. +

+

00139 {
+00140         nlassert( src != NULL );
+00141         nlassert( (_SampleFormat != AL_INVALID) && (_Frequency != 0 ) );
+00142 
+00143         // Fill buffer
+00144         alBufferData( _BufferName, _SampleFormat, src, bufsize, _Frequency );
+00145 
+00146         // Error handling
+00147         return ( alGetError() == AL_NO_ERROR );
+00148 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
virtual bool NLSOUND::CBufferAL::fillMore void *  src,
uint32  srcsize
[inline, virtual]
+
+ + + + + +
+   + + +

+Fill the buffer partially (if isFillMoreSupported() only), beginning at the pos changed by a previous call to fillMore(). If the pos+srcsize exceeds the buffer size, the exceeding data is put at the beginning of the buffer. srcsize must be smaller than the buffer size. +

+Reimplemented from NLSOUND::IBuffer. +

+Definition at line 84 of file buffer_al.h. +

+References uint32. +

+

00084 { throw ESoundDriverNotSupp(); }
+
+

+ + + + +
+ + + + + + + + + + +
virtual uint32 NLSOUND::CBufferAL::getBufferADPCMEncoded std::vector< uint8 > &  result  )  [inline, virtual]
+
+ + + + + +
+   + + +

+Unoptimized utility function designed to build ADPCM encoded sample bank file. Return the number of sample in the buffer. +

+Implements NLSOUND::IBuffer. +

+Definition at line 101 of file buffer_al.h. +

+References uint32. +

+

00101 { /* TODO */ return 0; }
+
+

+ + + + +
+ + + + + + + + + + +
virtual uint32 NLSOUND::CBufferAL::getBufferMono16 std::vector< sint16 > &  result  )  [inline, virtual]
+
+ + + + + +
+   + + +

+Unoptimized utility function designed to build Mono 16 bits encoded sample bank file. Return the number of sample in the buffer. +

+Implements NLSOUND::IBuffer. +

+Definition at line 105 of file buffer_al.h. +

+References uint32. +

+

00105 { /* TODO */ return 0; }
+
+

+ + + + +
+ + + + + + + + + +
float NLSOUND::CBufferAL::getDuration  )  const [virtual]
+
+ + + + + +
+   + + +

+Return the duration (in ms) of the sample in the buffer. +

+ +

+Implements NLSOUND::IBuffer. +

+Definition at line 99 of file buffer_al.cpp. +

+References _Frequency, _SampleFormat, getSize(), and uint32. +

+

00100 {
+00101         if ( _Frequency == 0 )
+00102         {
+00103                 return 0;
+00104         }
+00105         uint32 bytespersample;
+00106         switch ( _SampleFormat )
+00107         {
+00108         case AL_FORMAT_MONO8 : bytespersample = 1; break;
+00109         case AL_FORMAT_MONO16 : bytespersample = 2; break;
+00110         case AL_FORMAT_STEREO8 : bytespersample = 2; break;
+00111         case  AL_FORMAT_STEREO16 : bytespersample = 4; break;
+00112         default : return 0;
+00113         }
+00114         return (float)(getSize()) * 1000.0f / (float)_Frequency / (float)bytespersample;
+00115 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLSOUND::CBufferAL::getFormat TSampleFormat format,
uint freq
const [virtual]
+
+ + + + + +
+   + + +

+Return the format and frequency. +

+ +

+Implements NLSOUND::IBuffer. +

+Definition at line 82 of file buffer_al.cpp. +

+References _Frequency, _SampleFormat, format, NLSOUND::Mono16, NLSOUND::Mono8, nlstop, NLSOUND::Stereo16, NLSOUND::Stereo8, and uint. +

+

00083 {
+00084         switch ( _SampleFormat )
+00085         {
+00086         case AL_FORMAT_MONO8 : format = Mono8; break;
+00087         case AL_FORMAT_MONO16 : format = Mono16; break;
+00088         case AL_FORMAT_STEREO8 : format = Stereo8; break;
+00089         case AL_FORMAT_STEREO16 : format = Stereo16; break;
+00090         default : nlstop;
+00091         }
+00092         freq = _Frequency;
+00093 }
+
+

+ + + + +
+ + + + + + + + + + +
virtual const NLMISC::TStringId& NLSOUND::CBufferAL::getName void   )  [inline, virtual]
+
+ + + + + +
+   + + +

+Return the name of the buffer (as a string). +

+ +

+Implements NLSOUND::IBuffer. +

+Definition at line 91 of file buffer_al.h. +

+

00091 { return _Name; }
+
+

+ + + + +
+ + + + + + + + + +
uint32 NLSOUND::CBufferAL::getSize  )  const [virtual]
+
+ + + + + +
+   + + +

+Return the size of the buffer, in bytes. +

+ +

+Implements NLSOUND::IBuffer. +

+Definition at line 61 of file buffer_al.cpp. +

+References _BufferName, nlassert, uint32, and value. +

+Referenced by getDuration(). +

+

00062 {
+00063         ALint value;
+00064         alGetBufferi( _BufferName, AL_SIZE, &value );
+00065         nlassert( alGetError() == AL_NO_ERROR );
+00066         return value;
+00067 }
+
+

+ + + + +
+ + + + + + + + + +
virtual bool NLSOUND::CBufferAL::isBufferLoaded  )  [inline, virtual]
+
+ + + + + +
+   + + +

+Return true if the buffer is loaded. Used for async load/unload. +

+ +

+Implements NLSOUND::IBuffer. +

+Definition at line 94 of file buffer_al.h. +

+

00094 { /* TODO */ return false; }
+
+

+ + + + +
+ + + + + + + + + +
virtual bool NLSOUND::CBufferAL::isFillMoreSupported  )  const [inline, virtual]
+
+ + + + + +
+   + + +

+Return true if the buffer is able to be fill part by part, false if it must be filled in one call (OpenAL 1.0 -> false) +

+Implements NLSOUND::IBuffer. +

+Definition at line 76 of file buffer_al.h. +

+

00076 { return false; }
+
+

+ + + + +
+ + + + + + + + + +
bool NLSOUND::CBufferAL::isStereo  )  const [virtual]
+
+ + + + + +
+   + + +

+Return true if the buffer is stereo, false if mono. +

+ +

+Implements NLSOUND::IBuffer. +

+Definition at line 73 of file buffer_al.cpp. +

+References _SampleFormat. +

+Referenced by NLSOUND::CSourceAL::setStaticBuffer(). +

+

00074 {
+00075         return (_SampleFormat==AL_FORMAT_STEREO8) || (_SampleFormat==AL_FORMAT_STEREO16);
+00076 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLSOUND::CBufferAL::presetName const NLMISC::TStringId bufferName  )  [virtual]
+
+ + + + + +
+   + + +

+Preset the name of the buffer. Used for async loading to give a name before the buffer is effectivly loaded. If the name after loading of the buffer doesn't match the preset name, the load will assert. +

+Implements NLSOUND::IBuffer. +

+Definition at line 52 of file buffer_al.cpp. +

+

00053 {
+00054         _Name = bufferName;
+00055 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLSOUND::CBufferAL::setFormat TSampleFormat  format,
uint  freq
[virtual]
+
+ + + + + +
+   + + +

+Set the sample format. Example: freq=44100. +

+ +

+Implements NLSOUND::IBuffer. +

+Definition at line 121 of file buffer_al.cpp. +

+References _Frequency, _SampleFormat, format, NLSOUND::Mono16, NLSOUND::Mono8, nlstop, NLSOUND::Stereo16, NLSOUND::Stereo8, and uint. +

+

00122 {
+00123         switch ( format )
+00124         {
+00125         case Mono8 : _SampleFormat = AL_FORMAT_MONO8; break;
+00126         case Mono16 : _SampleFormat = AL_FORMAT_MONO16; break;
+00127         case Stereo8 : _SampleFormat = AL_FORMAT_STEREO8; break;
+00128         case Stereo16 : _SampleFormat = AL_FORMAT_STEREO16; break;
+00129         default            : nlstop; _SampleFormat = AL_INVALID;
+00130         }
+00131         _Frequency = freq;
+00132 }
+
+

+ + + + +
+ + + + + + + + + + +
virtual void NLSOUND::CBufferAL::setName NLMISC::TStringId name  )  [inline, virtual]
+
+ + + + + +
+   + + +

+Set the name of the buffer. +

+ +

+Definition at line 97 of file buffer_al.h. +

+

00097 { _Name = name; }
+
+

+ + + + +
+ + + + + + + + + + +
virtual void NLSOUND::CBufferAL::setSize uint32  size  )  [inline, virtual]
+
+ + + + + +
+   + + +

+Force the buffer size without filling data (if isFillMoreSupported() only). +

+ +

+Reimplemented from NLSOUND::IBuffer. +

+Definition at line 78 of file buffer_al.h. +

+References size, and uint32. +

+

00078 { throw ESoundDriverNotSupp(); }
+
+


Field Documentation

+

+ + + + +
+ + +
ALuint NLSOUND::CBufferAL::_BufferName [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 111 of file buffer_al.h. +

+Referenced by bufferName(), fillBuffer(), and getSize().

+

+ + + + +
+ + +
ALuint NLSOUND::CBufferAL::_Frequency [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 120 of file buffer_al.h. +

+Referenced by fillBuffer(), getDuration(), getFormat(), and setFormat().

+

+ + + + +
+ + +
NLMISC::TStringId NLSOUND::CBufferAL::_Name [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 114 of file buffer_al.h.

+

+ + + + +
+ + +
ALenum NLSOUND::CBufferAL::_SampleFormat [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 117 of file buffer_al.h. +

+Referenced by fillBuffer(), getDuration(), getFormat(), isStereo(), and setFormat().

+


The documentation for this class was generated from the following files: +
Generated on Tue Mar 16 14:33:46 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1