# HG changeset patch # User Daniel O'Connor # Date 1740631772 -37800 # Node ID babdb537635631986ab5f144734a393f16207993 # Parent 600a394629e600085bd23bcb91f50660be8657e6 Fix interpolator setup. - Don't overflow the shape table at the end of pulse up - Don't generate bogus offsets diff -r 600a394629e6 -r babdb5376356 modulator.c --- a/modulator.c Thu Feb 27 13:58:37 2025 +1030 +++ b/modulator.c Thu Feb 27 15:19:32 2025 +1030 @@ -188,8 +188,10 @@ nsamples = shapesamples * 2 * ncode + codegap * (ncode - 1) + slew1 + slew2 + 1; } - // Number of steps per samples in the pulse shape - stepsize = qdiv(qint(shapelen), qint(shapesamples)); + // How far to advance the shape pointer for each sample point + // Needs to be 1 less than the shape length otherwise we overflow + // at the end of the pulse up. + stepsize = qdiv(qint(shapelen - 1), qint(shapesamples)); qsprint(stepsize, tmps, sizeof(tmps)); printf("shapelen = %d shapesamples = %lu nsamples = %lu stepsize = %s\n", shapelen, shapesamples, nsamples, tmps); @@ -213,7 +215,7 @@ // Mask start is 0 because we use 8 bit samples cfg = interp_default_config(); interp_config_set_shift(&cfg, QBITS); - interp_config_set_mask(&cfg, 0, 32 - QBITS); + interp_config_set_mask(&cfg, 0, 32 - QBITS - 1); interp_config_set_blend(&cfg, true); interp_set_config(interp0, 0, &cfg); @@ -287,6 +289,7 @@ for (uint16_t i = 0; i < shapesamples; i++) { ctrl[idx] = ctrltmp; if (c == 0) { + // First code bit // Get sample pair uint8_t *sample_pair = (uint8_t *) interp0->peek[2]; // Ask lane 1 for a LERP, using the lane 0 accumulator @@ -304,6 +307,7 @@ } if (c == 0) bit1stopup = idx - 1; + // Pulse down // Since the pulse is symmetrical just copy the up slope in reverse // XXX: if we had asymmetrical predistortion this wouldn't be true