Skip to content

Commit e5d16df

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 e5d16df

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

Diff for: plugins/dac_data_manager.c

+20-35
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,19 @@ 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);
462460

463-
struct _complex_ref tx_data[4] = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}};
464-
mat_complex_split_t *complex_data[4];
461+
462+
unsigned int tx_data_count = (tx_channels == 1) ? tx_channels : (tx_channels / 2);
463+
struct _complex_ref *tx_data = malloc(tx_data_count * sizeof(struct _complex_ref));
464+
465+
unsigned int tx_i = 0;
466+
for (tx_i = 0; tx_i < tx_data_count; tx_i++) {
467+
tx_data[tx_i].re = NULL;
468+
tx_data[tx_i].im = NULL;
469+
}
470+
471+
mat_complex_split_t *complex_data[64];
465472

466473
if (complex_format) {
467474
for (i = 0; i <= (unsigned int) rep; i++) {
@@ -479,40 +486,18 @@ static int analyse_wavefile(struct dac_data_manager *manager,
479486
}
480487
replicate_tx_data_channels(tx_data, tx_channels);
481488

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);
489+
int ch = 0;
490+
for (i = 0 ; i < size; i++) {
491+
for (ch = 0; ch < tx_channels; ch++) {
492+
if (ch % 2 == 0) {
493+
sample_16[i * tx_channels + ch] = ((unsigned int) convert(scale, tx_data[ch / 2].re[i], offset));
494+
} else {
495+
sample_16[i * tx_channels + ch] = ((unsigned int) convert(scale, tx_data[ch / 2].im[i], offset));
496+
}
512497
}
513-
break;
514498
}
515499

500+
free(tx_data);
516501
for (j = 0; j <= (unsigned int) rep; j++) {
517502
Mat_VarFree(matvars[j]);
518503
}

0 commit comments

Comments
 (0)