Go back to floating point hermite resampler.

16-bit fixed point doesn't have enough accuracy for a decent SNR with hermite.
This commit is contained in:
Brandon Wright 2012-04-07 16:49:55 -05:00
parent 4f551d3d29
commit 53defb5b11
1 changed files with 25 additions and 28 deletions

View File

@ -14,30 +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 (int32 mu1, int32 a, int32 b, int32 c, int32 d)
static inline float
hermite (float mu1, float a, float b, float c, float d)
{
int32 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) << 14;
m1 = (d - b) << 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 ((a0 * b) +
((a1 * m0) >> 15) +
((a2 * m1) >> 15) +
(a3 * c)) >> 15;
return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
}
public:
@ -53,7 +50,7 @@ class HermiteResampler : public Resampler
void
time_ratio (double ratio)
{
r_step = (1 << 16) * ratio;
r_step = ratio;
clear ();
}
@ -61,7 +58,7 @@ class HermiteResampler : public Resampler
clear (void)
{
ring_buffer::clear ();
r_frac = (1 << 16);
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;
}
@ -79,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 << 16) && o_position < num_samples)
while (r_frac <= 1.0 && o_position < num_samples)
{
hermite_val = hermite (r_frac >> 1, r_left [0], r_left [1], r_left [2], r_left [3]);
data[o_position] = SHORT_CLAMP (hermite_val);
hermite_val = hermite (r_frac >> 1, 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 << 16))
if (r_frac > 1.0)
{
r_left [0] = r_left [1];
r_left [1] = r_left [2];
@ -105,7 +102,7 @@ class HermiteResampler : public Resampler
r_right[2] = r_right[3];
r_right[3] = s_right;
r_frac -= (1 << 16);
r_frac -= 1.0;
i_position += 2;
if (i_position >= max_samples)
@ -123,7 +120,7 @@ class HermiteResampler : public Resampler
inline int
avail (void)
{
return ((((uint32) size) << 14) - r_frac) / r_step * 2;
return (int) floor (((size >> 2) - r_frac) / r_step) * 2;
}
};