Revert "Change hermite resampler to use fixed-point arithmetic for speed on"

This reverts commit 2411daa2e7.
This commit is contained in:
Brandon Wright 2012-02-01 14:45:31 -06:00
parent b66f00d6f4
commit 986289a96c

View File

@ -14,32 +14,27 @@ class HermiteResampler : public Resampler
{
protected:
uint32 r_step;
uint32 r_frac;
float r_step;
float r_frac;
int r_left[4], r_right[4];
static inline int32
hermite (uint32 mu1, int32 a, int32 b, int32 c, int32 d)
static inline float
hermite (float mu1, float a, float b, float c, float d)
{
uint32 mu2, mu3, m0, m1, a0, a1, a2, a3;
float mu2, mu3, m0, m1, a0, a1, a2, a3;
mu2 = (mu1 * mu1) >> 15;
mu3 = (mu2 * mu1) >> 15;
mu2 = mu1 * mu1;
mu3 = mu2 * mu1;
m0 = (c - a + 32768) << 14;
m1 = (d - b + 32768) << 14;
m0 = (c - a) * 0.5;
m1 = (d - b) * 0.5;
a0 = (mu3 << 1) - (3 * mu2) + (1 << 15);
a1 = mu3 - (mu2 << 1) + mu1;
a2 = mu3 - mu2;
a3 = 3 * mu2 - (mu3 << 1);
a0 = +2 * mu3 - 3 * mu2 + 1;
a1 = mu3 - 2 * mu2 + mu1;
a2 = mu3 - mu2;
a3 = -2 * mu3 + 3 * mu2;
return (int32) ((
(a0 * (b + 32768)) +
((a1 * m0) >> 15) +
((a2 * m1) >> 15) +
(a3 * (c + 32768))
) >> 15) - 32768;
return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
}
public:
@ -55,7 +50,7 @@ class HermiteResampler : public Resampler
void
time_ratio (double ratio)
{
r_step = (1 << 15) * ratio;
r_step = ratio;
clear ();
}
@ -63,7 +58,7 @@ class HermiteResampler : public Resampler
clear (void)
{
ring_buffer::clear ();
r_frac = (1 << 15);
r_frac = 1.0;
r_left [0] = r_left [1] = r_left [2] = r_left [3] = 0;
r_right[0] = r_right[1] = r_right[2] = r_right[3] = 0;
}
@ -81,21 +76,21 @@ class HermiteResampler : public Resampler
{
int s_left = internal_buffer[i_position];
int s_right = internal_buffer[i_position + 1];
int hermite_val;
float hermite_val[2];
while (r_frac <= (1 << 15) && o_position < num_samples)
while (r_frac <= 1.0 && o_position < num_samples)
{
hermite_val = hermite (r_frac, r_left [0], r_left [1], r_left [2], r_left [3]);
data[o_position] = SHORT_CLAMP (hermite_val);
hermite_val = hermite (r_frac, r_right[0], r_right[1], r_right[2], r_right[3]);
data[o_position + 1] = SHORT_CLAMP (hermite_val);
hermite_val[0] = hermite (r_frac, r_left [0], r_left [1], r_left [2], r_left [3]);
hermite_val[1] = hermite (r_frac, r_right[0], r_right[1], r_right[2], r_right[3]);
data[o_position] = SHORT_CLAMP (hermite_val[0]);
data[o_position + 1] = SHORT_CLAMP (hermite_val[1]);
o_position += 2;
r_frac += r_step;
}
if (r_frac > (1 << 15))
if (r_frac > 1.0)
{
r_left [0] = r_left [1];
r_left [1] = r_left [2];
@ -107,7 +102,7 @@ class HermiteResampler : public Resampler
r_right[2] = r_right[3];
r_right[3] = s_right;
r_frac -= (1 << 15);
r_frac -= 1.0;
i_position += 2;
if (i_position >= max_samples)
@ -125,7 +120,7 @@ class HermiteResampler : public Resampler
inline int
avail (void)
{
return ((((uint32) size) << 13) - r_frac) / r_step * 2;
return (int) floor (((size >> 2) - r_frac) / r_step) * 2;
}
};