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

📄 guitar_tuner.c

📁 这是在TMS320C5416上实现的吉他发声程序
💻 C
字号:
/*****************************************************************************/
/*                                                                           */
/* FILENAME                                                                  */
/* 	 guitar_tuner.c                                                          */
/*                                                                           */
/* DESCRIPTION                                                               */
/*   Uses an adaptive filter to identify the notes of the strings of a       */
/*   guitar.                                                                 */
/*                                                                           */
/*                                                                           */
/* REVISION                                                                  */
/*   Revision: 1.00	                                                         */
/*   Author  : Richard Sikora                                                */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* HISTORY                                                                   */
/*   Revision 1.00                                                           */
/*   1st 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 "guitar_tunercfg.h"

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

#include "adaptive_filter.h"
#include "adaptive_filter_asm.h"
#include "sinewaves.h"
#include "bargraph.h"
#include "stereo.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; 

/*****************************************************************************/
/* 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;
    signed int reference;
	signed long result;
	
    /* Start the codec */
    hCodec = DSK5416_PCM3002_openCodec(0, &setup);
 
    /* Display project details on StdOut. \n is important. */
 
    puts("TMS320C5416 DSK: Guitar tuner using adaptive filters.\n");
          
    for ( i = 0 ; i < 12000000 ; i++ )
    {
      /* Read left input channel */    
      while (!DSK5416_PCM3002_read16(hCodec, &left_input));

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

      /* 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);
      
      /* 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)
        {
          left_output = left_input;
          right_output = right_input;
          /* Display greater of two outputs on bargraph */
          bargraph_6dB ( left_output, right_output);          
        }
      else if ( 1 == switch_value)
        {
          /* Generate 65 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 65, 8191 );
        
          /* Sixth string. Dropped C tuning. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }
      else if ( 2 == switch_value)
        {
          /* Generate 73 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 73, 8191 );
        
          /* Sixth string. Dropped D tuning. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }
      else if ( 3 == switch_value)
        {
          /* Generate 82 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 82, 8191 );
        
          /* Sixth string. Standard Tuning E. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        } 
      else if ( 4 == switch_value)
        {
          /* Generate 98 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 98, 8191 );
        
          /* Fifth string. Dropped G tuning. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }           
      else if ( 5 == switch_value)
        {
          /* Generate 110 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 110, 8191 );
        
          /* Fifth string. Standard and Open D tuning. Note = A. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }         
      else if ( 6 == switch_value)
        {
          /* Generate 147 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 147, 8191 );
        
          /* Fourth string. Standard, Open D and Open G tuning. Note = D. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        } 
      else if ( 7 == switch_value)
        {
          /* Generate 165 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 165, 8191 );
        
          /* Fourth string. Open E tuning. Note = E. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        } 
      else if ( 8 == switch_value)
        {
          /* Generate 185 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 185, 8191 );
        
          /* Third string. Open D tuning. Note = F#. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }                         
      else if ( 9 == switch_value)
        {
          /* Generate 196 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 196, 8191 );
        
          /* Third string. Standard and Open G tuning. Note = G. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }           
      else if ( 10 == switch_value)
        {
          /* Generate 220 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 220, 8191 );
        
          /* Second string. Open D tuning. Note = A. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }         
      else if ( 11 == switch_value)
        {
          /* Generate 247 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 247, 8191 );
        
          /* Second string. Standard tuning. Note = B. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }        
      else if ( 12 == switch_value)
        {
          /* Generate 293 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 293, 8191 );
        
          /* First string. Open D and Open G tuning. Note = D. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 0);
        }        
      else if ( 13 == switch_value)
        {
          /* Generate 330 Hz sinewave of amplitude 8191 */
          reference = generate_sinewave_1 ( 330, 8191 );
        
          /* First string. Standard and Open E tuning. Note = E. */
          result = adaptive_filter_asm_1 ( reference, mono_input );

          left_output = (signed int) (result >> 16); /* Remove high word */
          right_output = reference;
          
          /* Display only output from adaptive filter */
          bargraph_6dB ( left_output, 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 guitar_tuner.c                                                      */
/******************************************************************************/

⌨️ 快捷键说明

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