⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 performance.c

📁 TMS320C5416算法程序包。其中包括FFT
💻 C
字号:
/*****************************************************************************/
/*                                                                           */
/* FILENAME                                                                  */
/* 	 performance.c                                                           */
/*                                                                           */
/* DESCRIPTION                                                               */
/*   TMS320C5416 DSK.                                                        */
/*   Looks at some factors which affect code execution speed e.g. C code vs. */
/*   optimised C code vs assembly code.                                      */
/*                                                                           */
/* REVISION                                                                  */
/*   Revision: 1.00	                                                         */
/*   Author  : Richard Sikora                                                */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* HISTORY                                                                   */
/*   Revision 1.00                                                           */
/*   11th December 2002. Created by Richard Sikora.                          */
/*                                                                           */
/*****************************************************************************/

#include <stdio.h>    /* Required for functions printf() and puts()          */


/*****************************************************************************/
/*                                                                           */
/* The name of the following header file will change if used as part of a    */
/* different project.  The new project xxxx will use xxxxcfg.h instead.      */
/*                                                                           */
/*****************************************************************************/

#include "performancecfg.h"

#include "dsk5416.h"
#include "dsk5416_pcm3002.h"

#include "dsk5416_led.h"

#include "adaptive_filter.h"
#include "adaptive_filter_asm.h"
#include "bargraph.h"
#include "blackman_low_pass_filter_1200Hz.h"
#include "comb.h"
#include "fftcmplx.h"
#include "FIR_filters.h"
#include "goertzel.h"
#include "IIR_filters_second_order.h"
#include "IIR_filters_second_order_asm.h"
#include "IIR_filters_fourth_order.h"
#include "IIR_filters_fourth_order_asm.h"
#include "IIR_filters_sixth_order.h"
#include "IIR_filters_sixth_order_asm.h"
#include "IIR_low_pass_filters.h"
#include "switches.h"

/*****************************************************************************/
/* Configuration setup of registers of PCM3002 Codec                         */
/*****************************************************************************/

DSK5416_PCM3002_Config setup = {

    0x1FF,      // Set-Up Reg 0 - Left channel DAC attenuation
    0x1FF,      // Set-Up Reg 1 - Right channel DAC attenuation
    0x0,        // Set-Up Reg 2 - Various ctl e.g. power-down modes
    0x0         // Set-Up Reg 3 - Codec data format control
};

/*****************************************************************************/
/*                                                                           */
/* For compatibility with pcm3002 read / write, these variables must         */
/* be declared as Int16 or short int, rather than int.                       */
/*                                                                           */
/*****************************************************************************/

Int16 left_input;
Int16 left_output; 
Int16 right_input;
Int16 right_output;
Int16 mono_input; 

Int16 delay[3];       /* Delay for Goertzel filters */
COMPLEX y[128];       /* FFT up to 128 elements */

/*****************************************************************************/
/* UserTask()                                                                */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* The main user task.                                                       */
/*                                                                           */
/* Note that this task is not called by main(). It is scheduled by DSP/BIOS  */
/*                                                                           */
/*****************************************************************************/
 
void UserTask()
{
    DSK5416_PCM3002_CodecHandle hCodec;
    unsigned long i;
    unsigned int switch_value;
	
    /* Start the codec */
    hCodec = DSK5416_PCM3002_openCodec(0, &setup);
 
    /* Display project details on StdOut. \n is important. */
 
    puts("TMS320C5416 DSK: Comparison of performance of functions written in C and assembly language.\n");

    fourth_order_IIR_asm_initialise();

    for ( i = 0 ; i < 12000000 ; i++ )
    {
         /* Read user switches on DSK and display their meaning on Stdout. */
         switch_value = switch_status_display();
    
      if ( 0 == switch_value)
        {
          /* LED 3 displays the time to read / write first channel */
          DSK5416_LED_on(3);
        } 
      else 
        {
          DSK5416_LED_off(3); /* Always off for other cases */
        }  
      
      /* Read left input channel */    
      while (!DSK5416_PCM3002_read16(hCodec, &left_input));

      /* Output to left output channel */       
      while (!DSK5416_PCM3002_write16(hCodec, left_output));

      if ( 0 == switch_value)
        {  
          DSK5416_LED_off(3);
          /* LED 2 displays the time to read / write first channel */
          DSK5416_LED_on(2);  
        } 
      else
        {
          DSK5416_LED_off(2); /* Always off for other cases */
        }  

      /* Read right input channel */
      while (!DSK5416_PCM3002_read16(hCodec, &right_input));

      /* Output to right output channel */
      while (!DSK5416_PCM3002_write16(hCodec, right_output));
      
      if ( 0 == switch_value)
        {
          DSK5416_LED_off(2);
          /* LED 1 displays the time to read the user switches */
          DSK5416_LED_on(1);      
        }  
      
      /* Read user switches on DSK and display their meaning on Stdout. */
      switch_value = switch_status_display();
	  
	  /* Where required, generate mono input from left input and right input */
      mono_input = stereo_to_mono ( left_input, right_input);

      if ( 0 == switch_value)
        {
         DSK5416_LED_off(1);
         
         /* LED 0 displays the time the bargraph is on */
         DSK5416_LED_on(0);  
        
         /* Display greater of two outputs on bargraph */
         bargraph_6dB( left_output, right_output);

         DSK5416_LED_off(0);
        }
      else if ( 1 == switch_value)
        {
          /* Comb notch filters, 20 elements. Uses straight buffer */
          DSK5416_LED_on(1);
          comb_notch_filter ( mono_input, 20);
          DSK5416_LED_off(1);
          
          /* Comb notch filter, 20 elements. Uses circular buffer */
          DSK5416_LED_on(0);
          comb_notch_filter_circular( mono_input, 20 );     
          DSK5416_LED_off(0);          
        }  
      else if ( 2 == switch_value)
        {
          /* Comb notch filters, 80 elements. Uses straight buffer */
          DSK5416_LED_on(1);
          comb_bandpass_filter ( mono_input, 80);
          DSK5416_LED_off(1);
          
          /* Comb bandpass filter, 80 elements. Uses circular buffer */
          DSK5416_LED_on(0);
          comb_bandpass_filter_circular ( mono_input, 80);     
          DSK5416_LED_off(0);          
        } 
       else if ( 3 == switch_value)
        {
          /* Comb notch filters, 96 elements. Uses straight buffer */
          DSK5416_LED_on(1);
          comb_notch_filter ( mono_input, 96);
          DSK5416_LED_off(1);
          
          /* Comb bandpass filter, 96 elements. Uses straight buffer */
          DSK5416_LED_on(0);
          comb_bandpass_filter ( mono_input, 96);     
          DSK5416_LED_off(0);          
        } 
      else if ( 4 == switch_value)
        {
          /* Adaptive filter in C */
          DSK5416_LED_on(1);
          left_output = adaptive_filter_unoptimized( left_input, right_input);
          DSK5416_LED_off(1);
          
          /* Adaptive filter in C */
          DSK5416_LED_on(0);
          right_output = adaptive_filter( left_input, right_input);
          DSK5416_LED_off(0);          
        
        }
      else if ( 5 == switch_value)
        {
          /* Adaptive filter in C */        
          DSK5416_LED_on(1);
          left_output = adaptive_filter( left_input, right_input);
          DSK5416_LED_off(1);
          
          /* Adaptive filter in assembly language */
          DSK5416_LED_on(0);
          right_output = adaptive_filter_asm_1( left_input, right_input);
          DSK5416_LED_off(0);          
        }        
      else if ( 6 == switch_value)
        {
          /* FIR filter in C */
          DSK5416_LED_on(1);
          left_output = FIR_filter( &blackman_low_pass_filter_1200Hz[0], left_input);
          DSK5416_LED_off(1);
          
          /* FIR filter in assembly language */
          DSK5416_LED_on(0);
          right_output = FIR_filter_asm( &blackman_low_pass_filter_1200Hz[0], right_input);
          DSK5416_LED_off(0);
        }  
      else if ( 7 == switch_value)
        {
          /* FIR filter in assembly language */
          DSK5416_LED_on(1);
          right_output = FIR_filter_asm( &blackman_low_pass_filter_1200Hz[0], right_input);
          DSK5416_LED_off(1);

          /* Fourth order IIR filter direct form II in assembly language */
          DSK5416_LED_on(0);
          right_output = fourth_order_IIR_direct_form_II_asm( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(0); 
        } 
      else if ( 8 == switch_value)
        {
          /* Second order IIR filter direct form I */
          DSK5416_LED_on(1);
          left_output = second_order_IIR_direct_form_I( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(1);
          
          /* Second order IIR filter direct form II */
          DSK5416_LED_on(0);
          right_output = second_order_IIR_direct_form_II( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(0);          
        }
      else if ( 9 == switch_value)
        {
          /* Second order IIR filter direct form II in C */
          DSK5416_LED_on(1);
          left_output = second_order_IIR_direct_form_II( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(1);
          
          /* Second order IIR filter direct form II in assembly language */
          DSK5416_LED_on(0);
          right_output = second_order_IIR_direct_form_II_asm( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(0);          
        }                
      else if ( 10 == switch_value)
        {
          /* Fourth order IIR filter direct form II in C */
          DSK5416_LED_on(1);
          left_output = fourth_order_IIR_direct_form_II( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(1);
          
          /* Fourth order IIR filter direct form II in assembly language */
          DSK5416_LED_on(0);
          right_output = fourth_order_IIR_direct_form_II_asm( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(0);          
        }
      else if ( 11 == switch_value)
        {
          /* Sixth order IIR filter direct form II in C */
          DSK5416_LED_on(1);
          left_output = sixth_order_IIR_direct_form_II( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(1);
          
          /* Sixth order IIR filter direct form II in assembly language */
          DSK5416_LED_on(0);
          right_output = sixth_order_IIR_direct_form_II_asm( &IIR_low_pass_1200Hz[0], mono_input);
          DSK5416_LED_off(0);          
        }        
      else if ( 12 == switch_value)
        {
          /* Goertzel Filter */
          DSK5416_LED_on(1);
          goertzel_filter ( &delay[0], mono_input, 0x4000 );  
          DSK5416_LED_off(1);
          
          /* Goertzel in signal using Goertzel filter */
          DSK5416_LED_on(0);
          calculate_goertzel_output( &delay[0], 0x4000);     
          DSK5416_LED_off(0);          
        } 
      else if ( 13 == switch_value)
        {
          /* 4-point Fast Fourier Transform */  
          DSK5416_LED_on(1);
          FFT( &y[0], 4);     
          DSK5416_LED_off(1);
          
          /* 8-point Fast Fourier Transform */
          DSK5416_LED_on(0);
          FFT ( &y[0], 8);     
          DSK5416_LED_off(0);          
        }
      else if ( 14 == switch_value)
        {
          /* 16-point Fast Fourier Transform */
          DSK5416_LED_on(1);
          FFT( &y[0], 16);           
          DSK5416_LED_off(1);
          
          /* 32-point Fast Fourier Transform */
          DSK5416_LED_on(0);
          FFT ( &y[0], 32);    
          DSK5416_LED_off(0);          
        }
      else if ( 15 == switch_value)
        {
          /* 64-point Fast Fourier Transform */
          DSK5416_LED_on(1);
          FFT( &y[0], 64);      
          DSK5416_LED_off(1);
          
          /* 128-point Fast Fourier Transform */
          DSK5416_LED_on(0);
          FFT ( &y[0], 128);    
          DSK5416_LED_off(0);          
        }        
                 
     }

    /* Finished processing. Close the codec */
    DSK5416_PCM3002_closeCodec(hCodec);
    
    puts("TMS320C5416 DSK has terminated.\n");
}

/*****************************************************************************/
/* main()                                                                    */
/*****************************************************************************/

void main()
{
    /* Initialize the board support library                         */
    /* There is no need to initialize the DIP switches and the LEDs */
    
    DSK5416_init();
    
    /* All other functions are scheduled by DSP/BIOS */
}

/******************************************************************************/
/* End of performance.c                                                       */
/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -