Mercurial > ~darius > hgwebdir.cgi > modulator
comparison modulator.c @ 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 |
comparison
equal
deleted
inserted
replaced
18:f1e44afb41a3 | 19:2e14ccd1338a |
---|---|
223 memset(pulse_ctrl, 0, datalen); | 223 memset(pulse_ctrl, 0, datalen); |
224 idx = 0; | 224 idx = 0; |
225 | 225 |
226 // Up slew | 226 // Up slew |
227 for (uint16_t i = 0; i < slew1; i++) { | 227 for (uint16_t i = 0; i < slew1; i++) { |
228 ctrl[idx] |= PACTIVE; | |
228 data[idx++] = qtoi(qdiv(qmul(qint(dcofs), qint(i)), qint(slew1))); | 229 data[idx++] = qtoi(qdiv(qmul(qint(dcofs), qint(i)), qint(slew1))); |
229 ctrl[idx] |= PACTIVE; | |
230 } | 230 } |
231 for (uint16_t c = 0; c < ncode; c++) { | 231 for (uint16_t c = 0; c < ncode; c++) { |
232 if (c == 0) | 232 if (c == 0) |
233 bit1startup = idx; | 233 bit1startup = idx; |
234 | 234 |
240 if (c == 0) { | 240 if (c == 0) { |
241 interp0->accum[0] = 0; // Initial offset into shape table | 241 interp0->accum[0] = 0; // Initial offset into shape table |
242 interp0->base[2] = (uintptr_t)shape; // Start of shape table | 242 interp0->base[2] = (uintptr_t)shape; // Start of shape table |
243 } | 243 } |
244 for (uint16_t i = 0; i < shapesamples; i++) { | 244 for (uint16_t i = 0; i < shapesamples; i++) { |
245 ctrl[idx] = ctrltmp; | |
245 if (c == 0) { | 246 if (c == 0) { |
246 // Get sample pair | 247 // Get sample pair |
247 uint8_t *sample_pair = (uint8_t *) interp0->peek[2]; | 248 uint8_t *sample_pair = (uint8_t *) interp0->peek[2]; |
248 // Ask lane 1 for a LERP, using the lane 0 accumulator | 249 // Ask lane 1 for a LERP, using the lane 0 accumulator |
249 interp0->base[0] = sample_pair[0]; | 250 interp0->base[0] = sample_pair[0]; |
255 // Update interpolator for next point | 256 // Update interpolator for next point |
256 interp0->add_raw[0] = stepsize; | 257 interp0->add_raw[0] = stepsize; |
257 } else | 258 } else |
258 // Already done it before, just copy the previous instance | 259 // Already done it before, just copy the previous instance |
259 data[idx++] = data[bit1startup + i]; | 260 data[idx++] = data[bit1startup + i]; |
260 ctrl[idx] = ctrltmp; | |
261 } | 261 } |
262 if (c == 0) | 262 if (c == 0) |
263 bit1stopup = idx - 1; | 263 bit1stopup = idx - 1; |
264 // Pulse down | 264 // Pulse down |
265 // Since the pulse is symmetrical just copy the up slope in reverse | 265 // Since the pulse is symmetrical just copy the up slope in reverse |
266 // XXX: if we had asymmetrical predistortion this wouldn't be true | 266 // XXX: if we had asymmetrical predistortion this wouldn't be true |
267 for (uint16_t i = 0; i < shapesamples; i++) { | 267 for (uint16_t i = 0; i < shapesamples; i++) { |
268 data[idx++] = data[bit1stopup - i]; | |
269 // Could replace this with a separate loop to poke it into place | 268 // Could replace this with a separate loop to poke it into place |
270 // Similarly for TR switch when implemented | 269 // Similarly for TR switch when implemented |
271 if (i == 0 && c == 0) | 270 if (i == 0 && c == 0) |
272 ctrl[idx] = ctrltmp | SENSE1; | 271 ctrl[idx] = ctrltmp | SENSE1; |
273 else | 272 else |
274 ctrl[idx] = ctrltmp; | 273 ctrl[idx] = ctrltmp; |
274 data[idx++] = data[bit1stopup - i]; | |
275 } | 275 } |
276 | 276 |
277 // Code gap | 277 // Code gap |
278 if (c < ncode - 1) | 278 if (c < ncode - 1) |
279 for (uint16_t i = 0; i < codegap; i++) { | 279 for (uint16_t i = 0; i < codegap; i++) { |
280 ctrl[idx] = ctrltmp; | |
280 data[idx++] = dcofs; | 281 data[idx++] = dcofs; |
281 ctrl[idx] = ctrltmp; | |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 // Down slew | 285 // Down slew |
286 for (uint16_t i = 0; i < slew2 + 1; i++) { | 286 for (uint16_t i = 0; i < slew2 + 1; i++) { |
287 ctrl[idx] |= PACTIVE; | |
287 data[idx++] = qtoi(qdiv(qmul(qint(dcofs), qint(slew2 - i)), qint(slew2))); | 288 data[idx++] = qtoi(qdiv(qmul(qint(dcofs), qint(slew2 - i)), qint(slew2))); |
288 ctrl[idx] |= PACTIVE; | |
289 } | 289 } |
290 | 290 |
291 data[idx++] = 0; | 291 data[idx++] = 0; |
292 ctrl[idx] = 0; | 292 ctrl[idx] = 0; |
293 | 293 |