2021-06-13 10:17 AM
I'll try to explain everything with detail as this is one will be a hard one to explain.
Essentially what I am trying to achieve is sum both the left & right channel to produce a mono signal to be outputted via I2S as the subwoofer line.
The problem I am having right now is that after summing the samples and sending it back to the peripheral I am observing at least double the frequency compare to the input and I have no idea why. Also at lower frequencies the signal looks chopped (see pictures)
What I have done for you is:
The I2S3 DMA is setup as follow:
The I2S1 DMA is setup as follow:
Code: I2S_HALFCOMPLETE_CALLBACK()
void I2S_HALFCOMPLETE_CALLBACK() {
int * I2S3_TxBUFF = getI2S3_TxBUFF();
int INSAMPLE_I2S_MONO[1024];
for (int i = 0; i < 2048; i++) {
if ((i % 2) == 0){ // L Samples
INSAMPLE_I2S_MONO[i >> 1] = I2S1_RxBUFF[i];
} else if ((i % 2) == 1){ // R Samples
if (inputSourceMode == INPUT_INLINE) {
INSAMPLE_I2S_MONO[(i - 1) >> 1] += I2S1_RxBUFF[i];
INSAMPLE_I2S_MONO[(i - 1) >> 1] = INSAMPLE_I2S_MONO[(i - 1) >> 1] >> 1;
}
}
}
for (int i = 0; i < 2048; i++) {
if ((i % 2) == 0) { // L Samples
} else if ((i % 2) == 1) { // R Samples
}
if (i < 1024) {
I2S3_TxBUFF[i] = INSAMPLE_I2S_MONO[i];
}
}
}
CODE: I2S_TRANSFERCOMPLETE_CALLBACK()
void I2S_TRANSFERCOMPLETE_CALLBACK() {
int * I2S3_TxBUFF = getI2S3_TxBUFF();
int INSAMPLE_I2S_MONO[1024];
int * I2S3_TxBUFF = getI2S3_TxBUFF();
int INSAMPLE_I2S_MONO[1024];
for (int i = 2048; i < 4096; i++) {
if ((i % 2) == 0) { // L Samples
INSAMPLE_I2S_MONO[(i >> 1)-1024] = I2S1_RxBUFF[i];
} else if ((i % 2) == 1){ // R Samples
INSAMPLE_I2S_MONO[((i - 1) >> 1) - 1024] += I2S1_RxBUFF[i];
INSAMPLE_I2S_MONO[((i - 1) >> 1) - 1024] = INSAMPLE_I2S_MONO[((i - 1) >> 1) - 1024] >> 1;
}
}
for (int i = 2048; i < 4096; i++) {
if ((i % 2) == 0) { // L Samples
} else if ((i % 2) == 1){ // R Samples
}
if (i < 3072) {
I2S3_TxBUFF[i - 1024] = INSAMPLE_I2S_MONO[i-2048];
}
}
Results: @ 6Hz
@ 56Hz
@ 1kHz
@ 4khz