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.

Audio Sample Project Buffer problem

Hi,

I am trying to implement some DSP algorithm by using the Audio Sample Project. I have tried FFT/IFFT, FIR Filtering successfully. Now, I am trying to implement some kind of enhancement algorithm. It only includes trigonometric functions, "atan, cos and sin", FFT/IFFT and complex number magnitude/angle calculations. But when I run the code, the audio comes intermittently. If I decrease the sample rate to 8 KHZ, again the audio comes intermittently, but at least it can be understandable. I think the problem is related to buffers. One receive and one transmit buffers are used inside the program. Do I need to increase the number of buffers such that one of the is used for processing and the other one is only used for collecting or transmitting audio data?

How can I speed up the program? Do I need to use double buffers for both receive and transmit buffers? If so, how can I do that? Also the same problem occurs if I use SDRAM instead of IRAM (changing .far inside cmd file) and perform only FFT and IFFT operations in order to hear input audio at output.

I think, I miss some point, because 300 MHZ DSP can not be so slow. Could you please share your comments and recommendations with me?

Thanks&Best Regards,

Fikret Alim

  • Hi, again

    Can this problem be related with the usage of DMA? Is the DMA used or not used in the default configurations of audioSample.pjt given inside pspdrivers. I am doubtful about this issue, because inside the mcasp channel parameter settings inside the code, "IsDmaDriven" is set as NULL.

    What do you suggest to me, I need to speed up this simple program? I will implement a more complicated algorithm, but first I need to know what I was doing wrong?

    Best Regards,

    Fikret Alim

  • Below, you can find the additions and changes that I addet to the audioSample project. I also gave the Audio_Echo_Task(). If I switch the dip_switch to zero, then no problem at audio, but if the dip_switch is swithced to 1, then no sound can be heard. This is a simple enhancement algorithm as I said and I thought that problem may be related to the buffers. Can you please check and help me for my application.

    #define BUFLEN                  512 /* number of samples in the frame */
    #define BUFALIGN                128  /* alignment of buffer for L2 cache */

    #define N 512
    #pragma DATA_ALIGN(noise_mean, 8);
    float noise_mean[N]={0}; 

    clock_t t_start,t_stop,t_overhead;
    /*
     * ======== echo ========
     * This function copies from the input SIO to the output SIO. You could
     * easily replace the copy function with a signal processing algorithm.
     */
    Void Audio_echo_Task()
    {
        volatile int i32Count;
        Int nmadus = 0;
        float left_buffer[N], right_buffer[N],Clean_speech[2*N],Sig_Mag[N],Sig_phase[N];
     //Int16 *audio_in_buffer, *audio_out_buffer;
     Int16 *rcv,*xmt;
     float *twiddle;
     int i,rad;

     Int16 dip0,dip1,dip2;
     rad = 2;
        /* initialise the edma library                                            */
        edma3init();

        /* Call createStream function to create I/O streams                       */
        createStreams();

        /* Call prime function to do priming                                      */
        prime();

        /* Forever loop to continously receviec and transmit audio data           */
        for (i32Count = 0; i32Count >= 0; i32Count++)
        {

            nmadus = SIO_reclaim(inStream, (Ptr *)&rcv, NULL);

            /* Reclaim full buffer from the input stream                          */
            if (nmadus < 0)
            {
                LOG_printf(&trace,"\r\nError reclaiming full buffer from the input stream");
            }

            /* Reclaim empty buffer from the output stream to be reused           */
            nmadus = SIO_reclaim(outStream, (Ptr *)&xmt, NULL);
            if (nmadus < 0)
            {
                LOG_printf(&trace,"\r\nError reclaiming empty buffer from the output stream");
            }
      
            /* Issue an empty buffer to the input stream */
            if (SIO_issue(inStream, rcv, BUFSIZE * RX_NUM_SERIALIZER, NULL)
         != SYS_OK)
            {
                LOG_printf(&trace,"\r\nFailed to issue empty buffer to stream\n");
            }

      for (i = 0; i < BUFLEN; i++)
      {
       //printf("\n rcv[%d]= %d",2*i,rcv[2*i]);
          left_buffer[i]  = (float)(rcv[i * 2]) / 32768.0f;
          right_buffer[i] = (float)(rcv[i * 2 + 1]) / 32768.0f;
       //printf("\n left_buffer[%d] = %f ",i,left_buffer[i]);
       //printf("\n right_buffer[%d] = %f ",i,right_buffer[i]);
      }
      // complex FFT
      
            dip0 = EVMC6747_DIP_get( DIP_0 );

      if(dip0==1)
      {
       for (i = 0; i < N; i++)
       {
        pCFFT_InLeft[2 * i] = left_buffer[i];  //update Real part
        pCFFT_InLeft[2 * i + 1] = 0;     //fill 0 for imag part
        pCFFT_InRight[2 * i] = right_buffer[i];  //update Real part
        pCFFT_InRight[2 * i + 1] = 0;     //fill 0 for imag part
       }
       //memcpy (xmt, rcv, 2 * N * sizeof (Int16));
       tw_gen (w, N);

       // Once w(twiddles) are generated they can be saved as .const
       // and need not be generated every time..
       twiddle = (float *) w;

       // Forward FFT Calculation..
           t_start = clock ();

       DSPF_sp_fftSPxSP (N, pCFFT_InLeft, twiddle, pCFFT_OutLeft, brev, rad, 0, N);
       //DSPF_sp_fftSPxSP (N, pCFFT_InRight, twiddle, pCFFT_OutRight, brev, rad, 0, N);
       // Inverse FFT Calculation..
       
       if (cnt<5)
       {
        for(i=0;i<N;i++)
        {
         noise_mean[i]=noise_mean[i]+(pow((pow(pCFFT_OutLeft[2*i],2)+pow(pCFFT_OutLeft[2*i+1],2)),0.5))/5;
        }   
        cnt+=1;
       }
       else
       {
        for(i=0;i<N;i++)
        {
         Sig_Mag[i]=pow((pow(pCFFT_OutLeft[2*i],2)+pow(pCFFT_OutLeft[2*i+1],2)),0.5);
         Sig_phase[i]=atan(pCFFT_OutLeft[2*i+1]/pCFFT_OutLeft[2*i]);   
         Clean_speech[2*i]=(Sig_Mag[i]-noise_mean[i])*cos(Sig_phase[i]);
         Clean_speech[2*i+1]=(Sig_Mag[i]-noise_mean[i])*sin(Sig_phase[i]);
        
        }
       }
       DSPF_sp_ifftSPxSP (N, Clean_speech, twiddle, pCFFT_InvOutLeft, brev, rad, 0, N);
      // DSPF_sp_ifftSPxSP (N, pCFFT_OutRight, twiddle, pCFFT_InvOutRight, brev, rad, 0, N);
      // Restore CompleFFT out from pTemp..
          t_stop = clock ();

       for (i=0;i<N;i++)
       {
        left_buffer[i]=pCFFT_InvOutLeft[2*i];
        right_buffer[i]=pCFFT_InvOutLeft[2*i];
       }
      }
      // processing on left_buffer, right_buffer...
      for (i = 0; i < BUFLEN; i++)
      {
          xmt[i * 2] = (Int16)(left_buffer[i] * 32768.0f);
          xmt[i * 2 + 1] = (Int16)(right_buffer[i] * 32768.0f);
      }

            /* Issue full buffer to the output stream                             */
            if (SIO_issue(outStream, xmt, BUFSIZE * TX_NUM_SERIALIZER, NULL)
         != SYS_OK)
            {
                LOG_printf(&trace,"\r\nFailed to issue empty buffer to stream\n");
            }


        }
    }

  • 8623.audio.rar

     

    I have also added the project as attachment. I am really waiting for an answer, I tried everything, but I couldn't find anything wrong. Appreciated if someone can help me. In the attached project, the audio comes intermittently.

    Best Regards,

    Fikret Alim

  • Hi Fikret,

    I took a look at your project.

    As is it did not work for me - no audio!

    I tried to isolate the issue and it seems that the Clean_speech calculation is an issue. What I mean is that if I bypass the Clean_speech calculation and pass the pCFFT_OutLeft as input to the inverse function, everything works:

    //   DSPF_sp_ifftSPxSP (N, Clean_speech, twiddle, pCFFT_InvOutLeft, brev, rad, 0, N);
       DSPF_sp_ifftSPxSP (N, pCFFT_OutLeft, twiddle, pCFFT_InvOutLeft, brev, rad, 0, N);
      // DSPF_sp_ifftSPxSP (N, pCFFT_OutRight, twiddle, pCFFT_InvOutRight, brev, rad, 0, N);
      // Restore CompleFFT out from pTemp..

       for (i=0;i<N;i++)
       {
        left_buffer[i]=pCFFT_InvOutLeft[2*i];
        right_buffer[i]=pCFFT_InvOutLeft[2*i];
       }

      // processing on left_buffer, right_buffer...
      for (i = 0; i < BUFLEN; i++) // correct
      {
          xmt[i * 2] = (Int16)(left_buffer[i] * 32768.0f);
          xmt[i * 2 + 1] = (Int16)(right_buffer[i] * 32768.0f);
      }
     ..........

    I'm not sure if that helps, but I though it was worth mentioning...

  • Dear Mariana,

    Thank you for your answer. Actually, I am trying to increase the real-time processing performance of the software, because I will implement an algorithm including heavy tasks. And I wanted to learn what can I do for this issue. I have found the cache configuration given in the link below for this purpose;

    http://processors.wiki.ti.com/index.php/C6747_Audio_Example_cache_configuration

    But I have some problems with this configuration. My first question is; what should I do to adjust L2CFG Mode to 256k instead of 32k. Do the MAR bits need to be changed also or not? When I apply the changes same as in the link, then there is no problem I can hear the audio. But when I select 256k from the global settings and change the IRAM and CACHE_L2 properties then there is no problem at build, but I can't hear the audio.

    The second problem is, in the software I use DIP switch commands. I only change the cache settings, but there is an error related to DIP switch when the cache configuration is changed. The error is as follows;

     

     undefined         first referenced                                                                                                                                               

      symbol               in file                                                                                                                                                    

     ---------         ----------------                                                                                                                                               

     _EVMC6747_DIP_get C:\\Program Files\\Texas Instruments\\pspdrivers_01_30_01\\packages\\ti\\pspiom\\examples\\evm6747\\audio_basstrebsunum\\build\\ccs3\\Debug\\audioSample_io.obj

     

    error: unresolved symbols remain

    error: errors encountered during linking; "C:/Program Files/Texas

       Instruments/pspdrivers_01_30_01/packages/ti/pspiom/examples/evm6747/audio_ba

       sstrebsunum/build/ccs3/../../bin/Debug/audioSample.out" not built

     

    >> Compilation failure

     

    Build Complete,

      1 Errors, 0 Warnings, 0 Remarks.

    My last question is what else I can do for the performance, I read in a post that using double buffers in Audio Sample project increase the performance such that using buf[2][NUM_BUFS * 2]; instead of Ptr buf[NUM_BUFS * 2];. Does it also work?

    Thanks&Best Regards,

    Fikret

  • Fikret Alim said:
    My first question is; what should I do to adjust L2CFG Mode to 256k instead of 32k. Do the MAR bits need to be changed also or not? When I apply the changes same as in the link, then there is no problem I can hear the audio. But when I select 256k from the global settings and change the IRAM and CACHE_L2 properties then there is no problem at build, but I can't hear the audio.

    If you put 256K of L2 cache, it means that all your program is in external memory, and all the internal memory is used for caching the external memory. Some people preffer to have some part of the internal memory for the most critical routines, instead of having all in cacheable external memory.

    If you put L2 = 256K cache, then unless you remove the IRAM memory from the tcf file and put all the sections in the external memory, you should get a build error. Did you make all these changes?

    Also, for efficiancy, you might want to make all external memory cacheable. That is done in the MAR bits in the page you mentioned:

    http://processors.wiki.ti.com/index.php/C6747_Audio_Example_cache_configuration

    Fikret Alim said:

    The second problem is, in the software I use DIP switch commands. I only change the cache settings, but there is an error related to DIP switch when the cache configuration is changed. The error is as follows;

      undefined         first referenced                                                                                                                                               

      symbol               in file                                                                                                                                                    

     ---------         ----------------                                                                                                                                               

     _EVMC6747_DIP_get C:\\Program Files\\Texas Instruments\\pspdrivers_01_30_01\\packages\\ti\\pspiom\\examples\\evm6747\\audio_basstrebsunum\\build\\ccs3\\Debug\\audioSample_io.obj

     error: unresolved symbols remain

    error: errors encountered during linking; "C:/Program Files/Texas

       Instruments/pspdrivers_01_30_01/packages/ti/pspiom/examples/evm6747/audio_ba

       sstrebsunum/build/ccs3/../../bin/Debug/audioSample.out" not built

     >> Compilation failure

     Build Complete,

      1 Errors, 0 Warnings, 0 Remarks.

     This function is part of the BSL (board support library), have you included this library in your project? You can right click in the project, select "Add files to project" and browse to the ...\evmc6747_v1\dsp\lib\evmc6747bsl.lib file. Make sure that you use the EVMC6747_DIP_init function as well.

    Fikret Alim said:
    My last question is what else I can do for the performance, I read in a post that using double buffers in Audio Sample project increase the performance such that using buf[2][NUM_BUFS * 2]; instead of Ptr buf[NUM_BUFS * 2];. Does it also work?

    Never tried that, but it could work. You could also try to deouble the buffer sizer.