Advertisement
Guest User

Untitled

a guest
May 25th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1. #include "C5515.h"
  2. #include "gpio.h"
  3. #include "i2c.h"
  4. #include "i2s.h"
  5.  
  6. #include "TMS320.h"
  7. #include "stdio.h"
  8. #include "math.h"
  9. #include "dsplib.h"
  10. #include "dsplib_c.h"
  11.  
  12. #include "aic3204.h"
  13.  
  14. #define W_LEN 4096
  15. #define EFFECT_FLAG 1
  16. #define NO_EFFECT_FLAG 0
  17. #define IER0 (*(unsigned int*)0x00)
  18. #define IVPD (*(unsigned int*)0x000049)
  19. #define IVPH (*(unsigned int*)0x00004A)
  20.  
  21. extern unsigned int VECSTART;
  22.  
  23. /*********Буферы левого и правого канала************/
  24. Int16 b1[W_LEN] = { 0 };
  25. Int16 b2[W_LEN] = { 0 };
  26. Int16 b3[W_LEN] = { 0 };
  27. Int16 b4[W_LEN] = { 0 };
  28.  
  29. Int16 b5[W_LEN] = { 0 };
  30. Int16 b6[W_LEN] = { 0 };
  31. Int16 b7[W_LEN] = { 0 };
  32. Int16 b8[W_LEN] = { 0 };
  33.  
  34. Int16* buf_in_left_1 = b1;
  35. Int16* buf_in_right_1 = b2;
  36. Int16* buf_out_left_1 = b3;
  37. Int16* buf_out_right_1 = b4;
  38.  
  39. Int16* buf_in_left_2 = b5;
  40. Int16* buf_in_right_2 = b6;
  41. Int16* buf_out_left_2 = b7;
  42. Int16* buf_out_right_2 = b8;
  43.  
  44. Int16* change;
  45.  
  46. Int16 buf_index = 0;
  47.  
  48. Int16 effect_flag = NO_EFFECT_FLAG;
  49.  
  50. /* Обработчик прерывания по передаче */
  51. interrupt void i2s2_tx_isr()
  52. {
  53.     I2S2_W0_MSW_W = buf_out_left_2[buf_index];
  54.     I2S2_W1_MSW_W = buf_out_right_2[buf_index];
  55.  
  56.     while ((Rcv & I2S2_IR) == 0);
  57.  
  58.     buf_in_left_2[buf_index] = I2S2_W0_MSW_R;
  59.     buf_in_right_2[buf_index] = I2S2_W1_MSW_R;
  60.  
  61.     buf_index++;
  62.  
  63.     if (buf_index >= W_LEN) {
  64.         change = buf_in_left_2;
  65.         buf_in_left_2 = buf_in_left_1;
  66.         buf_in_left_1 = change;
  67.  
  68.         change = buf_out_left_2;
  69.         buf_out_left_2 = buf_out_left_1;
  70.         buf_out_left_1 = change;
  71.  
  72.         change = buf_in_right_2;
  73.         buf_in_right_2 = buf_in_right_1;
  74.         buf_in_right_1 = change;
  75.  
  76.         change = buf_out_right_2;
  77.         buf_out_right_2 = buf_out_right_1;
  78.         buf_out_right_1 = change;
  79.  
  80.         buf_index = 0;
  81.         effect_flag = EFFECT_FLAG;
  82.     }
  83. }
  84.  
  85.  
  86. void allpass(Int16 * input, Int16 * output, float c){
  87.  
  88.     float oldy = 0;
  89.     float oldx = 0;
  90.     int i = 0;
  91.  
  92.     for(i=0; i < W_LEN; ++i)
  93.     {
  94.       output[i] = c * input[i] + oldx - c * oldy;
  95.       oldx = input[i];
  96.       oldy = output[i];
  97.     }
  98. }
  99.  
  100. void main(void) {
  101.  
  102.     /* Initialize BSL */
  103.     c5515_init();
  104.     /* Configure Parallel Port */
  105.     SYS_EXBUSSEL &= ~0x7000;
  106.     SYS_EXBUSSEL |= 0x1000;  // Configure Parallel Port for I2S2
  107.  
  108.     /* Configure Serial Port */
  109.     SYS_EXBUSSEL &= ~0x0C00;
  110.     SYS_EXBUSSEL |= 0x0400; // Serial Port mode 1 (I2S1 and GP[11:10]).
  111.     c5515_GPIO_init();
  112.     c5515_GPIO_setDirection(GPIO10, GPIO_OUT);
  113.     c5515_GPIO_setOutput(GPIO10, 1); // Take AIC3201 chip out of reset
  114.     I2C_init(); // Initialize I2C
  115.  
  116.     asm(" BSET INTM");
  117.     unsigned long int vector;
  118.     vector = (unsigned long int) &VECSTART;
  119.     vector = vector >> 8;
  120.     IVPD = (unsigned short) vector;
  121.     IVPH = (unsigned short) vector;
  122.     IER0 |= 0x4000;
  123.     asm(" BCLR INTM");
  124.  
  125.     /* I2S settings */
  126.     I2S2_SRGR = 0x0015;
  127.     I2S2_ICMR = 0x0028; // Enable interrupts
  128.     I2S2_CR = 0x8012; // 16-bit word, Master, enable I2C
  129.  
  130.     aic3204_stereo_in1();
  131.  
  132.     while (1) {
  133.  
  134.         if (effect_flag == EFFECT_FLAG) {
  135.             /* добавить функцию эффекта */
  136. //          effect_flag = NO_EFFECT_FLAG;
  137. //          buf_out_left_1 = buf_in_left_1;
  138. //          buf_out_right_1 = buf_in_right_1;
  139.             float c1 = 0.1;
  140.             float c2 = 0.09;
  141.             allpass(buf_in_left_1, buf_out_left_1, c1);
  142. //          allpass(buf_in_left_1, buf_out_right_1, c2);
  143.             buf_out_right_1 = buf_in_left_1;
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement