Skip to content

Commit 05033c2

Browse files
plugins/dac_data_manager.c: dynamically convert data for enabled channels.
Instead of assuming a connected device will only have a maximum of 8 DMA channels, add a mechanism to dynamically convert data for all enabled channels. Signed-off-by: AlexandraTrifan <[email protected]>
1 parent 32e13fa commit 05033c2

File tree

1 file changed

+17
-35
lines changed

1 file changed

+17
-35
lines changed

Diff for: plugins/dac_data_manager.c

+17-35
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,10 @@ static int analyse_wavefile(struct dac_data_manager *manager,
456456

457457
*count = size * tx_channels * 2;
458458

459-
unsigned long long *sample = *((unsigned long long **) buf);
460-
unsigned int *sample_32 = *((unsigned int **) buf);
461459
unsigned short *sample_16 = *((unsigned short **) buf);
460+
struct _complex_ref *tx_data = calloc(tx_channels, sizeof(struct _complex_ref));
462461

463-
struct _complex_ref tx_data[4] = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}};
464-
mat_complex_split_t *complex_data[4];
462+
mat_complex_split_t *complex_data[64];
465463

466464
if (complex_format) {
467465
for (i = 0; i <= (unsigned int) rep; i++) {
@@ -479,44 +477,28 @@ static int analyse_wavefile(struct dac_data_manager *manager,
479477
}
480478
replicate_tx_data_channels(tx_data, tx_channels);
481479

482-
switch (tx_channels) {
483-
case 1:
484-
for (i = 0 ; i < size; i++) {
485-
sample_16[i] = convert(scale, tx_data[0].re[i], offset);
486-
}
487-
break;
488-
case 2:
489-
for (i = 0 ; i < size; i++) {
490-
sample_32[i] = ((unsigned int) convert(scale, tx_data[0].im[i], offset) << 16) |
491-
((unsigned int) convert(scale, tx_data[0].re[i], offset) << 0);
492-
}
493-
break;
494-
case 4:
495-
for (i = 0 ; i < size; i++) {
496-
sample[i] = ((unsigned long long) convert(scale, tx_data[1].im[i], offset) << 48) |
497-
((unsigned long long) convert(scale, tx_data[1].re[i], offset) << 32) |
498-
((unsigned long long) convert(scale, tx_data[0].im[i], offset) << 16) |
499-
((unsigned long long) convert(scale, tx_data[0].re[i], offset) << 0);
500-
}
501-
break;
502-
case 8:
503-
for (i = 0, j = 0; i < size; i++) {
504-
sample[j++] = ((unsigned long long) convert(scale, tx_data[3].im[i], offset) << 48) |
505-
((unsigned long long) convert(scale, tx_data[3].re[i], offset) << 32) |
506-
((unsigned long long) convert(scale, tx_data[2].im[i], offset) << 16) |
507-
((unsigned long long) convert(scale, tx_data[2].re[i], offset) << 0);
508-
sample[j++] = ((unsigned long long) convert(scale, tx_data[1].im[i], offset) << 48) |
509-
((unsigned long long) convert(scale, tx_data[1].re[i], offset) << 32) |
510-
((unsigned long long) convert(scale, tx_data[0].im[i], offset) << 16) |
511-
((unsigned long long) convert(scale, tx_data[0].re[i], offset) << 0);
480+
unsigned int ch = 0;
481+
unsigned int sample_i = 0;
482+
unsigned int tx_data_end = (tx_channels % 2 == 0) ? (tx_channels / 2) : tx_channels;
483+
484+
for (i = 0 ; i < size; i++) {
485+
for (ch = 0; ch < tx_data_end; ch++) {
486+
if (tx_channels % 2 == 0) {
487+
sample_16[sample_i++] = ((unsigned int) convert(scale, tx_data[ch].re[i], offset));
488+
sample_16[sample_i++] = ((unsigned int) convert(scale, tx_data[ch].im[i], offset));
489+
} else {
490+
sample_16[sample_i++] = ((unsigned int) convert(scale, tx_data[ch].re[i], offset));
491+
}
512492
}
513-
break;
514493
}
515494

516495
for (j = 0; j <= (unsigned int) rep; j++) {
517496
Mat_VarFree(matvars[j]);
518497
}
498+
free(tx_data);
499+
tx_data = NULL;
519500
free(matvars);
501+
520502
Mat_Close(matfp);
521503
return ret;
522504
}

0 commit comments

Comments
 (0)