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

📄 siggentest.c

📁 CHP 3 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 3.6.6.5 Real Time Signal Generation - Chapter 3  
//  File name: sigGenTest.c   
//
//  Description: This function is a real-time signal generator for C5510 DSK
//               The audio samples are generated by C55x assembly routines
//
//  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 "signalGencfg.h"
#include "dsk5510.h"
#include "dsk5510_aic23.h"

// Codec configuration settings  
DSK5510_AIC23_Config config = { \
  0x0017,  /* 0 DSK5510_AIC23_LEFTINVOL  Left line input channel volume */ \
  0x0017,  /* 1 DSK5510_AIC23_RIGHTINVOL Right line input channel volume */\
  0x01f9,  /* 2 DSK5510_AIC23_LEFTHPVOL  Left channel headphone volume */  \
  0x01f9,  /* 3 DSK5510_AIC23_RIGHTHPVOL Right channel headphone volume */ \
  0x0011,  /* 4 DSK5510_AIC23_ANAPATH    Analog audio path control */      \
  0x0000,  /* 5 DSK5510_AIC23_DIGPATH    Digital audio path control */     \
  0x0000,  /* 6 DSK5510_AIC23_POWERDOWN  Power down control */             \
  0x0043,  /* 7 DSK5510_AIC23_DIGIF      Digital audio interface format */ \
  0x008D,  /* 8 DSK5510_AIC23_SAMPLERATE Sample rate control */            \
  0x0001   /* 9 DSK5510_AIC23_DIGACT     Digital interface activation */   \
};

enum
{
  TONE = 0,
  RANDOM,
  TONERAND
};

// Funciton prototypes
void signalGen(unsigned short seconds, unsigned short sampleRate, short generator);

extern void  initTone(unsigned short f, unsigned short Fs);
extern void  initRand(unsigned short seed);
extern short tone(unsigned short Fs);  
extern short randNumber(void);  


// Glabel veriables 
DSK5510_AIC23_CodecHandle hCodec;
    
/*
 *  main() - Main code routine, initializes BSL and generates tone
 */

void main()
{
  // Initialize the board support library, must be called first
  DSK5510_init();

  // Start the codec  
  hCodec = DSK5510_AIC23_openCodec(0, &config);
    
  // Initializations with tone frequency and sampling frequency
  initTone(400, 8000);
  initRand(0x1955);
        
  // Generate 5 seconds random noise at 8000Hz sampling rate using math library  
  signalGen(5, 8000, RANDOM);

  // Generate 5 seconds 400Hz tone at 8000Hz sampling rate using math library  
  signalGen(5, 8000, TONE);

  // Generate 5 seconds random noise with 400Hz tone at 8000Hz sampling rate  
  signalGen(5, 8000, TONERAND);

  // Close the codec  
  DSK5510_AIC23_closeCodec(hCodec);
}

void signalGen(unsigned short seconds, unsigned short sampleRate, short generator)
{
  unsigned short i,j;
  short sample;
    
  for (i = 0; i < seconds; i++)
  {
    for (j = 0; j < sampleRate; j++)
    {    
      switch(generator)
      {
        case TONE:
          sample = tone(sampleRate)>>1;
          break;
        case RANDOM: 
          sample = randNumber()<<1;
          break;
        case TONERAND:  
          sample = (tone(sampleRate)>>1) + randNumber();                    
          break;                
      }
      // Write a sample to the left output channel  
      while (!DSK5510_AIC23_write16(hCodec, sample));
      // Write a sample to the right output channel  
      while (!DSK5510_AIC23_write16(hCodec, sample));
    }    
  }
}

⌨️ 快捷键说明

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