Skip to content

Commit

Permalink
Bunch of resampling fixes made for ut2004 retail.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jun 28, 2004
1 parent f94bc79 commit 0096e06
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
9 changes: 8 additions & 1 deletion osx/AL_EXT_vorbis/al_ext_vorbis.c
Expand Up @@ -94,6 +94,9 @@ static inline ALvoid __alMixVorbisMono(ALcontext *ctx, ALsource *src,
Float32 *dst, Float32 *in, long samples,
UInt32 devchannels)
{
#if 1
assert(0); // !!! FIXME: Updated for > 2 channels.
#else
register Float32 sample;
register Float32 gain0;
register Float32 gain1;
Expand Down Expand Up @@ -128,6 +131,7 @@ static inline ALvoid __alMixVorbisMono(ALcontext *ctx, ALsource *src,
dst[channel2] += sample * gain2;
dst += devchannels;
} // while
#endif
} // __alMixVorbisMono


Expand Down Expand Up @@ -320,8 +324,11 @@ UInt32 __alMixVorbis(struct ALcontext_struct *ctx, struct ALbuffer_struct *buf,
} // __alMixVorbis


static ALboolean __alPrepareBufferVorbis(ALsource *src, ALbuffer *buf)
static ALboolean __alPrepareBufferVorbis(ALcontext *ctx,
ALsource *src,
ALbuffer *buf)
{
// !!! FIXME: Note context sample rate.
VorbisOpaque *o = calloc(1, sizeof (VorbisOpaque));
if (o == NULL)
{
Expand Down
58 changes: 48 additions & 10 deletions osx/alBuffer.c
Expand Up @@ -291,8 +291,8 @@ ALboolean __alResampleStereo8(ALvoid *_src, ALsizei _srcsize,
register int dstsize = _dstsize;
register int eps = 0;
_srcsize -= 4; // fudge factor.
sampL = (SInt32) src[0];
sampR = (SInt32) src[1];
sampL = ((SInt32) src[0]) - 128;
sampR = ((SInt32) src[1]) - 128;
while (dst != max)
{
dst[0] = sampL;
Expand All @@ -302,8 +302,8 @@ ALboolean __alResampleStereo8(ALvoid *_src, ALsizei _srcsize,
if ((eps << 1) >= dstsize)
{
src += 2;
sampL = (src[0] + lastSampL) >> 1;
sampR = (src[1] + lastSampR) >> 1;
sampL = ((((SInt32) src[0]) - 128) + lastSampL) >> 1;
sampR = ((((SInt32) src[1]) - 128) + lastSampR) >> 1;
lastSampL = sampL;
lastSampR = sampR;
eps -= dstsize;
Expand Down Expand Up @@ -369,8 +369,8 @@ ALboolean __alResampleStereo8(ALvoid *_src, ALsizei _srcsize,
register int srcsize = _srcsize;
register int eps = 0;
srcsize -= 4; // fudge factor.
lastSampL = sampL = (SInt32) src[0];
lastSampR = sampR = (SInt32) src[1];
lastSampL = sampL = ((SInt32) src[0]) - 128;
lastSampR = sampR = ((SInt32) src[1]) - 128;
while (dst != max)
{
src += 2;
Expand Down Expand Up @@ -708,7 +708,7 @@ ALboolean __alResampleMono8(ALvoid *_src, ALsizei _srcsize,
register int srcsize = _srcsize;
register int eps = 0;
srcsize -= 2; // fudge factor.
samp = (SInt32) *src;
samp = ((SInt32) *src) - 128;
while (dst != max)
{
*dst = samp;
Expand Down Expand Up @@ -779,7 +779,7 @@ ALboolean __alResampleMono8(ALvoid *_src, ALsizei _srcsize,
register int srcsize = _srcsize;
register int eps = 0;
srcsize -= 2; // fudge factor.
lastSamp = samp = (SInt32) *src;
lastSamp = samp = ((SInt32) *src) - 128;
while (dst != max)
{
src++;
Expand Down Expand Up @@ -1096,13 +1096,51 @@ ALboolean __alResampleMonoFloat32(ALvoid *_src, ALsizei _srcsize,

else // arbitrary upsampling.
{
assert(0); // !!! FIXME: Fill this in when you finish debugging the integer version.
// Arbitrary upsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
register int dstsize = _dstsize;
register int srcsize = _srcsize;
register int eps = 0;
srcsize -= 4; // fudge factor.
samp = (SInt32) *src;
while (dst != max)
{
*dst = samp;
dst++;
eps += srcsize;
if ((eps << 1) >= dstsize)
{
src++;
samp = (*src + lastSamp) * 0.5f;
lastSamp = samp;
eps -= dstsize;
} // if
} // while
} // else
} // if

else // downsampling
{
assert(0); // !!! FIXME: Fill this in when you finish debugging the integer version.
// Arbitrary downsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
register int dstsize = _dstsize;
register int srcsize = _srcsize;
register int eps = 0;
srcsize -= 4; // fudge factor.
lastSamp = samp = (SInt32) *src;
while (dst != max)
{
src++;
eps += dstsize;
if ((eps << 1) >= srcsize)
{
*dst = samp;
dst++;
samp = (*src + lastSamp) * 0.5f;
lastSamp = samp;
eps -= srcsize;
} // if
} // while
} // else

return(AL_TRUE);
Expand Down

0 comments on commit 0096e06

Please sign in to comment.