1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-10 18:43:28 -05:00

WDSP: fixed resampler

This commit is contained in:
f4exb 2024-07-06 22:42:07 +02:00
parent 44fb308c4a
commit 07e179c196
3 changed files with 34 additions and 13 deletions

View File

@ -69,14 +69,14 @@ void RESAMPLE::calc_resample (RESAMPLE *a)
if (a->ncoef == 0) a->ncoef = (int)(140.0 * full_rate / min_rate);
a->ncoef = (a->ncoef / a->L + 1) * a->L;
a->cpp = a->ncoef / a->L;
a->h = new float[a->ncoef]; // (float *)malloc0(a->ncoef * sizeof(float));
a->h = new double[a->ncoef]; // (float *)malloc0(a->ncoef * sizeof(float));
impulse = FIR::fir_bandpass(a->ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, a->gain * (float)a->L);
i = 0;
for (j = 0; j < a->L; j++)
for (k = 0; k < a->ncoef; k += a->L)
a->h[i++] = impulse[j + k];
a->ringsize = a->cpp;
a->ring = new float[a->ringsize]; // (float *)malloc0(a->ringsize * sizeof(complex));
a->ring = new double[a->ringsize]; // (float *)malloc0(a->ringsize * sizeof(complex));
a->idx_in = a->ringsize - 1;
a->phnum = 0;
delete[] (impulse);
@ -88,7 +88,17 @@ void RESAMPLE::decalc_resample (RESAMPLE *a)
delete[] (a->h);
}
RESAMPLE* RESAMPLE::create_resample ( int run, int size, float* in, float* out, int in_rate, int out_rate, float fc, int ncoef, float gain)
RESAMPLE* RESAMPLE::create_resample (
int run,
int size,
float* in,
float* out,
int in_rate,
int out_rate,
double fc,
int ncoef,
double gain
)
{
RESAMPLE *a = new RESAMPLE;
@ -116,7 +126,7 @@ void RESAMPLE::destroy_resample (RESAMPLE *a)
void RESAMPLE::flush_resample (RESAMPLE *a)
{
memset (a->ring, 0, a->ringsize * sizeof (wcomplex));
std::fill(a->ring, a->ring + 2 * a->ringsize, 0);
a->idx_in = a->ringsize - 1;
a->phnum = 0;
}
@ -129,7 +139,7 @@ int RESAMPLE::xresample (RESAMPLE *a)
{
int i, j, n;
int idx_out;
float I, Q;
double I, Q;
for (i = 0; i < a->size; i++)
{

View File

@ -47,22 +47,32 @@ public:
float* out; // output buffer for resampler
int in_rate;
int out_rate;
float fcin;
float fc;
float fc_low;
float gain;
double fcin;
double fc;
double fc_low;
double gain;
int idx_in; // index for input into ring
int ncoefin;
int ncoef; // number of coefficients
int L; // interpolation factor
int M; // decimation factor
float* h; // coefficients
double* h; // coefficients
int ringsize; // number of complex pairs the ring buffer holds
float* ring; // ring buffer
double* ring; // ring buffer
int cpp; // coefficients of the phase
int phnum; // phase number
static RESAMPLE* create_resample (int run, int size, float* in, float* out, int in_rate, int out_rate, float fc, int ncoef, float gain);
static RESAMPLE* create_resample (
int run,
int size,
float* in,
float* out,
int in_rate,
int out_rate,
double fc,
int ncoef,
double gain
);
static void destroy_resample (RESAMPLE *a);
static void flush_resample (RESAMPLE *a);
static int xresample (RESAMPLE *a);

View File

@ -58,7 +58,8 @@ void SNBA::calc_snba (SNBA *d)
d->inresamp = RESAMPLE::create_resample (
d->resamprun,
d->bsize, d->in,
d->bsize,
d->in,
d->inbuff,
d->inrate,
d->internalrate,