#include <buffer.h>
Inheritance diagram for NLSOUND::IBuffer:

Nevrax France
Definition at line 44 of file buffer.h.
Source properties | |
| virtual uint32 | getBufferADPCMEncoded (std::vector< uint8 > &result)=0 |
| virtual uint32 | getBufferMono16 (std::vector< sint16 > &result)=0 |
| void | decodeADPCM (uint8 *indata, sint16 *outdata, uint nbSample, TADPCMState &state) |
| void | encodeADPCM (sint16 *indata, uint8 *outdata, uint nbSample, TADPCMState &state) |
| const sint | _IndexTable [16] |
| const uint | _StepsizeTable [89] |
Public Member Functions | |
| virtual bool | fillBuffer (void *src, uint32 bufsize)=0 |
| Set the buffer size and fill the buffer. Return true if ok. Call setFormat() first. | |
| virtual bool | fillMore (void *src, uint32 srcsize) |
| virtual float | getDuration () const=0 |
| Return the duration (in ms) of the sample in the buffer. | |
| virtual void | getFormat (TSampleFormat &format, uint &freq) const=0 |
| Return the format and frequency. | |
| virtual const NLMISC::TStringId & | getName ()=0 |
| Return the name of this buffer. | |
| virtual uint32 | getSize () const=0 |
| Return the size of the buffer, in bytes. | |
| virtual bool | isBufferLoaded ()=0 |
| Return true if the buffer is loaded. Used for async load/unload. | |
| virtual bool | isFillMoreSupported () const=0 |
| virtual bool | isStereo () const=0 |
| Return true if the buffer is stereo, false if mono. | |
| virtual void | presetName (const NLMISC::TStringId &bufferName)=0 |
| virtual void | setFormat (TSampleFormat format, uint freq)=0 |
| Set the sample format. Example: freq=44100. | |
| virtual void | setSize (uint32 size) |
| Force the buffer size without filling data (if isFillMoreSupported() only). | |
| virtual | ~IBuffer () |
| Destructor. | |
Protected Member Functions | |
| IBuffer () | |
| Constructor. | |
|
|
Constructor.
Definition at line 119 of file buffer.h.
00119 {};
|
|
|
Destructor.
Definition at line 124 of file buffer.h.
00124 {}
|
|
||||||||||||||||||||
|
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 _IndexTable, _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 }
|
|
||||||||||||||||||||
|
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 _IndexTable, _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 }
|
|
||||||||||||
|
Set the buffer size and fill the buffer. Return true if ok. Call setFormat() first.
Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::ILoader::fillBuffer(), NLSOUND::ILoader::fillBufferPart(), and NLSOUND::CSoundDriverAL::loadWavFile(). |
|
||||||||||||
|
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(); }
|
|
|
Unoptimized utility function designed to build ADPCM encoded sample bank file. Return the number of sample in the buffer. Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. |
|
|
Unoptimized utility function designed to build Mono 16 bits encoded sample bank file. Return the number of sample in the buffer. Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. |
|
|
Return the duration (in ms) of the sample in the buffer.
Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. |
|
||||||||||||
|
Return the format and frequency.
Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::CSourceDSound::getPitch(), NLSOUND::CSourceDSound::getTime(), NLSOUND::CSourceDSound::play(), and NLSOUND::CSourceDSound::setPitch(). |
|
|
Return the name of this buffer.
Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::CSimpleSound::setBuffer(). |
|
|
Return the size of the buffer, in bytes.
Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::ILoader::fillBufferPart(), NLSOUND::CSampleBank::load(), and NLSOUND::CSourceDSound::play(). |
|
|
Return true if the buffer is loaded. Used for async load/unload.
Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::CSimpleSource::play(). |
|
|
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 Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::ILoader::fillBufferPart(). |
|
|
Return true if the buffer is stereo, false if mono.
Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::CAudioMixerUser::createSource(), NLSOUND::CSimpleSource::play(), and NLSOUND::CSimpleSource::setDirection(). |
|
|
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. Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::CSampleBank::load(). |
|
||||||||||||
|
Set the sample format. Example: freq=44100.
Implemented in NLSOUND::CBufferDSound, and NLSOUND::CBufferAL. Referenced by NLSOUND::CSoundDriverAL::loadWavFile(). |
|
|
Force the buffer size without filling data (if isFillMoreSupported() only).
Reimplemented in NLSOUND::CBufferAL. Definition at line 73 of file buffer.h.
00073 { throw ESoundDriverNotSupp(); }
|
|
|
Initial value:
{
-1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8,
}
Definition at line 31 of file buffer.cpp. Referenced by decodeADPCM(), and encodeADPCM(). |
|
|
Initial value:
{
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
}
Definition at line 37 of file buffer.cpp. Referenced by decodeADPCM(), and encodeADPCM(). |
1.3.6