Mercurial > ~darius > hgwebdir.cgi > modulator
changeset 30:92fdf2ef995d default tip
Use 32 bit rather than 16 bit ints for loop vars.
No risk of overflow and is actually faster.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 27 Feb 2025 15:24:17 +1030 |
parents | babdb5376356 |
children | |
files | modulator.c |
diffstat | 1 files changed, 7 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/modulator.c Thu Feb 27 15:19:32 2025 +1030 +++ b/modulator.c Thu Feb 27 15:24:17 2025 +1030 @@ -205,11 +205,6 @@ printf("Pulse too short (%lu < %d)\n", shapesamples, 2); return 0; } - // Or too long (will overflow for loop variable) - if (qtoi(shapesamples) > 65535) { - printf("Shape too long (%u > %d)\n", qtoi(shapesamples), 65535); - return 0; - } // Setup interp 0 lane 0 to generate index into shape table // Mask start is 0 because we use 8 bit samples @@ -247,7 +242,7 @@ memset(pulse_ctrl, 0, datalen); idx = 0; #if 0 - for (uint16_t i = 0; i < 255 * 200; i++) + for (uint32_t i = 0; i < 255 * 200; i++) data[idx++] = i / 200; printf("Dummy done\n"); @@ -270,10 +265,10 @@ #endif // Up slew - for (uint16_t i = 0; i < slew1; i++) { + for (uint32_t i = 0; i < slew1; i++) { data[idx++] = qtoi(qdiv(qmul(qint(dcofs), qint(i)), qint(slew1))); } - for (uint16_t c = 0; c < ncode; c++) { + for (uint32_t c = 0; c < ncode; c++) { if (c == 0) bit1startup = idx; @@ -286,7 +281,7 @@ interp0->accum[0] = 0; // Initial offset into shape table interp0->base[2] = (uintptr_t)shape; // Start of shape table } - for (uint16_t i = 0; i < shapesamples; i++) { + for (uint32_t i = 0; i < shapesamples; i++) { ctrl[idx] = ctrltmp; if (c == 0) { // First code bit @@ -311,7 +306,7 @@ // 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 - for (uint16_t i = 0; i < shapesamples; i++) { + for (uint32_t i = 0; i < shapesamples; i++) { // Could replace this with a separate loop to poke it into place // Similarly for TR switch when implemented if (i == 0 && c == 0) @@ -323,14 +318,14 @@ // Code gap if (c < ncode - 1) - for (uint16_t i = 0; i < codegap; i++) { + for (uint32_t i = 0; i < codegap; i++) { ctrl[idx] = ctrltmp; data[idx++] = dcofs; } } // Down slew - for (uint16_t i = 0; i < slew2 + 1; i++) { + for (uint32_t i = 0; i < slew2 + 1; i++) { data[idx++] = qtoi(qdiv(qmul(qint(dcofs), qint(slew2 - i)), qint(slew2))); }