ftone.c

来自「CHP 3 - Real-Time Digital Signal Process」· C语言 代码 · 共 44 行

C
44
字号
// 
//  Project: Experiment 3.6.6.1 Real Time Signal Generation - Chapter 3  
//  File name: ftone.c   
//
//  Description: This function generates a tone using the math library cos(x)
//
//  For the book "Real Time Digital Signal Processing: 
//                Implementation and Application, 2nd Ed"
//                By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
//                Publisher: John Wiley and Sons, Ltd
//
//  Tools used: CCS v.2.12.07
//              TMS320VC5510 DSK Rev-C
//

#include <math.h>

#define UINTQ14     0x3FFF
#define PI          3.1415926

// Function prototype
void initFTone(unsigned short f, unsigned short Fs);
short ftone(unsigned short Fs);        

// Variable definition
static unsigned short n;         
static float twoPI_f_Fs;

void initFTone(unsigned short f, unsigned short Fs)
{
  n = 0;
  twoPI_f_Fs = 2.0*PI*(float)f/(float)Fs;
}

short fTone(unsigned short Fs)          
{    
  n++;
  if (n >= Fs)
  {
    n=0;
  }
  return((short)(cos(twoPI_f_Fs*(float)n)*UINTQ14));
}

⌨️ 快捷键说明

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