changeset 19:2e14ccd1338a

Set control data after shape data so it is lined up properly.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 25 Feb 2025 14:53:40 +1030
parents f1e44afb41a3
children 6aaa9658df1e
files modulator.c
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modulator.c	Tue Feb 25 14:36:10 2025 +1030
+++ b/modulator.c	Tue Feb 25 14:53:40 2025 +1030
@@ -225,8 +225,8 @@
 
   // Up slew
   for (uint16_t i = 0; i < slew1; i++) {
+    ctrl[idx] |= PACTIVE;
     data[idx++] = qtoi(qdiv(qmul(qint(dcofs), qint(i)), qint(slew1)));
-    ctrl[idx] |= PACTIVE;
   }
   for (uint16_t c = 0; c < ncode; c++) {
     if (c == 0)
@@ -242,6 +242,7 @@
       interp0->base[2] = (uintptr_t)shape; // Start of shape table
     }
     for (uint16_t i = 0; i < shapesamples; i++) {
+      ctrl[idx] = ctrltmp;
       if (c == 0) {
 	// Get sample pair
 	uint8_t *sample_pair = (uint8_t *) interp0->peek[2];
@@ -257,7 +258,6 @@
       } else
 	// Already done it before, just copy the previous instance
 	data[idx++] = data[bit1startup + i];
-      ctrl[idx] = ctrltmp;
     }
     if (c == 0)
       bit1stopup = idx - 1;
@@ -265,27 +265,27 @@
     // 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++) {
-      data[idx++] = data[bit1stopup - i];
       // Could replace this with a separate loop to poke it into place
       // Similarly for TR switch when implemented
       if (i == 0 && c == 0)
 	ctrl[idx] = ctrltmp | SENSE1;
       else
 	ctrl[idx] = ctrltmp;
+      data[idx++] = data[bit1stopup - i];
     }
 
     // Code gap
     if (c < ncode - 1)
       for (uint16_t i = 0; i < codegap; i++) {
+	ctrl[idx] = ctrltmp;
 	data[idx++] = dcofs;
-	ctrl[idx] = ctrltmp;
       }
   }
 
   // Down slew
   for (uint16_t i = 0; i < slew2 + 1; i++) {
+    ctrl[idx] |= PACTIVE;
     data[idx++] = qtoi(qdiv(qmul(qint(dcofs), qint(slew2 - i)), qint(slew2)));
-    ctrl[idx] |= PACTIVE;
   }
 
   data[idx++] = 0;