Skip to main content
CLeo.1
Senior II
June 13, 2021
Question

Why is my frequency being effectively doubled?

  • June 13, 2021
  • 0 replies
  • 421 views

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:

  • Ensured the I2S Clock is running correctly
  • Without summing just sending 1:1 samples and it's a mirror image of the input

The I2S3 DMA is setup as follow:

  • Length = 2048 (Tx_BUFF)

The I2S1 DMA is setup as follow:

  • Length = 4096 (Rx_BUFF)
  • Length - 4096 (Tx_BUFF)

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

0693W00000BaqUdQAJ.jpg@ 56Hz

0693W00000BaqUiQAJ.jpg@ 1kHz

0693W00000BaqUxQAJ.jpg@ 4khz

0693W00000BaqV2QAJ.jpg

This topic has been closed for replies.