1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 10:05:46 -05:00

WDSP: more double precision calculation

This commit is contained in:
f4exb 2024-07-17 21:19:57 +02:00
parent 3f800dd0a9
commit da7b3fbd41
5 changed files with 179 additions and 44 deletions

View File

@ -39,7 +39,10 @@ void ANB::initBlanker(ANB *a)
{ {
int i; int i;
a->trans_count = (int)(a->tau * a->samplerate); a->trans_count = (int)(a->tau * a->samplerate);
if (a->trans_count < 2) a->trans_count = 2;
if (a->trans_count < 2)
a->trans_count = 2;
a->hang_count = (int)(a->hangtime * a->samplerate); a->hang_count = (int)(a->hangtime * a->samplerate);
a->adv_count = (int)(a->advtime * a->samplerate); a->adv_count = (int)(a->advtime * a->samplerate);
a->count = 0; a->count = 0;
@ -51,8 +54,10 @@ void ANB::initBlanker(ANB *a)
a->power = 1.0; a->power = 1.0;
a->backmult = exp(-1.0 / (a->samplerate * a->backtau)); a->backmult = exp(-1.0 / (a->samplerate * a->backtau));
a->ombackmult = 1.0 - a->backmult; a->ombackmult = 1.0 - a->backmult;
for (i = 0; i <= a->trans_count; i++) for (i = 0; i <= a->trans_count; i++)
a->wave[i] = 0.5 * cos(i * a->coef); a->wave[i] = 0.5 * cos(i * a->coef);
std::fill(a->dline, a->dline + a->dline_size * 2, 0); std::fill(a->dline, a->dline + a->dline_size * 2, 0);
} }
@ -81,7 +86,7 @@ ANB* ANB::create_anb (
a->advtime = advtime; a->advtime = advtime;
a->backtau = backtau; a->backtau = backtau;
a->threshold = threshold; a->threshold = threshold;
a->wave = new float[((int)(MAX_SAMPLERATE * MAX_TAU) + 1)]; a->wave = new double[((int)(MAX_SAMPLERATE * MAX_TAU) + 1)];
a->dline_size = (int)((MAX_TAU + MAX_ADVTIME) * MAX_SAMPLERATE) + 1; a->dline_size = (int)((MAX_TAU + MAX_ADVTIME) * MAX_SAMPLERATE) + 1;
a->dline = new float[a->dline_size * 2]; a->dline = new float[a->dline_size * 2];
initBlanker(a); initBlanker(a);
@ -107,14 +112,18 @@ void ANB::xanb (ANB *a)
double scale; double scale;
double mag; double mag;
int i; int i;
if (a->run) if (a->run)
{ {
for (i = 0; i < a->buffsize; i++) for (i = 0; i < a->buffsize; i++)
{ {
mag = sqrt(a->in[2 * i + 0] * a->in[2 * i + 0] + a->in[2 * i + 1] * a->in[2 * i + 1]); double xr = a->in[2 * i + 0];
double xi = a->in[2 * i + 1];
mag = sqrt(xr*xr + xi*xi);
a->avg = a->backmult * a->avg + a->ombackmult * mag; a->avg = a->backmult * a->avg + a->ombackmult * mag;
a->dline[2 * a->in_idx + 0] = a->in[2 * i + 0]; a->dline[2 * a->in_idx + 0] = a->in[2 * i + 0];
a->dline[2 * a->in_idx + 1] = a->in[2 * i + 1]; a->dline[2 * a->in_idx + 1] = a->in[2 * i + 1];
if (mag > (a->avg * a->threshold)) if (mag > (a->avg * a->threshold))
a->count = a->trans_count + a->adv_count; a->count = a->trans_count + a->adv_count;
@ -123,45 +132,59 @@ void ANB::xanb (ANB *a)
case 0: case 0:
a->out[2 * i + 0] = a->dline[2 * a->out_idx + 0]; a->out[2 * i + 0] = a->dline[2 * a->out_idx + 0];
a->out[2 * i + 1] = a->dline[2 * a->out_idx + 1]; a->out[2 * i + 1] = a->dline[2 * a->out_idx + 1];
if (a->count > 0) if (a->count > 0)
{ {
a->state = 1; a->state = 1;
a->dtime = 0; a->dtime = 0;
a->power = 1.0; a->power = 1.0;
} }
break; break;
case 1: case 1:
scale = a->power * (0.5 + a->wave[a->dtime]); scale = a->power * (0.5 + a->wave[a->dtime]);
a->out[2 * i + 0] = a->dline[2 * a->out_idx + 0] * scale; a->out[2 * i + 0] = a->dline[2 * a->out_idx + 0] * scale;
a->out[2 * i + 1] = a->dline[2 * a->out_idx + 1] * scale; a->out[2 * i + 1] = a->dline[2 * a->out_idx + 1] * scale;
if (++a->dtime > a->trans_count) if (++a->dtime > a->trans_count)
{ {
a->state = 2; a->state = 2;
a->atime = 0; a->atime = 0;
} }
break; break;
case 2: case 2:
a->out[2 * i + 0] = 0.0; a->out[2 * i + 0] = 0.0;
a->out[2 * i + 1] = 0.0; a->out[2 * i + 1] = 0.0;
if (++a->atime > a->adv_count) if (++a->atime > a->adv_count)
a->state = 3; a->state = 3;
break; break;
case 3: case 3:
if (a->count > 0) if (a->count > 0)
a->htime = -a->count; a->htime = -a->count;
a->out[2 * i + 0] = 0.0; a->out[2 * i + 0] = 0.0;
a->out[2 * i + 1] = 0.0; a->out[2 * i + 1] = 0.0;
if (++a->htime > a->hang_count) if (++a->htime > a->hang_count)
{ {
a->state = 4; a->state = 4;
a->itime = 0; a->itime = 0;
} }
break; break;
case 4: case 4:
scale = 0.5 - a->wave[a->itime]; scale = 0.5 - a->wave[a->itime];
a->out[2 * i + 0] = a->dline[2 * a->out_idx + 0] * scale; a->out[2 * i + 0] = a->dline[2 * a->out_idx + 0] * scale;
a->out[2 * i + 1] = a->dline[2 * a->out_idx + 1] * scale; a->out[2 * i + 1] = a->dline[2 * a->out_idx + 1] * scale;
if (a->count > 0) if (a->count > 0)
{ {
a->state = 1; a->state = 1;
@ -169,17 +192,28 @@ void ANB::xanb (ANB *a)
a->power = scale; a->power = scale;
} }
else if (++a->itime > a->trans_count) else if (++a->itime > a->trans_count)
{
a->state = 0; a->state = 0;
}
break; break;
} }
if (a->count > 0) a->count--;
if (++a->in_idx == a->dline_size) a->in_idx = 0; if (a->count > 0)
if (++a->out_idx == a->dline_size) a->out_idx = 0; a->count--;
if (++a->in_idx == a->dline_size)
a->in_idx = 0;
if (++a->out_idx == a->dline_size)
a->out_idx = 0;
} }
} }
else if (a->in != a->out) else if (a->in != a->out)
{
std::copy(a->in, a->in + a->buffsize * 2, a->out); std::copy(a->in, a->in + a->buffsize * 2, a->out);
} }
}
void ANB::setBuffers_anb (ANB *a, float* in, float* out) void ANB::setBuffers_anb (ANB *a, float* in, float* out)
{ {

View File

@ -47,7 +47,7 @@ public:
double advtime; // deadtime (zero output) in advance of detected noise double advtime; // deadtime (zero output) in advance of detected noise
double backtau; // time constant used in averaging the magnitude of the input signal double backtau; // time constant used in averaging the magnitude of the input signal
double threshold; // triggers if (noise > threshold * average_signal_magnitude) double threshold; // triggers if (noise > threshold * average_signal_magnitude)
float *wave; // pointer to array holding transition waveform double *wave; // pointer to array holding transition waveform
int state; // state of the state machine int state; // state of the state machine
double avg; // average value of the signal magnitude double avg; // average value of the signal magnitude
int dtime; // count when decreasing the signal magnitude int dtime; // count when decreasing the signal magnitude

View File

@ -43,6 +43,7 @@ void NOB::init_nob (NOB *a)
{ {
int i; int i;
double coef; double coef;
a->adv_slew_count = (int)(a->advslewtime * a->samplerate); a->adv_slew_count = (int)(a->advslewtime * a->samplerate);
a->adv_count = (int)(a->advtime * a->samplerate); a->adv_count = (int)(a->advtime * a->samplerate);
a->hang_count = (int)(a->hangtime * a->samplerate); a->hang_count = (int)(a->hangtime * a->samplerate);
@ -50,15 +51,19 @@ void NOB::init_nob (NOB *a)
a->max_imp_seq = (int)(a->max_imp_seq_time * a->samplerate); a->max_imp_seq = (int)(a->max_imp_seq_time * a->samplerate);
a->backmult = exp (-1.0 / (a->samplerate * a->backtau)); a->backmult = exp (-1.0 / (a->samplerate * a->backtau));
a->ombackmult = 1.0 - a->backmult; a->ombackmult = 1.0 - a->backmult;
if (a->adv_slew_count > 0) if (a->adv_slew_count > 0)
{ {
coef = PI / (a->adv_slew_count + 1); coef = PI / (a->adv_slew_count + 1);
for (i = 0; i < a->adv_slew_count; i++) for (i = 0; i < a->adv_slew_count; i++)
a->awave[i] = 0.5 * cos ((i + 1) * coef); a->awave[i] = 0.5 * cos ((i + 1) * coef);
} }
if (a->hang_slew_count > 0) if (a->hang_slew_count > 0)
{ {
coef = PI / a->hang_slew_count; coef = PI / a->hang_slew_count;
for (i = 0; i < a->hang_slew_count; i++) for (i = 0; i < a->hang_slew_count; i++)
a->hwave[i] = 0.5 * cos (i * coef); a->hwave[i] = 0.5 * cos (i * coef);
} }
@ -179,14 +184,20 @@ void NOB::xnob (NOB *a)
a->dline[2 * a->in_idx + 1] = a->in[2 * i + 1]; a->dline[2 * a->in_idx + 1] = a->in[2 * i + 1];
mag = sqrt(a->dline[2 * a->in_idx + 0] * a->dline[2 * a->in_idx + 0] + a->dline[2 * a->in_idx + 1] * a->dline[2 * a->in_idx + 1]); mag = sqrt(a->dline[2 * a->in_idx + 0] * a->dline[2 * a->in_idx + 0] + a->dline[2 * a->in_idx + 1] * a->dline[2 * a->in_idx + 1]);
a->avg = a->backmult * a->avg + a->ombackmult * mag; a->avg = a->backmult * a->avg + a->ombackmult * mag;
if (mag > (a->avg * a->threshold)) if (mag > (a->avg * a->threshold))
a->imp[a->in_idx] = 1; a->imp[a->in_idx] = 1;
else else
a->imp[a->in_idx] = 0; a->imp[a->in_idx] = 0;
if ((bf_idx = a->out_idx + a->adv_slew_count) >= a->dline_size) bf_idx -= a->dline_size;
if ((bf_idx = a->out_idx + a->adv_slew_count) >= a->dline_size)
bf_idx -= a->dline_size;
if (a->imp[bf_idx] == 0) if (a->imp[bf_idx] == 0)
{ {
if (++a->bfb_in_idx == a->filterlen) a->bfb_in_idx -= a->filterlen; if (++a->bfb_in_idx == a->filterlen)
a->bfb_in_idx -= a->filterlen;
a->bfbuff[2 * a->bfb_in_idx + 0] = a->dline[2 * bf_idx + 0]; a->bfbuff[2 * a->bfb_in_idx + 0] = a->dline[2 * bf_idx + 0];
a->bfbuff[2 * a->bfb_in_idx + 1] = a->dline[2 * bf_idx + 1]; a->bfbuff[2 * a->bfb_in_idx + 1] = a->dline[2 * bf_idx + 1];
} }
@ -199,31 +210,41 @@ void NOB::xnob (NOB *a)
a->out[2 * i + 1] = a->dline[2 * a->out_idx + 1]; a->out[2 * i + 1] = a->dline[2 * a->out_idx + 1];
a->Ilast = a->dline[2 * a->out_idx + 0]; a->Ilast = a->dline[2 * a->out_idx + 0];
a->Qlast = a->dline[2 * a->out_idx + 1]; a->Qlast = a->dline[2 * a->out_idx + 1];
if (a->imp[a->scan_idx] > 0) if (a->imp[a->scan_idx] > 0)
{ {
a->time = 0; a->time = 0;
if (a->adv_slew_count > 0) if (a->adv_slew_count > 0)
a->state = 1; a->state = 1;
else if (a->adv_count > 0) else if (a->adv_count > 0)
a->state = 2; a->state = 2;
else else
a->state = 3; a->state = 3;
tidx = a->scan_idx; tidx = a->scan_idx;
a->blank_count = 0; a->blank_count = 0;
do do
{ {
len = 0; len = 0;
hcount = 0; hcount = 0;
while ((a->imp[tidx] > 0 || hcount > 0) && a->blank_count < a->max_imp_seq) while ((a->imp[tidx] > 0 || hcount > 0) && a->blank_count < a->max_imp_seq)
{ {
a->blank_count++; a->blank_count++;
if (hcount > 0) hcount--; if (hcount > 0)
if (a->imp[tidx] > 0) hcount = a->hang_count + a->hang_slew_count; hcount--;
if (++tidx >= a->dline_size) tidx -= a->dline_size; if (a->imp[tidx] > 0)
hcount = a->hang_count + a->hang_slew_count;
if (++tidx >= a->dline_size)
tidx -= a->dline_size;
} }
j = 1; j = 1;
len = 0; len = 0;
lidx = tidx; lidx = tidx;
while (j <= a->adv_slew_count + a->adv_count && len == 0) while (j <= a->adv_slew_count + a->adv_count && len == 0)
{ {
if (a->imp[lidx] == 1) if (a->imp[lidx] == 1)
@ -231,16 +252,22 @@ void NOB::xnob (NOB *a)
len = j; len = j;
tidx = lidx; tidx = lidx;
} }
if (++lidx >= a->dline_size) lidx -= a->dline_size;
if (++lidx >= a->dline_size)
lidx -= a->dline_size;
j++; j++;
} }
if((a->blank_count += len) > a->max_imp_seq) if((a->blank_count += len) > a->max_imp_seq)
{ {
a->blank_count = a->max_imp_seq; a->blank_count = a->max_imp_seq;
a->overflow = 1; a->overflow = 1;
break; break;
} }
} while (len != 0); }
while (len != 0);
if (a->overflow == 0) if (a->overflow == 0)
{ {
a->blank_count -= a->hang_slew_count; a->blank_count -= a->hang_slew_count;
@ -252,37 +279,53 @@ void NOB::xnob (NOB *a)
bfboutidx = a->bfb_in_idx; bfboutidx = a->bfb_in_idx;
a->I1 = 0.0; a->I1 = 0.0;
a->Q1 = 0.0; a->Q1 = 0.0;
for (k = 0; k < a->filterlen; k++) for (k = 0; k < a->filterlen; k++)
{ {
a->I1 += a->fcoefs[k] * a->bfbuff[2 * bfboutidx + 0]; a->I1 += a->fcoefs[k] * a->bfbuff[2 * bfboutidx + 0];
a->Q1 += a->fcoefs[k] * a->bfbuff[2 * bfboutidx + 1]; a->Q1 += a->fcoefs[k] * a->bfbuff[2 * bfboutidx + 1];
if (--bfboutidx < 0) bfboutidx += a->filterlen;
if (--bfboutidx < 0)
bfboutidx += a->filterlen;
} }
} }
if (a->mode == 2 || a->mode == 3 || a->mode == 4) if (a->mode == 2 || a->mode == 3 || a->mode == 4)
{ {
if ((ff_idx = a->scan_idx + a->blank_count) >= a->dline_size) ff_idx -= a->dline_size; if ((ff_idx = a->scan_idx + a->blank_count) >= a->dline_size)
ff_idx -= a->dline_size;
ffcount = 0; ffcount = 0;
while (ffcount < a->filterlen) while (ffcount < a->filterlen)
{ {
if (a->imp[ff_idx] == 0) if (a->imp[ff_idx] == 0)
{ {
if (++a->ffb_in_idx == a->filterlen) a->ffb_in_idx -= a->filterlen; if (++a->ffb_in_idx == a->filterlen)
a->ffb_in_idx -= a->filterlen;
a->ffbuff[2 * a->ffb_in_idx + 0] = a->dline[2 * ff_idx + 0]; a->ffbuff[2 * a->ffb_in_idx + 0] = a->dline[2 * ff_idx + 0];
a->ffbuff[2 * a->ffb_in_idx + 1] = a->dline[2 * ff_idx + 1]; a->ffbuff[2 * a->ffb_in_idx + 1] = a->dline[2 * ff_idx + 1];
++ffcount; ++ffcount;
} }
if (++ff_idx >= a->dline_size) ff_idx -= a->dline_size;
if (++ff_idx >= a->dline_size)
ff_idx -= a->dline_size;
} }
if ((ffboutidx = a->ffb_in_idx + 1) >= a->filterlen) ffboutidx -= a->filterlen;
if ((ffboutidx = a->ffb_in_idx + 1) >= a->filterlen)
ffboutidx -= a->filterlen;
a->I2 = 0.0; a->I2 = 0.0;
a->Q2 = 0.0; a->Q2 = 0.0;
for (k = 0; k < a->filterlen; k++) for (k = 0; k < a->filterlen; k++)
{ {
a->I2 += a->fcoefs[k] * a->ffbuff[2 * ffboutidx + 0]; a->I2 += a->fcoefs[k] * a->ffbuff[2 * ffboutidx + 0];
a->Q2 += a->fcoefs[k] * a->ffbuff[2 * ffboutidx + 1]; a->Q2 += a->fcoefs[k] * a->ffbuff[2 * ffboutidx + 1];
if (++ffboutidx >= a->filterlen) ffboutidx -= a->filterlen;
if (++ffboutidx >= a->filterlen)
ffboutidx -= a->filterlen;
} }
} }
@ -323,7 +366,9 @@ void NOB::xnob (NOB *a)
else else
{ {
if (a->adv_slew_count > 0) if (a->adv_slew_count > 0)
{
a->state = 5; a->state = 5;
}
else else
{ {
a->state = 6; a->state = 6;
@ -332,23 +377,29 @@ void NOB::xnob (NOB *a)
} }
} }
} }
break; break;
} }
case 1: // slew output in advance of blanking period case 1: // slew output in advance of blanking period
{ {
scale = 0.5 + a->awave[a->time]; scale = 0.5 + a->awave[a->time];
a->out[2 * i + 0] = a->Ilast * scale + (1.0 - scale) * a->I; a->out[2 * i + 0] = a->Ilast * scale + (1.0 - scale) * a->I;
a->out[2 * i + 1] = a->Qlast * scale + (1.0 - scale) * a->Q; a->out[2 * i + 1] = a->Qlast * scale + (1.0 - scale) * a->Q;
if (++a->time == a->adv_slew_count) if (++a->time == a->adv_slew_count)
{ {
a->time = 0; a->time = 0;
if (a->adv_count > 0) if (a->adv_count > 0)
a->state = 2; a->state = 2;
else else
a->state = 3; a->state = 3;
} }
break; break;
} }
case 2: // initial advance period case 2: // initial advance period
{ {
a->out[2 * i + 0] = a->I; a->out[2 * i + 0] = a->I;
@ -361,8 +412,10 @@ void NOB::xnob (NOB *a)
a->state = 3; a->state = 3;
a->time = 0; a->time = 0;
} }
break; break;
} }
case 3: // impulse & hang period case 3: // impulse & hang period
{ {
a->out[2 * i + 0] = a->I; a->out[2 * i + 0] = a->I;
@ -378,52 +431,69 @@ void NOB::xnob (NOB *a)
a->time = 0; a->time = 0;
} }
else else
{
a->state = 0; a->state = 0;
} }
}
break; break;
} }
case 4: // slew output after blanking period case 4: // slew output after blanking period
{ {
scale = 0.5 - a->hwave[a->time]; scale = 0.5 - a->hwave[a->time];
a->out[2 * i + 0] = a->Inext * scale + (1.0 - scale) * a->I; a->out[2 * i + 0] = a->Inext * scale + (1.0 - scale) * a->I;
a->out[2 * i + 1] = a->Qnext * scale + (1.0 - scale) * a->Q; a->out[2 * i + 1] = a->Qnext * scale + (1.0 - scale) * a->Q;
if (++a->time == a->hang_slew_count) if (++a->time == a->hang_slew_count)
a->state = 0; a->state = 0;
break; break;
} }
case 5: case 5:
{ {
scale = 0.5 + a->awave[a->time]; scale = 0.5 + a->awave[a->time];
a->out[2 * i + 0] = a->Ilast * scale; a->out[2 * i + 0] = a->Ilast * scale;
a->out[2 * i + 1] = a->Qlast * scale; a->out[2 * i + 1] = a->Qlast * scale;
if (++a->time == a->adv_slew_count) if (++a->time == a->adv_slew_count)
{ {
a->state = 6; a->state = 6;
a->time = 0; a->time = 0;
a->blank_count += a->adv_count + a->filterlen; a->blank_count += a->adv_count + a->filterlen;
} }
break; break;
} }
case 6: case 6:
{ {
a->out[2 * i + 0] = 0.0; a->out[2 * i + 0] = 0.0;
a->out[2 * i + 1] = 0.0; a->out[2 * i + 1] = 0.0;
if (++a->time == a->blank_count) if (++a->time == a->blank_count)
a->state = 7; a->state = 7;
break; break;
} }
case 7: case 7:
{ {
a->out[2 * i + 0] = 0.0; a->out[2 * i + 0] = 0.0;
a->out[2 * i + 1] = 0.0; a->out[2 * i + 1] = 0.0;
staydown = 0; staydown = 0;
a->time = 0; a->time = 0;
if ((tidx = a->scan_idx + a->hang_slew_count + a->hang_count) >= a->dline_size) tidx -= a->dline_size;
if ((tidx = a->scan_idx + a->hang_slew_count + a->hang_count) >= a->dline_size)
tidx -= a->dline_size;
while (a->time++ <= a->adv_count + a->adv_slew_count + a->hang_slew_count + a->hang_count) // CHECK EXACT COUNTS!!!!!!!!!!!!!!!!!!!!!!! while (a->time++ <= a->adv_count + a->adv_slew_count + a->hang_slew_count + a->hang_count) // CHECK EXACT COUNTS!!!!!!!!!!!!!!!!!!!!!!!
{ {
if (a->imp[tidx] == 1) staydown = 1; if (a->imp[tidx] == 1) staydown = 1;
if (--tidx < 0) tidx += a->dline_size; if (--tidx < 0) tidx += a->dline_size;
} }
if (staydown == 0) if (staydown == 0)
{ {
if (a->hang_count > 0) if (a->hang_count > 0)
@ -435,8 +505,13 @@ void NOB::xnob (NOB *a)
{ {
a->state = 9; a->state = 9;
a->time = 0; a->time = 0;
if ((tidx = a->scan_idx + a->hang_slew_count + a->hang_count - a->adv_count - a->adv_slew_count) >= a->dline_size) tidx -= a->dline_size;
if (tidx < 0) tidx += a->dline_size; if ((tidx = a->scan_idx + a->hang_slew_count + a->hang_count - a->adv_count - a->adv_slew_count) >= a->dline_size)
tidx -= a->dline_size;
if (tidx < 0)
tidx += a->dline_size;
a->Inext = a->dline[2 * tidx + 0]; a->Inext = a->dline[2 * tidx + 0];
a->Qnext = a->dline[2 * tidx + 1]; a->Qnext = a->dline[2 * tidx + 1];
} }
@ -446,20 +521,28 @@ void NOB::xnob (NOB *a)
a->overflow = 0; a->overflow = 0;
} }
} }
break; break;
} }
case 8: case 8:
{ {
a->out[2 * i + 0] = 0.0; a->out[2 * i + 0] = 0.0;
a->out[2 * i + 1] = 0.0; a->out[2 * i + 1] = 0.0;
if (++a->time == a->hang_count) if (++a->time == a->hang_count)
{ {
if (a->hang_slew_count > 0) if (a->hang_slew_count > 0)
{ {
a->state = 9; a->state = 9;
a->time = 0; a->time = 0;
if ((tidx = a->scan_idx + a->hang_slew_count - a->adv_count - a->adv_slew_count) >= a->dline_size) tidx -= a->dline_size;
if (tidx < 0) tidx += a->dline_size; if ((tidx = a->scan_idx + a->hang_slew_count - a->adv_count - a->adv_slew_count) >= a->dline_size)
tidx -= a->dline_size;
if (tidx < 0)
tidx += a->dline_size;
a->Inext = a->dline[2 * tidx + 0]; a->Inext = a->dline[2 * tidx + 0];
a->Qnext = a->dline[2 * tidx + 1]; a->Qnext = a->dline[2 * tidx + 1];
} }
@ -469,8 +552,10 @@ void NOB::xnob (NOB *a)
a->overflow = 0; a->overflow = 0;
} }
} }
break; break;
} }
case 9: case 9:
{ {
scale = 0.5 - a->hwave[a->time]; scale = 0.5 - a->hwave[a->time];
@ -482,17 +567,26 @@ void NOB::xnob (NOB *a)
a->state = 0; a->state = 0;
a->overflow = 0; a->overflow = 0;
} }
break; break;
} }
} }
if (++a->in_idx == a->dline_size) a->in_idx = 0;
if (++a->scan_idx == a->dline_size) a->scan_idx = 0; if (++a->in_idx == a->dline_size)
if (++a->out_idx == a->dline_size) a->out_idx = 0; a->in_idx = 0;
if (++a->scan_idx == a->dline_size)
a->scan_idx = 0;
if (++a->out_idx == a->dline_size)
a->out_idx = 0;
} }
} }
else if (a->in != a->out) else if (a->in != a->out)
{
std::copy(a->in, a->in + a->buffsize * 2, a->out); std::copy(a->in, a->in + a->buffsize * 2, a->out);
} }
}
void NOB::setBuffers_nob (NOB *a, float* in, float* out) void NOB::setBuffers_nob (NOB *a, float* in, float* out)
{ {

View File

@ -38,14 +38,14 @@ void SHIFT::calc_shift (SHIFT *a)
a->sin_delta = sin (a->delta); a->sin_delta = sin (a->delta);
} }
SHIFT* SHIFT::create_shift (int run, int size, float* in, float* out, int rate, float fshift) SHIFT* SHIFT::create_shift (int run, int size, float* in, float* out, int rate, double fshift)
{ {
SHIFT *a = new SHIFT; SHIFT *a = new SHIFT;
a->run = run; a->run = run;
a->size = size; a->size = size;
a->in = in; a->in = in;
a->out = out; a->out = out;
a->rate = (float)rate; a->rate = (double) rate;
a->shift = fshift; a->shift = fshift;
a->phase = 0.0; a->phase = 0.0;
calc_shift (a); calc_shift (a);
@ -67,9 +67,10 @@ void SHIFT::xshift (SHIFT *a)
if (a->run) if (a->run)
{ {
int i; int i;
float I1, Q1, t1, t2; double I1, Q1, t1, t2;
float cos_phase = cos (a->phase); double cos_phase = cos (a->phase);
float sin_phase = sin (a->phase); double sin_phase = sin (a->phase);
for (i = 0; i < a->size; i++) for (i = 0; i < a->size; i++)
{ {
I1 = a->in[2 * i + 0]; I1 = a->in[2 * i + 0];
@ -81,13 +82,19 @@ void SHIFT::xshift (SHIFT *a)
cos_phase = t1 * a->cos_delta - t2 * a->sin_delta; cos_phase = t1 * a->cos_delta - t2 * a->sin_delta;
sin_phase = t1 * a->sin_delta + t2 * a->cos_delta; sin_phase = t1 * a->sin_delta + t2 * a->cos_delta;
a->phase += a->delta; a->phase += a->delta;
if (a->phase >= TWOPI) a->phase -= TWOPI;
if (a->phase < 0.0 ) a->phase += TWOPI; if (a->phase >= TWOPI)
a->phase -= TWOPI;
if (a->phase < 0.0 )
a->phase += TWOPI;
} }
} }
else if (a->in != a->out) else if (a->in != a->out)
{
std::copy( a->in, a->in + a->size * 2, a->out); std::copy( a->in, a->in + a->size * 2, a->out);
} }
}
void SHIFT::setBuffers_shift(SHIFT *a, float* in, float* out) void SHIFT::setBuffers_shift(SHIFT *a, float* in, float* out)
{ {
@ -119,7 +126,7 @@ void SHIFT::SetShiftRun (RXA& rxa, int run)
rxa.shift.p->run = run; rxa.shift.p->run = run;
} }
void SHIFT::SetShiftFreq (RXA& rxa, float fshift) void SHIFT::SetShiftFreq (RXA& rxa, double fshift)
{ {
rxa.shift.p->shift = fshift; rxa.shift.p->shift = fshift;
calc_shift (rxa.shift.p); calc_shift (rxa.shift.p);

View File

@ -41,14 +41,14 @@ public:
int size; int size;
float* in; float* in;
float* out; float* out;
float rate; double rate;
float shift; double shift;
float phase; double phase;
float delta; double delta;
float cos_delta; double cos_delta;
float sin_delta; double sin_delta;
static SHIFT* create_shift (int run, int size, float* in, float* out, int rate, float fshift); static SHIFT* create_shift (int run, int size, float* in, float* out, int rate, double fshift);
static void destroy_shift (SHIFT *a); static void destroy_shift (SHIFT *a);
static void flush_shift (SHIFT *a); static void flush_shift (SHIFT *a);
static void xshift (SHIFT *a); static void xshift (SHIFT *a);
@ -57,7 +57,7 @@ public:
static void setSize_shift (SHIFT *a, int size); static void setSize_shift (SHIFT *a, int size);
// RXA Properties // RXA Properties
static void SetShiftRun (RXA& rxa, int run); static void SetShiftRun (RXA& rxa, int run);
static void SetShiftFreq (RXA& rxa, float fshift); static void SetShiftFreq (RXA& rxa, double fshift);
private: private:
static void calc_shift (SHIFT *a); static void calc_shift (SHIFT *a);