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

📄 quantaudiotest.c

📁 CHP 3 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 3.6.2 Quantization Audio - Chapter 3 
//  File name: quantAudioTest.c   
//
//  Description: This function is the quantization audio data experiment test program.
//               This function is modified based on the DSK tone example.
//
//  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 "quantAudiocfg.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 */ \
    0x0081,  /* 8 DSK5510_AIC23_SAMPLERATE Sample rate control */            \
    0x0001   /* 9 DSK5510_AIC23_DIGACT     Digital interface activation */   \
};

#define QUANT_16BIT    0xFFFF
#define QUANT_12BIT    0xFFF0
#define QUANT_8BIT     0xFF00
#define QUANT_4BIT     0xF000

void playAudio(unsigned short seconds, unsigned short sampleRate, short mask);

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

  // Start the codec  
  hCodec = DSK5510_AIC23_openCodec(0, &config);

  // Loop back line-in audio for 30 seconds at 48kHz sampling rate
  // No quantization
  playAudio(30, 48000, QUANT_16BIT);
    
  // Loop back line-in audio for 30 seconds at 48kHz sampling rate
  // Quantization to 12-bits
  playAudio(30, 48000, QUANT_12BIT);

  // Loop back line-in audio for 30 seconds at 48kHz sampling rate
  // Quantization to 8-bits
  playAudio(30, 48000, QUANT_8BIT);

  // Loop back line-in audio for 30 seconds at 48kHz sampling rate
  // Quantization to 4-bits
  playAudio(30, 48000, QUANT_4BIT);

  // Close the codec  
  DSK5510_AIC23_closeCodec(hCodec);
}

void playAudio(unsigned short seconds, unsigned short sampleRate, short mask)
{
  unsigned short i,j;
  short left,right;
    
  for (i = 0; i < seconds; i++)
  {
    for (j = 0; j < sampleRate; j++)
    {    
      // Read a sample from the left input channel 
      while (!DSK5510_AIC23_read16(hCodec, &left));
      left = quantAudio(left, mask);    
      // Read a sample from the right input channel 
      while (!DSK5510_AIC23_read16(hCodec, &right));   
      right = quantAudio(right, mask);
            
      // Write a sample to the left output channel 
      while (!DSK5510_AIC23_write16(hCodec, left));
      // Write a sample to the right output channel 
      while (!DSK5510_AIC23_write16(hCodec, right));
    }    
  }
}

⌨️ 快捷键说明

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