Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.24 KB | None | 0 0
  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /* FILENAME                                                                  */
  4. /*   main.c                                                                  */
  5. /*                                                                           */
  6. /* DESCRIPTION                                                               */
  7. /*   TMS320C5505 USB Stick. Application 1. Getting started.                  */
  8. /*   Take microphone input and send to headphones.                           */
  9. /*                                                                           */
  10. /* REVISION                                                                  */
  11. /*   Revision: 1.00                                                          */
  12. /*   Author  : Richard Sikora                                                */
  13. /*---------------------------------------------------------------------------*/
  14. /*                                                                           */
  15. /* HISTORY                                                                   */
  16. /*   Revision: 1.00                                                          */
  17. /*   5th March 2010. Created by Richard Sikora from TMS320C5510 DSK code.    */
  18. /*                                                                           */
  19. /*****************************************************************************/
  20. /*
  21.  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  22.  *
  23.  *
  24.  *  Redistribution and use in source and binary forms, with or without
  25.  *  modification, are permitted provided that the following conditions
  26.  *  are met:
  27.  *
  28.  *    Redistributions of source code must retain the above copyright
  29.  *    notice, this list of conditions and the following disclaimer.
  30.  *
  31.  *    Redistributions in binary form must reproduce the above copyright
  32.  *    notice, this list of conditions and the following disclaimer in the
  33.  *    documentation and/or other materials provided with the  
  34.  *    distribution.
  35.  *
  36.  *    Neither the name of Texas Instruments Incorporated nor the names of
  37.  *    its contributors may be used to endorse or promote products derived
  38.  *    from this software without specific prior written permission.
  39.  *
  40.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  41.  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  42.  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  43.  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  44.  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  45.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  46.  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  47.  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  48.  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  49.  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  50.  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  51.  *
  52. */
  53.  
  54. #include "stdio.h"
  55. #include "usbstk5505.h"
  56. #include "aic3204.h"
  57. #include "PLL.h"
  58. #include "stereo.h"
  59. #include "usbstk5505_led.h"
  60. #include "math.h"
  61.  
  62. Int16 left_input;
  63. Int16 right_input;
  64. Int16 left_output;
  65. Int16 right_output;
  66. Int16 mono_input;
  67.  
  68.  
  69. #define SAMPLES_PER_SECOND 48000
  70. #define MAX_NUM 10
  71. unsigned long int i = 0;
  72.  
  73. #define cPI 3.14
  74. double const cPIRAD = 180;
  75. double const cFREQ = 1/SAMPLES_PER_SECOND;
  76. #define cCHOSEN_FREQ  4800
  77.  
  78. double const cOMEGA = 0.628; // 2* cPI * (1/10))
  79. static unsigned long int counter = 0;
  80. static short temp_count = 0;
  81. /* ------------------------------------------------------------------------ *
  82.  *                                                                          *
  83.  * void led_ctrl( short)                                                                 *
  84.  *                                                                          *
  85.  * ------------------------------------------------------------------------ */
  86. void led_ctrl(short sh)  
  87. {
  88.     if(temp_count == sh)
  89.     {
  90.         USBSTK5505_LED_off(sh);
  91.         counter++;
  92.         if(counter == SAMPLES_PER_SECOND)
  93.         {
  94.             temp_count = 0;
  95.         }
  96.         return;
  97.     }
  98.     if(counter > (SAMPLES_PER_SECOND/2))
  99.     {
  100.         temp_count++;
  101.         counter = 0;
  102.     }
  103.     if(counter < ((SAMPLES_PER_SECOND/4) - 1) )
  104.     {
  105.         USBSTK5505_LED_on(sh);
  106.     }
  107.     else
  108.     {
  109.         USBSTK5505_LED_off(sh);
  110.     }
  111.     counter++;
  112. }
  113.  
  114.  
  115.  
  116. /* ------------------------------------------------------------------------ *
  117.  *                                                                          *
  118.  *  main( )                                                                 *
  119.  *                                                                          *
  120.  * ------------------------------------------------------------------------ */
  121. void main( void )
  122. {
  123.     // changed:
  124.     double sin_calc = 0;
  125.     double sin_res = 0;
  126.     double sin_calc_temp = 0;
  127.    
  128.     /* Initialize BSL */
  129.     USBSTK5505_init( );
  130.     USBSTK5505_LED_init( );
  131.     /* Initialize PLL */
  132.     pll_frequency_setup(100);
  133.  
  134.     /* Initialise hardware interface and I2C for code */
  135.     aic3204_hardware_init();
  136.    
  137.     /* Initialise the AIC3204 codec */
  138.     aic3204_init();
  139.  
  140.     printf("\n\nRunning Getting Started Project\n");
  141.     printf( "<-> Audio Loopback from Stereo IN --> to HP/Lineout\n" );
  142.    
  143.     /* Setup sampling frequency and 30dB gain for microphone */
  144.     set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, 30);   
  145.  
  146.     asm(" bclr XF");
  147.    
  148.    
  149.    
  150.     for ( i = 0  ; i < SAMPLES_PER_SECOND * 600L  ;i++  )
  151.     {
  152.     // a) implementierung des 1. Ziel aus Aufgabe 1 : zB LED blinkt 2 mal für 2, 10 mal für 10, etc.
  153.     // TODO here:
  154.     led_ctrl(8);
  155.    
  156.      aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two channels.
  157.    
  158.      mono_input = stereo_to_mono(left_input, right_input);
  159.      /*
  160.      printf( "\nLeft:\n" );
  161.      printf("%d",left_input);
  162.      printf( "\nRight:\n" );
  163.      printf("%d",right_input);
  164.      */
  165.      left_output =  left_input;            // Very simple processing. Replace with your own code!
  166.      right_output = right_input;          // Directly connect inputs to outputs.
  167.    
  168.      // Original :
  169.      //aic3204_codec_write(left_output, right_output);
  170.      // Changed:
  171.      // Time is i (Ts). real time is Ts * n (n being natural)
  172.      sin_calc+=cOMEGA;
  173.      //sin_calc_temp = sin_calc/1000; //*(( ( 2*cPI) / SAMPLES_PER_SECOND) );
  174.      if(sin_calc >= 6.28)
  175.      {
  176.         sin_calc -= 6.28;
  177.      }
  178.      //sin_calc_temp = i/100;
  179.      sin_res = sin(sin_calc);
  180.      aic3204_codec_write(sin_res*5000,sin_res*5000);
  181.     }
  182.  
  183.    /* Disable I2S and put codec into reset */
  184.     aic3204_disable();
  185.  
  186.     printf( "\n***Program has Terminated***\n" );
  187.     SW_BREAKPOINT;
  188. }
  189.  
  190. /* ------------------------------------------------------------------------ *
  191.  *                                                                          *
  192.  *  End of main.c                                                           *
  193.  *                                                                          *
  194.  * ------------------------------------------------------------------------ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement