Advertisement
worms005

DSP

Nov 29th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.37 KB | None | 0 0
  1.  
  2. #include "stdio.h"
  3. #include "usbstk5505.h"
  4. #include "aic3204.h"
  5. #include "PLL.h"
  6. #include "FIR_Filters_asm.h"
  7. #include "LEDFlasher.h"
  8. #include "Hamming.h"
  9. #include "Hanning.h"
  10. #include "Kaiser.h"
  11. #include "Rectangular.h"
  12. #include "stereo.h"
  13.  
  14. Int16 left_input;
  15. Int16 right_input;
  16. Int16 left_output;
  17. Int16 right_output;
  18. Int16 mono_input;
  19.  
  20. int k=0;
  21. Int16 mono[512];
  22. Int16 right[512];
  23. Int16 left[512];
  24.  
  25. #define SAMPLES_PER_SECOND 48000
  26. #define GAIN_IN_dB         30
  27.  
  28. unsigned long int i = 0;
  29. unsigned int step = 0;
  30.  
  31. /* ------------------------------------------------------------------------ *
  32.  *                                                                          *
  33.  *  main( )                                                                 *
  34.  *                                                                          *
  35.  * ------------------------------------------------------------------------ */
  36. void main( void )
  37. {
  38.     /* Initialize BSL */
  39.     USBSTK5505_init( );
  40.  
  41.     /* Initialize the Phase Locked Loop in EEPROM */
  42.     pll_frequency_setup(100);
  43.  
  44.     /* Initialise hardware interface and I2C for code */
  45.     aic3204_hardware_init();
  46.  
  47.     /* Initialise the AIC3204 codec */
  48.     aic3204_init();
  49.  
  50.     printf("\n\nRunning FIR Filters Project\n");
  51.     printf( "<-> Audio Loopback from Stereo Line IN --> to HP/Lineout\n\n" );
  52.  
  53.     /* Set sampling frequency in Hz and ADC gain in dB */
  54.     set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);
  55.  
  56.     puts("1 Flash   = Straight through, no processing");
  57.     puts("2 Flashes = Hamming filter 500 Hz");
  58.     puts("3 Flashes = Hamming filter 1000 Hz");
  59.     puts("4 Flashes = Hamming filter 2000 Hz");
  60.     puts("5 Flashes = Hamming filter 3000 Hz");
  61.  
  62.     asm(" bclr XF");
  63.  
  64.     for ( i = 0  ; i < SAMPLES_PER_SECOND * 600L  ;i++ )
  65.     {
  66.  
  67.      aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two channels.
  68.  
  69.      mono_input = stereo_to_mono(left_input, right_input);
  70.  
  71.  
  72.      step = LEDFlasher(5); // 5 Different filter settings.
  73.      step=2;
  74.      switch (step)
  75.       {
  76.        case 1:
  77.          left_output = mono_input; // Straight through, no processing.
  78.          right_output = mono_input;
  79.        break;
  80.  
  81.        case 2:
  82.          left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_500Hz[0], mono_input);
  83.          right_output = FIR_filter_asm_2(&Hamming_High_Pass_Filter_500Hz[0], mono_input);
  84.        break;
  85.  
  86.        case 3:
  87.          left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_1000Hz[0], mono_input);
  88.          right_output = FIR_filter_asm_2(&Hamming_High_Pass_Filter_1000Hz[0], mono_input);
  89.        break;
  90.  
  91.        case 4:
  92.          left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_2000Hz[0], mono_input);
  93.          right_output = FIR_filter_asm_2(&Hamming_High_Pass_Filter_2000Hz[0], mono_input);
  94.        break;
  95.  
  96.        case 5:
  97.          left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_3000Hz[0], mono_input);
  98.          right_output = FIR_filter_asm_2(&Hamming_High_Pass_Filter_3000Hz[0], mono_input);
  99.        break;
  100.       }
  101.      mono[k]=mono_input;
  102.      left[k]=left_output;
  103.      right[k]=right_output;
  104.      k=k+1;
  105.      if (k==512){
  106.          k=0;
  107.      }
  108.  
  109.      aic3204_codec_write(left_output, right_output);
  110.     }
  111.  
  112.    /* Disable I2S and put codec into reset */
  113.     aic3204_disable();
  114.  
  115.     printf( "\n***Program has Terminated***\n" );
  116.     SW_BREAKPOINT;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement