Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************/
- /* */
- /* FILENAME */
- /* main.c */
- /* */
- /* DESCRIPTION */
- /* TMS320C5505 USB Stick. Application 1. Getting started. */
- /* Take microphone input and send to headphones. */
- /* */
- /* REVISION */
- /* Revision: 1.00 */
- /* Author : Richard Sikora */
- /*---------------------------------------------------------------------------*/
- /* */
- /* HISTORY */
- /* Revision: 1.00 */
- /* 5th March 2010. Created by Richard Sikora from TMS320C5510 DSK code. */
- /* */
- /*****************************************************************************/
- /*
- * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
- *
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- #include "stdio.h"
- #include "usbstk5505.h"
- #include "aic3204.h"
- #include "PLL.h"
- #include "stereo.h"
- #include "usbstk5505_led.h"
- #include "math.h"
- Int16 left_input;
- Int16 right_input;
- Int16 left_output;
- Int16 right_output;
- Int16 mono_input;
- #define SAMPLES_PER_SECOND 48000
- #define MAX_NUM 10
- unsigned long int i = 0;
- #define cPI 3.14
- double const cPIRAD = 180;
- double const cFREQ = 1/SAMPLES_PER_SECOND;
- #define cCHOSEN_FREQ 4800
- double const cOMEGA = 0.628; // 2* cPI * (1/10))
- static unsigned long int counter = 0;
- static short temp_count = 0;
- /* ------------------------------------------------------------------------ *
- * *
- * void led_ctrl( short) *
- * *
- * ------------------------------------------------------------------------ */
- void led_ctrl(short sh)
- {
- if(temp_count == sh)
- {
- USBSTK5505_LED_off(sh);
- counter++;
- if(counter == SAMPLES_PER_SECOND)
- {
- temp_count = 0;
- }
- return;
- }
- if(counter > (SAMPLES_PER_SECOND/2))
- {
- temp_count++;
- counter = 0;
- }
- if(counter < ((SAMPLES_PER_SECOND/4) - 1) )
- {
- USBSTK5505_LED_on(sh);
- }
- else
- {
- USBSTK5505_LED_off(sh);
- }
- counter++;
- }
- /* ------------------------------------------------------------------------ *
- * *
- * main( ) *
- * *
- * ------------------------------------------------------------------------ */
- void main( void )
- {
- // changed:
- double sin_calc = 0;
- double sin_res = 0;
- double sin_calc_temp = 0;
- /* Initialize BSL */
- USBSTK5505_init( );
- USBSTK5505_LED_init( );
- /* Initialize PLL */
- pll_frequency_setup(100);
- /* Initialise hardware interface and I2C for code */
- aic3204_hardware_init();
- /* Initialise the AIC3204 codec */
- aic3204_init();
- printf("\n\nRunning Getting Started Project\n");
- printf( "<-> Audio Loopback from Stereo IN --> to HP/Lineout\n" );
- /* Setup sampling frequency and 30dB gain for microphone */
- set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, 30);
- asm(" bclr XF");
- for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )
- {
- // a) implementierung des 1. Ziel aus Aufgabe 1 : zB LED blinkt 2 mal für 2, 10 mal für 10, etc.
- // TODO here:
- led_ctrl(8);
- aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two channels.
- mono_input = stereo_to_mono(left_input, right_input);
- /*
- printf( "\nLeft:\n" );
- printf("%d",left_input);
- printf( "\nRight:\n" );
- printf("%d",right_input);
- */
- left_output = left_input; // Very simple processing. Replace with your own code!
- right_output = right_input; // Directly connect inputs to outputs.
- // Original :
- //aic3204_codec_write(left_output, right_output);
- // Changed:
- // Time is i (Ts). real time is Ts * n (n being natural)
- sin_calc+=cOMEGA;
- //sin_calc_temp = sin_calc/1000; //*(( ( 2*cPI) / SAMPLES_PER_SECOND) );
- if(sin_calc >= 6.28)
- {
- sin_calc -= 6.28;
- }
- //sin_calc_temp = i/100;
- sin_res = sin(sin_calc);
- aic3204_codec_write(sin_res*5000,sin_res*5000);
- }
- /* Disable I2S and put codec into reset */
- aic3204_disable();
- printf( "\n***Program has Terminated***\n" );
- SW_BREAKPOINT;
- }
- /* ------------------------------------------------------------------------ *
- * *
- * End of main.c *
- * *
- * ------------------------------------------------------------------------ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement