DELAY create_delay (int run, int size, float* in, float* out, int rate, float tdelta, float tdelay) { DELAY a = (DELAY) malloc0 (sizeof (delay)); a->run = run; a->size = size; a->in = in; a->out = out; a->rate = rate; a->tdelta = tdelta; a->tdelay = tdelay; a->L = (int)(0.5 + 1.0 / (a->tdelta * (float)a->rate)); a->ft = 0.45 / (float)a->L; a->ncoef = (int)(60.0 / a->ft); a->ncoef = (a->ncoef / a->L + 1) * a->L; a->cpp = a->ncoef / a->L; a->phnum = (int)(0.5 + a->tdelay / a->tdelta); a->snum = a->phnum / a->L; a->phnum %= a->L; a->idx_in = 0; a->adelta = 1.0 / (a->rate * a->L); a->adelay = a->adelta * (a->snum * a->L + a->phnum); a->h = fir_bandpass (a->ncoef,-a->ft, +a->ft, 1.0, 1, 0, (float)a->L); a->rsize = a->cpp + (WSDEL - 1); a->ring = (float *) malloc0 (a->rsize * sizeof (complex)); InitializeCriticalSectionAndSpinCount ( &a->cs_update, 2500 ); return a; }
RESAMPLEF create_resampleF ( int run, int size, float* in, float* out, int in_rate, int out_rate) { RESAMPLEF a = (RESAMPLEF) malloc0 (sizeof (resampleF)); int x, y, z; int i, j, k; int min_rate; double full_rate; double fc; double fc_norm; double* impulse; a->run = run; a->size = size; a->in = in; a->out = out; x = in_rate; y = out_rate; while (y != 0) { z = y; y = x % y; x = z; } a->L = out_rate / x; a->M = in_rate / x; if (in_rate < out_rate) min_rate = in_rate; else min_rate = out_rate; fc = 0.45 * (double)min_rate; full_rate = (double)(in_rate * a->L); fc_norm = fc / full_rate; a->ncoef = (int)(60.0 / fc_norm); a->ncoef = (a->ncoef / a->L + 1) * a->L; a->cpp = a->ncoef / a->L; a->h = (double *) malloc0 (a->ncoef * sizeof (double)); impulse = fir_bandpass (a->ncoef, -fc_norm, +fc_norm, 1.0, 1, 0, (double)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 = (double *) malloc0 (a->ringsize * sizeof (double)); a->idx_in = a->ringsize - 1; a->phnum = 0; _aligned_free (impulse); return a; }
void calc_resample (RESAMPLE a) { int x, y, z; int i, j, k; int min_rate; double full_rate; double fc_norm_high, fc_norm_low; double* impulse; a->fc = a->fcin; a->ncoef = a->ncoefin; x = a->in_rate; y = a->out_rate; while (y != 0) { z = y; y = x % y; x = z; } a->L = a->out_rate / x; a->M = a->in_rate / x; if (a->in_rate < a->out_rate) min_rate = a->in_rate; else min_rate = a->out_rate; if (a->fc == 0.0) a->fc = 0.45 * (double)min_rate; full_rate = (double)(a->in_rate * a->L); fc_norm_high = a->fc / full_rate; if (a->fc_low < 0.0) fc_norm_low = - fc_norm_high; else fc_norm_low = a->fc_low / full_rate; 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 = (double *)malloc0(a->ncoef * sizeof(double)); impulse = fir_bandpass(a->ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, a->gain * (double)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 = (double *)malloc0(a->ringsize * sizeof(complex)); a->idx_in = a->ringsize - 1; a->phnum = 0; _aligned_free(impulse); }
PORT void SetTXAFMDeviation (int channel, double deviation) { double* impulse; FMMOD a; EnterCriticalSection (&ch[channel].csDSP); a = txa[channel].fmmod.p; a->deviation = deviation; // mod a->sphase = 0.0; a->sdelta = TWOPI * a->deviation / a->samplerate; // bandpass a->bp_fc = a->deviation + a->f_high; _aligned_free (a->bp_mults); impulse = fir_bandpass (a->size + 1, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); a->bp_mults = fftcv_mults (2 * a->size, impulse); _aligned_free (impulse); LeaveCriticalSection (&ch[channel].csDSP); }
void calc_fmmod (FMMOD a) { double* impulse; // ctcss gen a->tscale = 1.0 / (1.0 + a->ctcss_level); a->tphase = 0.0; a->tdelta = TWOPI * a->ctcss_freq / a->samplerate; // mod a->sphase = 0.0; a->sdelta = TWOPI * a->deviation / a->samplerate; // bandpass a->bp_fc = a->deviation + a->f_high; impulse = fir_bandpass(a->size + 1, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); a->bp_mults = fftcv_mults(2 * a->size, impulse); a->bp_infilt = (double *)malloc0(2 * a->size * sizeof(complex)); a->bp_product = (double *)malloc0(2 * a->size * sizeof(complex)); a->bp_CFor = fftw_plan_dft_1d(2 * a->size, (fftw_complex *)a->bp_infilt, (fftw_complex *)a->bp_product, FFTW_FORWARD, FFTW_PATIENT); a->bp_CRev = fftw_plan_dft_1d(2 * a->size, (fftw_complex *)a->bp_product, (fftw_complex *)a->out, FFTW_BACKWARD, FFTW_PATIENT); _aligned_free(impulse); }