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

This reverts commit 986289a96c.
This commit is contained in:
Brandon Wright 2012-02-02 15:47:44 -06:00
parent 986289a96c
commit 93cf0a77b9
1 changed files with 30 additions and 25 deletions

View File

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