NLSOUND::CBufferDSound Class Reference

#include <buffer_dsound.h>

Inheritance diagram for NLSOUND::CBufferDSound:

NLSOUND::IBuffer

Detailed Description

Buffer for the DSound implementation of the audio driver.

A buffer represents a sound file loaded in RAM.

Author:
Peter Hanappe, Olivier Cado

Nevrax France

Date:
2002

Definition at line 45 of file buffer_dsound.h.

Public Member Functions

 CBufferDSound ()
 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 uint8getData () const
 Return a pointer to the sample data.

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.

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 bool readRawBuffer (const std::string &name, uint8 *rawData, uint dataSize, TSampleFormat format, uint32 frequency)
virtual bool readWavBuffer (const std::string &name, uint8 *wavData, uint dataSize)
 Load a sound file in the buffer. Throws an exception is an error occurs.

virtual void setFormat (TSampleFormat format, uint freq)
 Set the sample format. Example: freq=44100.

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

virtual ~CBufferDSound ()
 Destructor.


Static Public Member Functions

Source properties
void decodeADPCM (uint8 *indata, sint16 *outdata, uint nbSample, TADPCMState &state)
void encodeADPCM (sint16 *indata, uint8 *outdata, uint nbSample, TADPCMState &state)
Source properties
void decodeADPCM (uint8 *indata, sint16 *outdata, uint nbSample, TADPCMState &state)
void encodeADPCM (sint16 *indata, uint8 *outdata, uint nbSample, TADPCMState &state)

Private Attributes

uint8_Data
TSampleFormat _Format
uint _Freq
NLMISC::TStringId _Name
uint32 _Size


Constructor & Destructor Documentation

NLSOUND::CBufferDSound::CBufferDSound  ) 
 

Constructor.

Definition at line 131 of file buffer_dsound.cpp.

References _Format, _Freq, NLSOUND::EmptyString, and NLSOUND::Mono16.

00132 {
00133         _Name = CSoundDriverDSound::instance()->getStringMapper()->map(EmptyString);
00134     _Data = NULL;
00135     _Size = 0; 
00136     _Format = Mono16;
00137     _Freq = 0;
00138 }

NLSOUND::CBufferDSound::~CBufferDSound  )  [virtual]
 

Destructor.

Definition at line 140 of file buffer_dsound.cpp.

00141 {
00142 //      nldebug("Destroying DirectSound buffer %s (%p)", CSoundDriverDSound::instance()->getStringMapper()->unmap(_Name).c_str(), this);
00143 
00144     if (_Data != NULL)
00145     {
00146         delete[] _Data;
00147     }
00148 }


Member Function Documentation

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 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::CBufferDSound::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 163 of file buffer_dsound.cpp.

References src, and uint32.

00164 {
00165     return false;
00166 }

virtual bool NLSOUND::IBuffer::fillMore void *  src,
uint32  srcsize
[inline, virtual, inherited]
 

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 in NLSOUND::CBufferAL.

Definition at line 79 of file buffer.h.

References uint32.

Referenced by NLSOUND::ILoader::fillBufferPart().

00079 { throw ESoundDriverNotSupp(); }

uint32 NLSOUND::CBufferDSound::getBufferADPCMEncoded std::vector< uint8 > &  result  )  [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 451 of file buffer_dsound.cpp.

References _Format, NLSOUND::IBuffer::encodeADPCM(), NLSOUND::Mono16, sint16, and uint32.

00452 {
00453         result.clear();
00454 
00455         if (_Data == 0)
00456                 return 0;
00457 
00458         if (_Format != Mono16)
00459                 return 0;
00460 
00461         uint32 nbSample = _Size/2;
00462         nbSample &= 0xfffffffe;
00463 
00464         result.resize(nbSample / 2);
00465 
00466         TADPCMState     state;
00467         state.PreviousSample = 0;
00468         state.StepIndex = 0;
00469         encodeADPCM((sint16*)_Data, &result[0], nbSample, state);
00470 
00471         return nbSample;
00472 }

uint32 NLSOUND::CBufferDSound::getBufferMono16 std::vector< sint16 > &  result  )  [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 474 of file buffer_dsound.cpp.

References _Format, NLSOUND::Mono16, sint16, NLSOUND::Stereo16, uint, and uint32.

00475 {
00476         result.clear();
00477 
00478         if (_Data == 0)
00479                 return 0;
00480 
00481         if (_Format == Mono16)
00482         {
00483                 uint nbSample = _Size/2;
00484                 nbSample &= 0xfffffffe;
00485 
00486                 result.reserve(nbSample);
00487                 result.insert(result.begin(), (sint16*)_Data, ((sint16*)_Data)+nbSample);
00488 
00489                 return nbSample;
00490         }
00491         else if (_Format == Stereo16)
00492         {
00493                 uint nbSample = _Size/4;
00494                 nbSample &= 0xfffffffe;
00495 
00496                 struct TFrame
00497                 {
00498                         sint16  Channel1;
00499                         sint16  Channel2;
00500                 };
00501                 result.reserve(nbSample);
00502                 TFrame *frame = (TFrame *)_Data;
00503                 for (uint i=0; i<nbSample; ++i)
00504                 {
00505                         result[i] = (frame->Channel1>>1) +(frame->Channel2>>1);
00506                 }
00507 
00508                 return nbSample;
00509         }
00510         else
00511                 return 0;
00512 }

virtual uint8* NLSOUND::CBufferDSound::getData  )  const [inline, virtual]
 

Return a pointer to the sample data.

Definition at line 103 of file buffer_dsound.h.

References uint8.

00103 { return _Data; }

float NLSOUND::CBufferDSound::getDuration  )  const [virtual]
 

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

Implements NLSOUND::IBuffer.

Definition at line 169 of file buffer_dsound.cpp.

References _Format, _Freq, NLSOUND::Mono16, NLSOUND::Mono16ADPCM, NLSOUND::Mono8, NLSOUND::Stereo16, and NLSOUND::Stereo8.

00170 {
00171     float frames = (float) _Size;
00172 
00173     switch (_Format) 
00174         {
00175     case Mono8:
00176         break;
00177     case Mono16ADPCM:
00178         frames *= 2.0f;
00179         break;
00180     case Mono16:
00181         frames /= 2.0f;
00182         break;
00183     case Stereo8:
00184         frames /= 2.0f;
00185         break;
00186     case Stereo16:
00187         frames /= 4.0f;
00188         break;
00189     }
00190 
00191     return 1000.0f * frames / (float) _Freq;
00192 }

virtual void NLSOUND::CBufferDSound::getFormat TSampleFormat format,
uint freq
const [inline, virtual]
 

Return the format and frequency.

Implements NLSOUND::IBuffer.

Definition at line 72 of file buffer_dsound.h.

References _Format, _Freq, format, and uint.

00072 { format = _Format; freq = _Freq; }

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

Return the name of the buffer.

Implements NLSOUND::IBuffer.

Definition at line 106 of file buffer_dsound.h.

00106 { return _Name; }

virtual uint32 NLSOUND::CBufferDSound::getSize void   )  const [inline, virtual]
 

Return the size of the buffer, in bytes.

Implements NLSOUND::IBuffer.

Definition at line 63 of file buffer_dsound.h.

References uint32.

00063 { return _Size; }

virtual bool NLSOUND::CBufferDSound::isBufferLoaded  )  [inline, virtual]
 

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

Implements NLSOUND::IBuffer.

Definition at line 108 of file buffer_dsound.h.

00108 { return _Data != 0; }

virtual bool NLSOUND::CBufferDSound::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 78 of file buffer_dsound.h.

00078 { return false; }

virtual bool NLSOUND::CBufferDSound::isStereo  )  const [inline, virtual]
 

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

Implements NLSOUND::IBuffer.

Definition at line 69 of file buffer_dsound.h.

References _Format, NLSOUND::Stereo16, and NLSOUND::Stereo8.

00069 { return (_Format == Stereo8) || (_Format == Stereo16); }

void NLSOUND::CBufferDSound::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 150 of file buffer_dsound.cpp.

00151 {
00152         _Name = bufferName;
00153 }

bool NLSOUND::CBufferDSound::readRawBuffer const std::string &  name,
uint8 rawData,
uint  dataSize,
TSampleFormat  format,
uint32  frequency
[virtual]
 

Definition at line 416 of file buffer_dsound.cpp.

References _Format, _Freq, format, nlassertex, uint, uint32, and uint8.

00417 {
00418         NL_ALLOC_CONTEXT(NLSOUND_CBufferDSound);
00419         // free any existing data
00420     if (_Data != NULL)
00421     {
00422         free(_Data);
00423         _Data = NULL;
00424     }
00425 
00426         _Format = format;
00427         _Size = dataSize;
00428     // Allocate the sample buffer
00429         _Data = new uint8 [_Size];
00430 
00431     // read in the format data
00432         memcpy(_Data, rawData, dataSize);
00433 
00434     _Freq = frequency;
00435 
00436 
00437     // Allocate the sample buffer
00438 
00439         static NLMISC::TStringId        empty(CSoundDriverDSound::instance()->getStringMapper()->map(""));
00440         NLMISC::TStringId nameId = CSoundDriverDSound::instance()->getStringMapper()->map(CFile::getFilenameWithoutExtension(name));
00441         // if name is preseted, the name must match.
00442         if (_Name != empty)
00443         {
00444                 nlassertex(nameId == _Name, ("The preseted name and buffer name doen't match !"));
00445         }
00446         _Name = nameId;
00447 
00448         return true;
00449 }

bool NLSOUND::CBufferDSound::readWavBuffer const std::string &  name,
uint8 wavData,
uint  dataSize
[virtual]
 

Load a sound file in the buffer. Throws an exception is an error occurs.

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.

Definition at line 196 of file buffer_dsound.cpp.

References _Format, _Freq, buffer, format, NLSOUND::Mono16, NLSOUND::Mono8, nlassertex, num, sint, sint32, size, NLSOUND::Stereo16, NLSOUND::Stereo8, uint, uint32, and uint8.

00197 {
00198         NL_ALLOC_CONTEXT(NLSOUND_CBufferDSound);
00199     sint error; 
00200     sint32 num;
00201     HMMIO hmmio;
00202     WAVEFORMATEX format;
00203     MMCKINFO riff_chunk;
00204     MMCKINFO data_chunk;
00205     MMCKINFO chunk;
00206 
00207   
00208     if (_Data != NULL)
00209     {
00210         delete [] _Data;
00211         _Data = NULL;
00212     }
00213 
00214 /*      NLMISC::CIFile  ifile(file);
00215         uint size = ifile.getFileSize();
00216         uint8 *buffer = new uint8[ifile.getFileSize()];
00217         ifile.serialBuffer(buffer, size);
00218 */
00219         uint size = dataSize;
00220         uint8 *buffer = wavData;
00221 
00222         MMIOINFO mmioInfo;
00223         memset(&mmioInfo, 0, sizeof(mmioInfo));
00224         mmioInfo.pchBuffer = (char*)buffer;
00225         mmioInfo.fccIOProc = FOURCC_MEM;
00226         mmioInfo.cchBuffer = size;
00227         
00228 
00229     hmmio = mmioOpen(NULL, &mmioInfo, MMIO_READ | MMIO_DENYWRITE);
00230 
00231     if (hmmio == NULL) 
00232     {
00233                 delete [] buffer;
00234         throw ESoundDriver("Failed to open the file");
00235     }
00236 
00237 
00238     // Check it's a WAVE file 
00239     riff_chunk.ckid = FOURCC_RIFF;
00240 
00241     error = (sint) mmioDescend(hmmio, &riff_chunk, NULL, 0);
00242 
00243     if ((error != 0) || (riff_chunk.ckid != FOURCC_RIFF) || (riff_chunk.fccType != mmioFOURCC('W', 'A', 'V', 'E'))) 
00244     {
00245         mmioClose(hmmio, 0);
00246                 delete buffer;
00247         throw ESoundDriver("Not a WAVE file");
00248     }
00249 
00250 
00251     // Search the format chunk 
00252     chunk.ckid = mmioFOURCC('f', 'm', 't', ' ');
00253 
00254     error = (sint) mmioDescend(hmmio, &chunk, &riff_chunk, MMIO_FINDCHUNK);
00255 
00256     if (error != 0) 
00257     {
00258         mmioClose(hmmio, 0);
00259 
00260                 delete [] buffer;
00261         throw ESoundDriver("Couldn't find the format chunk");
00262     }
00263 
00264     if (chunk.cksize < (long) sizeof(PCMWAVEFORMAT)) 
00265     {
00266         mmioClose(hmmio, 0);
00267                 delete [] buffer;
00268         throw ESoundDriver("Invalid format chunk size");
00269     }
00270 
00271 
00272     // read in the format data
00273 
00274     num = mmioRead(hmmio, (HPSTR) &format, (long) sizeof(format));
00275     if (num != (long) sizeof(format)) 
00276     {
00277         mmioClose(hmmio, 0);
00278                 delete [] buffer;
00279         throw ESoundDriver("Read failed");
00280     }
00281 
00282     format.cbSize = 0;
00283 
00284     // Get out of the format chunk
00285 
00286     if (mmioAscend(hmmio, &chunk, 0) != 0) 
00287     {
00288         mmioClose(hmmio, 0);
00289                 delete [] buffer;
00290         throw ESoundDriver("Read failed");
00291     }
00292 
00293 
00294     // copy the format data 
00295 
00296     if (format.wFormatTag != WAVE_FORMAT_PCM) 
00297     {
00298         mmioClose(hmmio, 0);
00299                 delete [] buffer;
00300         throw ESoundDriver("Unsupported sample format");
00301     }
00302 
00303     _Freq = format.nSamplesPerSec;
00304 
00305     if (format.nChannels == 1) 
00306     {
00307         if (format.wBitsPerSample == 8)
00308         {
00309             _Format = Mono8;
00310         } 
00311         else if (format.wBitsPerSample == 16)
00312         {
00313             _Format = Mono16;
00314         }
00315         else
00316         {
00317             mmioClose(hmmio, 0);
00318                         delete [] buffer;
00319             throw ESoundDriver("Unsupported sample size");
00320         }
00321     }
00322     else if (format.nChannels == 2)
00323     {
00324         if (format.wBitsPerSample == 8)
00325         {
00326             _Format = Stereo8;
00327         } 
00328         else if (format.wBitsPerSample == 16)
00329         {
00330             _Format = Stereo16;
00331         }
00332         else
00333         {
00334             mmioClose(hmmio, 0);
00335                         delete [] buffer;
00336             throw ESoundDriver("Unsupported sample size");
00337         }
00338     }
00339     else // Shouldn't normally happen
00340     {
00341         mmioClose(hmmio, 0);
00342                 delete [] buffer;
00343         throw ESoundDriver("Unsupported number of channels");
00344     }
00345 
00346     
00347     // Set the file position to the beginning of the data chunk */
00348  
00349     sint32 pos = mmioSeek(hmmio, riff_chunk.dwDataOffset + sizeof(FOURCC), SEEK_SET);
00350 
00351     if (pos < 0) 
00352     {
00353         mmioClose(hmmio, 0);
00354                 delete [] buffer;
00355         throw ESoundDriver("Read to set the read position");
00356     }
00357 
00358     data_chunk.ckid = mmioFOURCC('d', 'a', 't', 'a');
00359 
00360     if (mmioDescend(hmmio, &data_chunk, &riff_chunk, MMIO_FINDCHUNK) != 0) 
00361     {
00362         mmioClose(hmmio, 0);
00363                 delete [] buffer;
00364         throw ESoundDriver("Read to set the read position");
00365     }
00366 
00367 
00368     // Allocate the sample buffer
00369     _Size = data_chunk.cksize;
00370 
00371     _Data = new uint8[_Size];
00372 
00373     if (_Data == NULL)
00374     {
00375         mmioClose(hmmio, 0);
00376                 delete [] buffer;
00377         throw ESoundDriver("Out of memory");
00378     }
00379 
00380 
00381     // Read the sample data
00382 
00383     num = mmioRead(hmmio, (HPSTR) _Data, _Size);
00384 
00385     if (num < 0) 
00386     {
00387                 delete [] buffer;
00388         throw ESoundDriver("Failed to read the samples");
00389     }
00390     else if ((uint32) num < _Size)
00391     {
00392         // FIXME: print warning or throw exception ???
00393         char* p = (char*) _Data;
00394         ZeroMemory(p + num, _Size - num);
00395     }
00396 
00397 
00398     mmioClose(hmmio, 0);
00399 
00400 //      delete [] buffer;
00401 
00402         static NLMISC::TStringId        empty(CSoundDriverDSound::instance()->getStringMapper()->map(""));
00403 //      NLMISC::TStringId name = CSoundDriverDSound::instance()->getStringMapper()->map(CFile::getFilenameWithoutExtension(file));
00404         NLMISC::TStringId nameId = CSoundDriverDSound::instance()->getStringMapper()->map(CFile::getFilenameWithoutExtension(name));
00405         // if name is preseted, the name must match.
00406         if (_Name != empty)
00407         {
00408                 nlassertex(nameId == _Name, ("The preseted name and buffer name doen't match !"));
00409         }
00410         _Name = nameId;
00411 
00412         return true;
00413 }

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

Set the sample format. Example: freq=44100.

Implements NLSOUND::IBuffer.

Definition at line 156 of file buffer_dsound.cpp.

References _Format, _Freq, format, and uint.

00157 {
00158     _Format = format;
00159     _Freq = freq;
00160 }

virtual void NLSOUND::IBuffer::setSize uint32  size  )  [inline, virtual, inherited]
 

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

Reimplemented in NLSOUND::CBufferAL.

Definition at line 73 of file buffer.h.

References size, and uint32.

00073 { throw ESoundDriverNotSupp(); }


Field Documentation

uint8* NLSOUND::CBufferDSound::_Data [private]
 

Definition at line 114 of file buffer_dsound.h.

TSampleFormat NLSOUND::CBufferDSound::_Format [private]
 

Definition at line 118 of file buffer_dsound.h.

Referenced by CBufferDSound(), getBufferADPCMEncoded(), getBufferMono16(), getDuration(), getFormat(), isStereo(), readRawBuffer(), readWavBuffer(), and setFormat().

uint NLSOUND::CBufferDSound::_Freq [private]
 

Definition at line 120 of file buffer_dsound.h.

Referenced by CBufferDSound(), getDuration(), getFormat(), readRawBuffer(), readWavBuffer(), and setFormat().

NLMISC::TStringId NLSOUND::CBufferDSound::_Name [private]
 

Definition at line 112 of file buffer_dsound.h.

uint32 NLSOUND::CBufferDSound::_Size [private]
 

Definition at line 116 of file buffer_dsound.h.


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 14:34:08 2004 for NeL by doxygen 1.3.6