0
\$\begingroup\$

I have a confusing problem that's happening to me, ill explain it to the best of my abilities with code, text, all that good stuff.

THE PROBLEM:

I have a laptop that uses its in-line output into an ADC. The ADC then goes into my STM32H7 MCU. The MCU processes the audio signal using the CMSIS DSP LIBRARY. Once done doing the signal processing it shoots the newly filter data into the DAC from there the DAC is then connected to my headphones via an auxiliary cable.

When I play a music file that has stereo I hear it in both speakers of my headphone. Using this site as reference. Site I used to check for stereo

DIAGRAM: enter image description here

WHAT I FOUND:

I got it working but without using the DSP library, which is not a good thing as the DSP is needed here. Somehow the DSP library is adding the two channels together or mixing the two and I have no idea how.

Sample codes that got stereo working:

1.

void prcoess_inline_halfSample(int * RxBuff_inline, int * TxBuff_inline, float * inSample_inline_L, float * inSample_inline_R, 
                                   float * outSample_inline_L, float * outSample_inline_R, float scaleFactor, uint8_t volumeCurrent, 
                                   arm_biquad_casd_df1_inst_f32 * audioStream_L, arm_biquad_casd_df1_inst_f32 * audioStream_R,
                                   float inputCompensator) {
    
                for (int i = 0; i < 2; i ++){
    
                TxBuff_inline[i] = RxBuff_inline[i];
            }
    }
    
    void process_inline_CompleteSample(int * RxBuff_inline, int * TxBuff_inline, float * inSample_inline_L, float * inSample_inline_R, 
                                       float * outSample_inline_L, float * outSample_inline_R,float scaleFactor, uint8_t volumeCurrent, 
                                       arm_biquad_casd_df1_inst_f32 * audioStream_L, arm_biquad_casd_df1_inst_f32 * audioStream_R, 
                                       float inputCompensator) {
    
    
               for (int i = 2; i < 4; i ++){
                   
                   TxBuff_inline[i] = RxBuff_inline[i];
               }
    
                    
    }
void prcoess_inline_halfSample(int * RxBuff_inline, int * TxBuff_inline, float * inSample_inline_L, float * inSample_inline_R, 
                               float * outSample_inline_L, float * outSample_inline_R, float scaleFactor, uint8_t volumeCurrent, 
                               arm_biquad_casd_df1_inst_f32 * audioStream_L, arm_biquad_casd_df1_inst_f32 * audioStream_R, 
                               float inputCompensator) {

            for (int i = 0; i < 2; i ++){

              if (i % 2 == 0){ // L Samples

              inSample_inline_L[i] = (float) RxBuff_inline[i] * (scaleFactor * (float) volumeCurrent) * inputCompensator;

            } else if ( i % 2 == 1){ // R Samples

              inSample_inline_R[i-1] = (float) RxBuff_inline[i] * (scaleFactor * (float) volumeCurrent) * inputCompensator;

            }
        }
              //arm_biquad_cascade_df1_f32(audioStream_L, inSample_inline_L, outSample_inline_L, 1);
              //arm_biquad_cascade_df1_f32(audioStream_R, inSample_inline_R, outSample_inline_R, 1);

            for (int i = 0; i < 2; i ++){

               if (i % 2 == 0) { // L Samples

               TxBuff_inline[i] = (int)inSample_inline_L[i];

             } else if ( i % 2 == 1) { // R Samples

               TxBuff_inline[i] = (int)inSample_inline_R[i-1];

             }
        }
}

void process_inline_CompleteSample(int * RxBuff_inline, int * TxBuff_inline, float * inSample_inline_L, float * inSample_inline_R, 
                                   float * outSample_inline_L, float * outSample_inline_R,float scaleFactor, uint8_t volumeCurrent, 
                                   arm_biquad_casd_df1_inst_f32 * audioStream_L, arm_biquad_casd_df1_inst_f32 * audioStream_R, 
                                   float inputCompensator) {


           for (int i = 2; i < 4; i ++){

                  if (i % 2 == 0){ // L Samples

                  inSample_inline_L[i-1] = (float) RxBuff_inline[i] * (scaleFactor * (float) volumeCurrent) * inputCompensator;

                } else if ( i % 2 == 1){ // R Samples

                  inSample_inline_R[i-2] = (float) RxBuff_inline[i] * (scaleFactor * (float) volumeCurrent) * inputCompensator;

                }
            }

                 //arm_biquad_cascade_df1_f32(audioStream_L, &inSample_inline_L[1], &outSample_inline_L[1], 1);
                 //arm_biquad_cascade_df1_f32(audioStream_R, &inSample_inline_R[1], &outSample_inline_R[1], 1);

                 for (int i = 2; i < 4; i ++){

                   if (i % 2 == 0) { // L Samples

                   TxBuff_inline[i] = (int)inSample_inline_L[i-1];

                 } else if ( i % 2 == 1) { // R Samples

                   TxBuff_inline[i] = (int)inSample_inline_R[i-2];

                 }
            }
}

What this tells me is that I have my indexing correct, and my L and R channels positioned properly in the buffer to be transmitted to the DAC. Its something up with the DSP library for some reason.

ORIGINAL CODE:

void prcoess_inline_halfSample(int * RxBuff_inline, int * TxBuff_inline, float * inSample_inline_L, float * inSample_inline_R,
                               float * outSample_inline_L, float * outSample_inline_R, float scaleFactor, uint8_t volumeCurrent,
                               arm_biquad_casd_df1_inst_f32 * audioStream_L, arm_biquad_casd_df1_inst_f32 * audioStream_R,
                               float inputCompensator) {

            for (int i = 0; i < 2; i ++){

              if (i % 2 == 0){ // L Samples

              inSample_inline_L[i] = (float) RxBuff_inline[i] * (scaleFactor * (float) volumeCurrent) * inputCompensator;

            } else if ( i % 2 == 1){ // R Samples

              inSample_inline_R[i-1] = (float) RxBuff_inline[i] * (scaleFactor * (float) volumeCurrent) * inputCompensator;

            }
        }
              arm_biquad_cascade_df1_f32(audioStream_L, inSample_inline_L, outSample_inline_L, 1);
              arm_biquad_cascade_df1_f32(audioStream_R, inSample_inline_R, outSample_inline_R, 1);

            for (int i = 0; i < 2; i ++){

               if (i % 2 == 0) { // L Samples

               TxBuff_inline[i] = (int)outSample_inline_L[i];

             } else if ( i % 2 == 1) { // R Samples

               TxBuff_inline[i] = (int)outSample_inline_R[i-1];

             }
        }
}

void process_inline_CompleteSample(int * RxBuff_inline, int * TxBuff_inline, float * inSample_inline_L, float * inSample_inline_R,
                                   float * outSample_inline_L, float * outSample_inline_R,float scaleFactor, uint8_t volumeCurrent,
                                   arm_biquad_casd_df1_inst_f32 * audioStream_L, arm_biquad_casd_df1_inst_f32 * audioStream_R,
                                   float inputCompensator) {


           for (int i = 2; i < 4; i ++){

                  if (i % 2 == 0){ // L Samples

                  inSample_inline_L[i-1] = (float) RxBuff_inline[i] * (scaleFactor * (float) volumeCurrent) * inputCompensator;

                } else if ( i % 2 == 1){ // R Samples

                  inSample_inline_R[i-2] = (float) RxBuff_inline[i] * (scaleFactor * (float) volumeCurrent) * inputCompensator;

                }
            }

                 arm_biquad_cascade_df1_f32(audioStream_L, &inSample_inline_L[1], &outSample_inline_L[1], 1);
                 arm_biquad_cascade_df1_f32(audioStream_R, &inSample_inline_R[1], &outSample_inline_R[1], 1);

                 for (int i = 2; i < 4; i ++){

                   if (i % 2 == 0) { // L Samples

                   TxBuff_inline[i] = (int)outSample_inline_L[i-1];

                 } else if ( i % 2 == 1) { // R Samples

                   TxBuff_inline[i] = (int)outSample_inline_R[i-2];

                 }
            }
}

Any ideas what could be causing this?

\$\endgroup\$
2
\$\begingroup\$

Fixed it, an oversight on my part.

I was using the same state variables for both channels so thats why it sounded it was mixed together because it was using the old outputs of each channel to calculate a new value for the present channels.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.