1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-05-23 18:52:28 -04: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); if (a->ncoef == 0) a->ncoef = (int)(140.0 * full_rate / min_rate);
a->ncoef = (a->ncoef / a->L + 1) * a->L; a->ncoef = (a->ncoef / a->L + 1) * a->L;
a->cpp = a->ncoef / 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); impulse = FIR::fir_bandpass(a->ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, a->gain * (float)a->L);
i = 0; i = 0;
for (j = 0; j < a->L; j++) for (j = 0; j < a->L; j++)
for (k = 0; k < a->ncoef; k += a->L) for (k = 0; k < a->ncoef; k += a->L)
a->h[i++] = impulse[j + k]; a->h[i++] = impulse[j + k];
a->ringsize = a->cpp; 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->idx_in = a->ringsize - 1;
a->phnum = 0; a->phnum = 0;
delete[] (impulse); delete[] (impulse);
@ -88,7 +88,17 @@ void RESAMPLE::decalc_resample (RESAMPLE *a)
delete[] (a->h); 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; RESAMPLE *a = new RESAMPLE;
@ -116,7 +126,7 @@ void RESAMPLE::destroy_resample (RESAMPLE *a)
void RESAMPLE::flush_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->idx_in = a->ringsize - 1;
a->phnum = 0; a->phnum = 0;
} }
@ -129,7 +139,7 @@ int RESAMPLE::xresample (RESAMPLE *a)
{ {
int i, j, n; int i, j, n;
int idx_out; int idx_out;
float I, Q; double I, Q;
for (i = 0; i < a->size; i++) for (i = 0; i < a->size; i++)
{ {

View File

@ -47,22 +47,32 @@ public:
float* out; // output buffer for resampler float* out; // output buffer for resampler
int in_rate; int in_rate;
int out_rate; int out_rate;
float fcin; double fcin;
float fc; double fc;
float fc_low; double fc_low;
float gain; double gain;
int idx_in; // index for input into ring int idx_in; // index for input into ring
int ncoefin; int ncoefin;
int ncoef; // number of coefficients int ncoef; // number of coefficients
int L; // interpolation factor int L; // interpolation factor
int M; // decimation factor int M; // decimation factor
float* h; // coefficients double* h; // coefficients
int ringsize; // number of complex pairs the ring buffer holds 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 cpp; // coefficients of the phase
int phnum; // phase number 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 destroy_resample (RESAMPLE *a);
static void flush_resample (RESAMPLE *a); static void flush_resample (RESAMPLE *a);
static int xresample (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->inresamp = RESAMPLE::create_resample (
d->resamprun, d->resamprun,
d->bsize, d->in, d->bsize,
d->in,
d->inbuff, d->inbuff,
d->inrate, d->inrate,
d->internalrate, d->internalrate,