MCPcopy Create free account
hub / github.com/JACoders/OpenJK / ResampleSfx

Function ResampleSfx

code/client/snd_mem.cpp:210–253  ·  view source on GitHub ↗

================ ResampleSfx resample / decimate to the current source rate ================ */

Source from the content-addressed store, hash-verified

208================
209*/
210void ResampleSfx (sfx_t *sfx, int iInRate, int iInWidth, byte *pData)
211{
212 int iOutCount;
213 int iSrcSample;
214 float fStepScale;
215 int i;
216 int iSample;
217 unsigned int uiSampleFrac, uiFracStep; // uiSampleFrac MUST be unsigned, or large samples (eg music tracks) crash
218
219 fStepScale = (float)iInRate / dma.speed; // this is usually 0.5, 1, or 2
220
221 // When stepscale is > 1 (we're downsampling), we really ought to run a low pass filter on the samples
222
223 iOutCount = (int)(sfx->iSoundLengthInSamples / fStepScale);
224 sfx->iSoundLengthInSamples = iOutCount;
225
226 sfx->pSoundData = (short *) SND_malloc( sfx->iSoundLengthInSamples*2 ,sfx );
227
228 sfx->fVolRange = 0;
229 uiSampleFrac = 0;
230 uiFracStep = (int)(fStepScale*256);
231
232 for (i=0 ; i<sfx->iSoundLengthInSamples ; i++)
233 {
234 iSrcSample = uiSampleFrac >> 8;
235 uiSampleFrac += uiFracStep;
236 if (iInWidth == 2) {
237 iSample = LittleShort ( ((short *)pData)[iSrcSample] );
238 } else {
239 iSample = (unsigned int)( (unsigned char)(pData[iSrcSample]) - 128) << 8;
240 }
241
242 sfx->pSoundData[i] = (short)iSample;
243
244 // work out max vol for this sample...
245 //
246 if (iSample < 0)
247 iSample = -iSample;
248 if (sfx->fVolRange < (iSample >> 8) )
249 {
250 sfx->fVolRange = iSample >> 8;
251 }
252 }
253}
254
255
256//=============================================================================

Callers 2

S_LoadSound_FinalizeFunction · 0.70
S_LoadSound_ActualFunction · 0.70

Calls 1

SND_mallocFunction · 0.70

Tested by

no test coverage detected