diff --git a/wdsp/anb.cpp b/wdsp/anb.cpp index 53189228d..85cb28e84 100644 --- a/wdsp/anb.cpp +++ b/wdsp/anb.cpp @@ -39,7 +39,10 @@ void ANB::initBlanker(ANB *a) { int i; 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->adv_count = (int)(a->advtime * a->samplerate); a->count = 0; @@ -51,8 +54,10 @@ void ANB::initBlanker(ANB *a) a->power = 1.0; a->backmult = exp(-1.0 / (a->samplerate * a->backtau)); a->ombackmult = 1.0 - a->backmult; + for (i = 0; i <= a->trans_count; i++) a->wave[i] = 0.5 * cos(i * a->coef); + std::fill(a->dline, a->dline + a->dline_size * 2, 0); } @@ -81,7 +86,7 @@ ANB* ANB::create_anb ( a->advtime = advtime; a->backtau = backtau; 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 = new float[a->dline_size * 2]; initBlanker(a); @@ -107,14 +112,18 @@ void ANB::xanb (ANB *a) double scale; double mag; int i; + if (a->run) { 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->dline[2 * a->in_idx + 0] = a->in[2 * i + 0]; a->dline[2 * a->in_idx + 1] = a->in[2 * i + 1]; + if (mag > (a->avg * a->threshold)) a->count = a->trans_count + a->adv_count; @@ -123,45 +132,59 @@ void ANB::xanb (ANB *a) case 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]; + if (a->count > 0) { a->state = 1; a->dtime = 0; a->power = 1.0; } + break; + case 1: 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 + 1] = a->dline[2 * a->out_idx + 1] * scale; + if (++a->dtime > a->trans_count) { a->state = 2; a->atime = 0; } + break; + case 2: a->out[2 * i + 0] = 0.0; a->out[2 * i + 1] = 0.0; + if (++a->atime > a->adv_count) a->state = 3; + break; + case 3: if (a->count > 0) a->htime = -a->count; a->out[2 * i + 0] = 0.0; a->out[2 * i + 1] = 0.0; + if (++a->htime > a->hang_count) { a->state = 4; a->itime = 0; + } + break; + case 4: scale = 0.5 - a->wave[a->itime]; 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; + if (a->count > 0) { a->state = 1; @@ -169,16 +192,27 @@ void ANB::xanb (ANB *a) a->power = scale; } else if (++a->itime > a->trans_count) + { a->state = 0; + } + break; } - if (a->count > 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; + + if (a->count > 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) + { std::copy(a->in, a->in + a->buffsize * 2, a->out); + } } void ANB::setBuffers_anb (ANB *a, float* in, float* out) diff --git a/wdsp/anb.hpp b/wdsp/anb.hpp index 7a38069fc..74056c2ec 100644 --- a/wdsp/anb.hpp +++ b/wdsp/anb.hpp @@ -47,7 +47,7 @@ public: double advtime; // deadtime (zero output) in advance of detected noise double backtau; // time constant used in averaging the magnitude of the input signal 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 double avg; // average value of the signal magnitude int dtime; // count when decreasing the signal magnitude diff --git a/wdsp/nob.cpp b/wdsp/nob.cpp index 68860bb93..c8d18baf8 100644 --- a/wdsp/nob.cpp +++ b/wdsp/nob.cpp @@ -43,6 +43,7 @@ void NOB::init_nob (NOB *a) { int i; double coef; + a->adv_slew_count = (int)(a->advslewtime * a->samplerate); a->adv_count = (int)(a->advtime * 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->backmult = exp (-1.0 / (a->samplerate * a->backtau)); a->ombackmult = 1.0 - a->backmult; + if (a->adv_slew_count > 0) { coef = PI / (a->adv_slew_count + 1); + for (i = 0; i < a->adv_slew_count; i++) a->awave[i] = 0.5 * cos ((i + 1) * coef); } + if (a->hang_slew_count > 0) { coef = PI / a->hang_slew_count; + for (i = 0; i < a->hang_slew_count; i++) 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]; 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; + if (mag > (a->avg * a->threshold)) a->imp[a->in_idx] = 1; else 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->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 + 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->Ilast = a->dline[2 * a->out_idx + 0]; a->Qlast = a->dline[2 * a->out_idx + 1]; + if (a->imp[a->scan_idx] > 0) { a->time = 0; + if (a->adv_slew_count > 0) a->state = 1; else if (a->adv_count > 0) a->state = 2; else a->state = 3; + tidx = a->scan_idx; a->blank_count = 0; + do { len = 0; hcount = 0; + while ((a->imp[tidx] > 0 || hcount > 0) && a->blank_count < a->max_imp_seq) { a->blank_count++; - if (hcount > 0) hcount--; - if (a->imp[tidx] > 0) hcount = a->hang_count + a->hang_slew_count; - if (++tidx >= a->dline_size) tidx -= a->dline_size; + if (hcount > 0) + hcount--; + if (a->imp[tidx] > 0) + hcount = a->hang_count + a->hang_slew_count; + if (++tidx >= a->dline_size) + tidx -= a->dline_size; } + j = 1; len = 0; lidx = tidx; + while (j <= a->adv_slew_count + a->adv_count && len == 0) { if (a->imp[lidx] == 1) @@ -231,16 +252,22 @@ void NOB::xnob (NOB *a) len = j; tidx = lidx; } - if (++lidx >= a->dline_size) lidx -= a->dline_size; + + if (++lidx >= a->dline_size) + lidx -= a->dline_size; + j++; } + if((a->blank_count += len) > a->max_imp_seq) { a->blank_count = a->max_imp_seq; a->overflow = 1; break; } - } while (len != 0); + } + while (len != 0); + if (a->overflow == 0) { a->blank_count -= a->hang_slew_count; @@ -252,37 +279,53 @@ void NOB::xnob (NOB *a) bfboutidx = a->bfb_in_idx; a->I1 = 0.0; a->Q1 = 0.0; + for (k = 0; k < a->filterlen; k++) { a->I1 += a->fcoefs[k] * a->bfbuff[2 * bfboutidx + 0]; 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 ((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; + while (ffcount < a->filterlen) { 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 + 1] = a->dline[2 * ff_idx + 1]; ++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->Q2 = 0.0; + for (k = 0; k < a->filterlen; k++) { a->I2 += a->fcoefs[k] * a->ffbuff[2 * ffboutidx + 0]; 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 { if (a->adv_slew_count > 0) + { a->state = 5; + } else { a->state = 6; @@ -332,23 +377,29 @@ void NOB::xnob (NOB *a) } } } + break; } + case 1: // slew output in advance of blanking period { scale = 0.5 + a->awave[a->time]; 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; + if (++a->time == a->adv_slew_count) { a->time = 0; + if (a->adv_count > 0) a->state = 2; else a->state = 3; } + break; } + case 2: // initial advance period { a->out[2 * i + 0] = a->I; @@ -361,8 +412,10 @@ void NOB::xnob (NOB *a) a->state = 3; a->time = 0; } + break; } + case 3: // impulse & hang period { a->out[2 * i + 0] = a->I; @@ -378,52 +431,69 @@ void NOB::xnob (NOB *a) a->time = 0; } else + { a->state = 0; + } } + break; } + case 4: // slew output after blanking period { scale = 0.5 - a->hwave[a->time]; 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; + if (++a->time == a->hang_slew_count) a->state = 0; + break; } + case 5: { scale = 0.5 + a->awave[a->time]; a->out[2 * i + 0] = a->Ilast * scale; a->out[2 * i + 1] = a->Qlast * scale; + if (++a->time == a->adv_slew_count) { a->state = 6; a->time = 0; a->blank_count += a->adv_count + a->filterlen; } + break; } + case 6: { a->out[2 * i + 0] = 0.0; a->out[2 * i + 1] = 0.0; + if (++a->time == a->blank_count) a->state = 7; + break; } + case 7: { a->out[2 * i + 0] = 0.0; a->out[2 * i + 1] = 0.0; staydown = 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!!!!!!!!!!!!!!!!!!!!!!! { if (a->imp[tidx] == 1) staydown = 1; if (--tidx < 0) tidx += a->dline_size; } + if (staydown == 0) { if (a->hang_count > 0) @@ -435,8 +505,13 @@ void NOB::xnob (NOB *a) { a->state = 9; 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->Qnext = a->dline[2 * tidx + 1]; } @@ -446,20 +521,28 @@ void NOB::xnob (NOB *a) a->overflow = 0; } } + break; } + case 8: { a->out[2 * i + 0] = 0.0; a->out[2 * i + 1] = 0.0; + if (++a->time == a->hang_count) { if (a->hang_slew_count > 0) { a->state = 9; 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->Qnext = a->dline[2 * tidx + 1]; } @@ -469,8 +552,10 @@ void NOB::xnob (NOB *a) a->overflow = 0; } } + break; } + case 9: { scale = 0.5 - a->hwave[a->time]; @@ -482,16 +567,25 @@ void NOB::xnob (NOB *a) a->state = 0; a->overflow = 0; } + 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->out_idx == a->dline_size) a->out_idx = 0; + + if (++a->in_idx == a->dline_size) + 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) + { std::copy(a->in, a->in + a->buffsize * 2, a->out); + } } void NOB::setBuffers_nob (NOB *a, float* in, float* out) diff --git a/wdsp/shift.cpp b/wdsp/shift.cpp index 67f9a9f71..d952fd312 100644 --- a/wdsp/shift.cpp +++ b/wdsp/shift.cpp @@ -38,14 +38,14 @@ void SHIFT::calc_shift (SHIFT *a) 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; a->run = run; a->size = size; a->in = in; a->out = out; - a->rate = (float)rate; + a->rate = (double) rate; a->shift = fshift; a->phase = 0.0; calc_shift (a); @@ -67,9 +67,10 @@ void SHIFT::xshift (SHIFT *a) if (a->run) { int i; - float I1, Q1, t1, t2; - float cos_phase = cos (a->phase); - float sin_phase = sin (a->phase); + double I1, Q1, t1, t2; + double cos_phase = cos (a->phase); + double sin_phase = sin (a->phase); + for (i = 0; i < a->size; i++) { I1 = a->in[2 * i + 0]; @@ -81,12 +82,18 @@ void SHIFT::xshift (SHIFT *a) cos_phase = t1 * a->cos_delta - t2 * a->sin_delta; sin_phase = t1 * a->sin_delta + t2 * a->cos_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) + { std::copy( a->in, a->in + a->size * 2, a->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; } -void SHIFT::SetShiftFreq (RXA& rxa, float fshift) +void SHIFT::SetShiftFreq (RXA& rxa, double fshift) { rxa.shift.p->shift = fshift; calc_shift (rxa.shift.p); diff --git a/wdsp/shift.hpp b/wdsp/shift.hpp index b014e5547..7e8deb346 100644 --- a/wdsp/shift.hpp +++ b/wdsp/shift.hpp @@ -41,14 +41,14 @@ public: int size; float* in; float* out; - float rate; - float shift; - float phase; - float delta; - float cos_delta; - float sin_delta; + double rate; + double shift; + double phase; + double delta; + double cos_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 flush_shift (SHIFT *a); static void xshift (SHIFT *a); @@ -57,7 +57,7 @@ public: static void setSize_shift (SHIFT *a, int size); // RXA Properties static void SetShiftRun (RXA& rxa, int run); - static void SetShiftFreq (RXA& rxa, float fshift); + static void SetShiftFreq (RXA& rxa, double fshift); private: static void calc_shift (SHIFT *a);