Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replaced all downsamplers with Bresenham.
  • Loading branch information
icculus committed Nov 16, 2003
1 parent 708fcfd commit e9605a4
Showing 1 changed file with 110 additions and 8 deletions.
118 changes: 110 additions & 8 deletions osx/alBuffer.c
Expand Up @@ -235,7 +235,6 @@ static ALboolean __alBufferDataFromStereo8(ALcontext *ctx, ALbuffer *buf,
register SInt32 lastSampR = ((SInt32) src[1]) - 128;
register SInt32 sampL;
register SInt32 sampR;
register int maxincr;

// resample to device frequency...

Expand Down Expand Up @@ -287,7 +286,7 @@ static ALboolean __alBufferDataFromStereo8(ALcontext *ctx, ALbuffer *buf,
#if 0 // broken
register SInt32 linear_counter;
register int incr;
maxincr = (int) ratio;
register int maxincr = (int) ratio;
while (dst != max)
{
sampL = ((SInt32) src[0])-128;
Expand All @@ -305,6 +304,7 @@ static ALboolean __alBufferDataFromStereo8(ALcontext *ctx, ALbuffer *buf,
#else
// Arbitrary upsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
// !!! FIXME: Replace with "run lengths".
register int dstsize = buf->allocatedSpace;
register int eps = 0;
size -= 4; // fudge factor.
Expand Down Expand Up @@ -332,7 +332,8 @@ static ALboolean __alBufferDataFromStereo8(ALcontext *ctx, ALbuffer *buf,

else // downsampling
{
maxincr = (((int) ratio) << 1);
#if 0
register int maxincr = (((int) ratio) << 1);

while (dst != max)
{
Expand All @@ -345,6 +346,32 @@ static ALboolean __alBufferDataFromStereo8(ALcontext *ctx, ALbuffer *buf,
lastSampR = sampR;
dst += 2;
} // while
#else
// Arbitrary downsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
// !!! FIXME: Replace with "run lengths".
register int dstsize = buf->allocatedSpace;
register int eps = 0;
size -= 4; // fudge factor.
lastSampL = sampL = (SInt32) src[0];
lastSampR = sampR = (SInt32) src[1];
while (dst != max)
{
src += 2;
eps += dstsize;
if ((eps << 1) >= size)
{
dst[0] = sampL;
dst[1] = sampR;
dst += 2;
sampL = (src[0] + lastSampL) >> 1;
sampR = (src[1] + lastSampR) >> 1;
lastSampL = sampL;
lastSampR = sampR;
eps -= size;
} // if
} // while
#endif
} // else

return(AL_TRUE);
Expand All @@ -364,7 +391,6 @@ static ALboolean __alBufferDataFromStereo16(ALcontext *ctx, ALbuffer *buf,
register SInt32 lastSampR = (SInt32) src[1];
register SInt32 sampL;
register SInt32 sampR;
register int maxincr;

// resample to device frequency...

Expand Down Expand Up @@ -415,7 +441,7 @@ static ALboolean __alBufferDataFromStereo16(ALcontext *ctx, ALbuffer *buf,
#if 0 // broken
register SInt32 linear_counter;
register int incr;
maxincr = (int) ratio;
register int maxincr = (int) ratio;
while (dst != max)
{
sampL = (SInt32) src[0];
Expand All @@ -433,6 +459,7 @@ static ALboolean __alBufferDataFromStereo16(ALcontext *ctx, ALbuffer *buf,
#else
// Arbitrary upsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
// !!! FIXME: Replace with "run lengths".
register int dstsize = buf->allocatedSpace;
register int eps = 0;
size -= 8; // fudge factor.
Expand Down Expand Up @@ -460,7 +487,8 @@ static ALboolean __alBufferDataFromStereo16(ALcontext *ctx, ALbuffer *buf,

else // downsampling
{
maxincr = (((int) ratio) << 1);
#if 0
register int maxincr = (((int) ratio) << 1);

while (dst != max)
{
Expand All @@ -473,6 +501,32 @@ static ALboolean __alBufferDataFromStereo16(ALcontext *ctx, ALbuffer *buf,
lastSampR = sampR;
dst += 2;
} // while
#else
// Arbitrary downsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
// !!! FIXME: Replace with "run lengths".
register int dstsize = buf->allocatedSpace;
register int eps = 0;
size -= 8; // fudge factor.
lastSampL = sampL = (SInt32) src[0];
lastSampR = sampR = (SInt32) src[1];
while (dst != max)
{
src += 2;
eps += dstsize;
if ((eps << 1) >= size)
{
dst[0] = sampL;
dst[1] = sampR;
dst += 2;
sampL = (src[0] + lastSampL) >> 1;
sampR = (src[1] + lastSampR) >> 1;
lastSampL = sampL;
lastSampR = sampR;
eps -= size;
} // if
} // while
#endif
} // else

return(AL_TRUE);
Expand Down Expand Up @@ -544,7 +598,7 @@ static ALboolean __alBufferDataFromMono8(ALcontext *ctx, ALbuffer *buf,
#if 0 // broken!
register SInt32 linear_counter;
register int incr;
maxincr = (int) ratio;
register int maxincr = (int) ratio;
while (dst != max)
{
samp = ((SInt32) *src) - 128; // -128 to convert to signed.
Expand All @@ -569,6 +623,7 @@ static ALboolean __alBufferDataFromMono8(ALcontext *ctx, ALbuffer *buf,
#else
// Arbitrary upsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
// !!! FIXME: Replace with "run lengths".
register int dstsize = buf->allocatedSpace;
register int eps = 0;
size -= 2; // fudge factor.
Expand All @@ -592,6 +647,7 @@ static ALboolean __alBufferDataFromMono8(ALcontext *ctx, ALbuffer *buf,

else // downsampling
{
#if 0
register float pos = 0.0f; // !!! FIXME: SLOW!
while (dst != max)
{
Expand All @@ -601,6 +657,28 @@ static ALboolean __alBufferDataFromMono8(ALcontext *ctx, ALbuffer *buf,
lastSamp = samp;
dst++;
} // while
#else
// Arbitrary downsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
// !!! FIXME: Replace with "run lengths".
register int dstsize = buf->allocatedSpace;
register int eps = 0;
size -= 2; // fudge factor.
lastSamp = samp = (SInt32) *src;
while (dst != max)
{
src++;
eps += dstsize;
if ((eps << 1) >= size)
{
*dst = samp;
dst++;
samp = (*src + lastSamp) >> 1;
lastSamp = samp;
eps -= size;
} // if
} // while
#endif
} // else

return(AL_TRUE);
Expand Down Expand Up @@ -658,7 +736,7 @@ static ALboolean __alBufferDataFromMono16(ALcontext *ctx, ALbuffer *buf,
#if 0 // broken!
register SInt32 linear_counter;
register int incr;
maxincr = (int) ratio;
register int maxincr = (int) ratio;
while (dst != max)
{
samp = (SInt32) *src;
Expand All @@ -683,6 +761,7 @@ static ALboolean __alBufferDataFromMono16(ALcontext *ctx, ALbuffer *buf,
#else
// Arbitrary upsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
// !!! FIXME: Replace with "run lengths".
register int dstsize = buf->allocatedSpace;
register int eps = 0;
size -= 4; // fudge factor.
Expand All @@ -706,6 +785,7 @@ static ALboolean __alBufferDataFromMono16(ALcontext *ctx, ALbuffer *buf,

else // downsampling
{
#if 0
register float pos = 0.0f; // !!! FIXME: SLOW!
while (dst != max)
{
Expand All @@ -715,6 +795,28 @@ static ALboolean __alBufferDataFromMono16(ALcontext *ctx, ALbuffer *buf,
lastSamp = samp;
dst++;
} // while
#else
// Arbitrary downsampling based on Bresenham's line algorithm.
// !!! FIXME: Needs better interpolation.
// !!! FIXME: Replace with "run lengths".
register int dstsize = buf->allocatedSpace;
register int eps = 0;
size -= 4; // fudge factor.
lastSamp = samp = (SInt32) *src;
while (dst != max)
{
src++;
eps += dstsize;
if ((eps << 1) >= size)
{
*dst = samp;
dst++;
samp = (*src + lastSamp) >> 1;
lastSamp = samp;
eps -= size;
} // if
} // while
#endif
} // else

return(AL_TRUE);
Expand Down

0 comments on commit e9605a4

Please sign in to comment.