QVector<double> upsconv(const QVector<double>& x, const QVector<double>& g, int lx) { // Dyadic upsampling int p = 0; int rem2 = p - ((p / 2) * 2); int addLEN = 2 * rem2 - 1; int lux = 2 * x.size() + addLEN; QVector<double> ux(lux, 0.0); QVector<double>::const_iterator iter = x.begin(); for(int index = 0 + rem2; index < ux.size(); index += 2) ux[index] = *iter++; // Convolution with recompose filter QVector<double> y = conv1(ux, g, true); // Crop boundries int ly = y.size(); double d = double(ly - lx) / 2.0; int first = int(floor(d)); int last = ly - int(ceil(d)); QVector<double> z(last - first); qCopy(y.begin() + first, y.begin() + last, z.begin()); return z; }
static sample_t diff_resampled(const SRCParams ¶ms, sample_t *buf1, sample_t *buf2, size_t size) { ///////////////////////////////////////////////////////////////////////////// // After resample only q*nyquist of the bandwidth is preserved. Therefore, // to compare output of the resampler with the original signal we must feed // the resampler with the bandlimited signal. Bandlimiting filter has a // transition band and we must guarantee: // passband + transition_band <= q*nyquist. // // It looks reasonable to make the transition band of the bandlimiting filter // to be equal to the transition band of the resampler. In this case we have: // passband + (1-q)*nyquist <= q*nyquist // passband <= (2q - 1)*nyquist // // In normalized form nyquist = 0.5, so we have following parameters of the // bandlimiting filter: passband = q-0.5, transition band = 0.5*(1-q) ParamFIR low_pass(ParamFIR::low_pass, params.q-0.5, 0, 0.5*(1-params.q), params.a + 10, true); const FIRInstance *fir = low_pass.make(params.fs); BOOST_REQUIRE(fir != 0); int trans_len = fir->length * 2; delete fir; Speakers spk(FORMAT_LINEAR, MODE_MONO, params.fs); samples_t s1, s2; s1.zero(); s1[0] = buf1; s2.zero(); s2[0] = buf2; ChunkSource src1(spk, Chunk(s1, size)); ChunkSource src2(spk, Chunk(s2, size)); Convolver conv1(&low_pass); Convolver conv2(&low_pass); SliceFilter slice1(trans_len, size - trans_len); SliceFilter slice2(trans_len, size - trans_len); FilterChain chain1(&conv1, &slice1); FilterChain chain2(&conv2, &slice2); return calc_diff(&src1, &chain1, &src2, &chain2); }
gaint gagchk (struct gagrid *pgr1, struct gagrid *pgr2, gaint dim) { gadouble gmin1,gmax1,gmin2,gmax2,fuz1,fuz2,fuzz; gadouble (*conv1) (gadouble *, gadouble); gadouble (*conv2) (gadouble *, gadouble); gadouble *vals1, *vals2; gaint i1,i2,i,siz1,siz2; struct dt dtim1,dtim2; if (dim<0) return(0); if (dim==pgr1->idim) { conv1 = pgr1->igrab; vals1 = pgr1->ivals; i1 = pgr1->ilinr; siz1 = pgr1->isiz; } else if (dim==pgr1->jdim) { conv1 = pgr1->jgrab; vals1 = pgr1->jvals; i1 = pgr1->jlinr; siz1 = pgr1->jsiz; } else return (1); if (dim==pgr2->idim) { conv2 = pgr2->igrab; vals2 = pgr2->ivals; i2 = pgr2->ilinr; siz2 = pgr2->isiz; } else if (dim==pgr2->jdim) { conv2 = pgr2->jgrab; vals2 = pgr2->jvals; i2 = pgr2->jlinr; siz2 = pgr2->jsiz; } else return (1); if (siz1 != siz2) return(1); gmin1 = pgr1->dimmin[dim]; gmax1 = pgr1->dimmax[dim]; gmin2 = pgr2->dimmin[dim]; gmax2 = pgr2->dimmax[dim]; if (dim==3) { /* Dimension is time. */ gr2t (vals1, gmin1, &dtim1); gr2t (vals2, gmin2, &dtim2); if (dtim1.yr != dtim2.yr) return (1); if (dtim1.mo != dtim2.mo) return (1); if (dtim1.dy != dtim2.dy) return (1); if (dtim1.hr != dtim2.hr) return (1); if (dtim1.mn != dtim2.mn) return (1); gr2t (vals1, gmax1, &dtim1); gr2t (vals2, gmax2, &dtim2); if (dtim1.yr != dtim2.yr) return (1); if (dtim1.mo != dtim2.mo) return (1); if (dtim1.dy != dtim2.dy) return (1); if (dtim1.hr != dtim2.hr) return (1); if (dtim1.mn != dtim2.mn) return (1); return (0); } /* Check endpoints. If unequal, then automatic no match. */ fuz1=fabs(conv1(vals1,gmax1)-conv1(vals1,gmin1))*FUZZ_SCALE; fuz2=fabs(conv2(vals2,gmax2)-conv2(vals2,gmin2))*FUZZ_SCALE; fuzz=(fuz1+fuz2)*0.5; if ( fabs((conv1(vals1,gmin1)) - (conv2(vals2,gmin2))) > fuzz ) return (1); if ( fabs((conv1(vals1,gmax1)) - (conv2(vals2,gmax2))) > fuzz ) return (1); if (i1!=i2) return (1); if (i1) return (0); /* If linear then matches */ /* Nonlinear, but endpoints match. Check every grid point for a match. If any non-matches, then not a match. */ for (i=0; i<siz1; i++) { if (fabs((conv1(vals1,gmin1+(gadouble)i)) - (conv2(vals2,gmin2+(gadouble)i))) > fuzz ) { return (1); } } return (0); }