This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6748 LCDK Audio Signal Processing using starterware and DSP lib- work with channels

Other Parts Discussed in Thread: TMS320C6748

Hi,

I would like to do audio lms filtering and FIR/IIR filtering. I started with modyfying mcaspPlayBk.c from StarterWare.

I would like to work with both channels. First I want to let play only right channel, left channel and then swap left channel data with right channel data. I wrote following code and use it instead of memcpy() in mcaspPlayBk.c.

for(j=0;j<=(BUFLEN/4)-1;j++){

            sample1=*((unsigned short*)rxBufPtr[lastFullRxBuf]+4*j);//should be right channel
            sample2=*((unsigned short*)rxBufPtr[lastFullRxBuf]+2*j+1);//schould be filled with 0
            sample3=*((unsigned short*)rxBufPtr[lastFullRxBuf]+4*j+1);//schould be left channel

           *((unsigned short*)txBufPtr[lastSentTxBuf]+4*j)=(unsigned short)sample1;
           *((unsigned short*)txBufPtr[lastSentTxBuf]+2*j+1)=(unsigned short)sample2;
           *((unsigned short*)txBufPtr[lastSentTxBuf]+4*j+1)=(unsigned short)sample3;
            }

I expected following:

1)  when I will write sample1,2 and 3 on the same position, where I have read them out. I will hear both channels, as normal.

2)  when I let sample 1 on the correct position and  write 0 to correct position of sample3 . I will hear only right channel.

3)  when I let sample 3 on the correct position and write 0 to correct position of sample 1. I will hear only left channel.

4)  when I will swap sample1 and 3. I will also hear swept channels.

But in cases 1) and 2) I can hear only right channel and in other cases I can hear nothing.

Please can you point me a way how to separate an audio stream into right channel and left channel and swap the channels? And one more question: Is correct the idea stereo filtering= left channel filtering+ right channel filtering.

Thank you for your answers.

Petr Duga

I am using:

TMS320C6748 lcdk Ver 5

Code Composer Studio Version: 5.3.0.00090

C6748_StarterWare_1_20_03_03

dsplib_c674x_3_2_0_1

  • It works now.

    I made a mistake in indexing of left channel.

    It schould be 4*j+2 instead of 4*j+1.

    I thought the problem is in data format.

    Perhaps it helps somebody with audio proccessing.

    Petr Duga

  • No experience with McAsp. Comment on your code though. Not sure if your address arithmetic is correct.

    *((unsigned short*)rxBufPtr[lastFullRxBuf]+4*j);

    The order of precedence would have the array first, then the cast, then the offset. That would mean you would be indexing 4*j shorts rather than 4*j bytes past the base address. Suggest you wirte your own memcpy and use pointers to the proper types. Something like:

    void my_copy(void *d, const void *s, int n)
    {
      const unsigned short *src     = (const unsigned short *)s;
      unsigned short       *dst     = (unsigned short *)d;
      int                   samples = n/4;
      unsigned short left;
      unsigned short right;
      while(samples)
      {
        left  = src++;
        right = src++;
        dst++ = left;
        dst++ = right;
        samples--;
      }

    }

  • There is a working code for fir filtering based on mcaspPlayBk.c demo:

    //it works - for stereo until fs=24kHz, and just for one channel until 44100Hz//
                int i , j , AUDIO_BUF_SIZE_4 , AUDIO_BUF_SIZE_8 ;
                float SampleR, SampleL, SumR, SumL;

                AUDIO_BUF_SIZE_4=AUDIO_BUF_SIZE/4;
                AUDIO_BUF_SIZE_8=AUDIO_BUF_SIZE/8;

                for(i=0;i<HLEN-1;i++){
                    SumR=0;
                    SumL=0;
                   for(j=0;j<HLEN;j++){
                    if(i-j<0){
                    SampleR=(short )*((int *)rxBufPtr[lastbutoneFullRxBuf] + AUDIO_BUF_SIZE_4 + 2 * ( i - j) );
                    SampleL=(short )*((int *)rxBufPtr[lastbutoneFullRxBuf] + AUDIO_BUF_SIZE_4 + 2 * ( i - j) + 1 );
                    }else{
                    SampleR=(short )*((int *)rxBufPtr[lastFullRxBuf] + 2 * ( i - j) );
                    SampleL=(short )*((int *)rxBufPtr[lastFullRxBuf] + 2 * ( i - j) + 1 );
                    }
                    SumR=SumR+SampleR*hLP3400Ef[j];
                    SumL=SumL+SampleL*hLP3400Ef[j];
                    }
                    *((int*)txBufPtr[lastSentTxBuf] + 2 * i) = (short) SumR;
                    *((int*)txBufPtr[lastSentTxBuf] + 2 * i + 1) = (short) SumL;
                }


                for(i=HLEN-1; i<AUDIO_BUF_SIZE_8;i++){
                     SumR=0;
                     SumL=0;
                   for(j=0;j<HLEN;j++){
                     SampleR=(short)*((int*)rxBufPtr[lastFullRxBuf] + 2 * (i - j));
                     SumR=SumR+SampleR*hLP3400Ef[j];

                     SampleL=(short)*((int*)rxBufPtr[lastFullRxBuf] + 2 * (i - j) + 1);
                     SumL=SumL+SampleL*hLP3400Ef[j];
                     }
                     *((int*)txBufPtr[lastSentTxBuf] + 2 * i) = (short) SumR;
                     *((int*)txBufPtr[lastSentTxBuf] + 2 * i + 1) = (short) SumL;
                }

  • I'll take your word on it. Assuming a sample consists of a 16-bit left channel value and 16-bit right channel value, I get the impression you are processing every 2nd left channel value. Every other left channel and all right channel values appears to be discarded.

  • I'm not exactly sure how to use your code for FIR filtering, are both for-loops (AUDIO_BUF_SIZE_4 & AUDIO_BUF_SIZE_8)  needed? 

    what about that lastbutoneFullRxBuf identifier? 

    I'm modifying the starter ware mcasp example but with your FIR code i only get stuttering audio, would it be possible for you to upload a full working mcaspPlayBk.c that filters input with a FIR filter and outputs it?