Skip to content

Commit

Permalink
plugins/dac_data_manager.c: dynamically convert data for enabled chan…
Browse files Browse the repository at this point in the history
…nels.

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]>
  • Loading branch information
AlexandraTrifan authored and dNechita committed Feb 13, 2025
1 parent 32e13fa commit 7c1d5d8
Showing 1 changed file with 17 additions and 35 deletions.
52 changes: 17 additions & 35 deletions plugins/dac_data_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,10 @@ static int analyse_wavefile(struct dac_data_manager *manager,

*count = size * tx_channels * 2;

unsigned long long *sample = *((unsigned long long **) buf);
unsigned int *sample_32 = *((unsigned int **) buf);
unsigned short *sample_16 = *((unsigned short **) buf);
struct _complex_ref *tx_data = calloc(tx_channels, sizeof(struct _complex_ref));

struct _complex_ref tx_data[4] = {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}};
mat_complex_split_t *complex_data[4];
mat_complex_split_t *complex_data[64];

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

switch (tx_channels) {
case 1:
for (i = 0 ; i < size; i++) {
sample_16[i] = convert(scale, tx_data[0].re[i], offset);
}
break;
case 2:
for (i = 0 ; i < size; i++) {
sample_32[i] = ((unsigned int) convert(scale, tx_data[0].im[i], offset) << 16) |
((unsigned int) convert(scale, tx_data[0].re[i], offset) << 0);
}
break;
case 4:
for (i = 0 ; i < size; i++) {
sample[i] = ((unsigned long long) convert(scale, tx_data[1].im[i], offset) << 48) |
((unsigned long long) convert(scale, tx_data[1].re[i], offset) << 32) |
((unsigned long long) convert(scale, tx_data[0].im[i], offset) << 16) |
((unsigned long long) convert(scale, tx_data[0].re[i], offset) << 0);
}
break;
case 8:
for (i = 0, j = 0; i < size; i++) {
sample[j++] = ((unsigned long long) convert(scale, tx_data[3].im[i], offset) << 48) |
((unsigned long long) convert(scale, tx_data[3].re[i], offset) << 32) |
((unsigned long long) convert(scale, tx_data[2].im[i], offset) << 16) |
((unsigned long long) convert(scale, tx_data[2].re[i], offset) << 0);
sample[j++] = ((unsigned long long) convert(scale, tx_data[1].im[i], offset) << 48) |
((unsigned long long) convert(scale, tx_data[1].re[i], offset) << 32) |
((unsigned long long) convert(scale, tx_data[0].im[i], offset) << 16) |
((unsigned long long) convert(scale, tx_data[0].re[i], offset) << 0);
unsigned int ch = 0;
unsigned int sample_i = 0;
unsigned int tx_data_end = (tx_channels % 2 == 0) ? (tx_channels / 2) : tx_channels;

for (i = 0 ; i < size; i++) {
for (ch = 0; ch < tx_data_end; ch++) {
if (tx_channels % 2 == 0) {
sample_16[sample_i++] = ((unsigned int) convert(scale, tx_data[ch].re[i], offset));
sample_16[sample_i++] = ((unsigned int) convert(scale, tx_data[ch].im[i], offset));
} else {
sample_16[sample_i++] = ((unsigned int) convert(scale, tx_data[ch].re[i], offset));
}
}
break;
}

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

Mat_Close(matfp);
return ret;
}
Expand Down

0 comments on commit 7c1d5d8

Please sign in to comment.