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

📄 srctest.c

📁 CHP 4 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 4.5.7 Sample Rate Convertor using FIR filter - Chapter 4
//  File name: srcTest.c   
//
//  Description: This is the test file for the sample rate convertor
//
//  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 <stdlib.h>
#include <stdio.h>

#include "decimation.h"
#include "interpolation.h"

// Define DSP system memory map  
#pragma DATA_SECTION(deciFilt96to32, "expdata0:fir");
#pragma DATA_SECTION(temp, "expdata0:fir");
#pragma DATA_SECTION(x1, "expdata1:fir");
#pragma DATA_SECTION(x2, "expdata1:fir");
#pragma DATA_SECTION(w2, ".bss:fir");
#pragma DATA_SECTION(intpFilt48to96, ".data:fir");
#pragma DATA_SECTION(z1, "expdata1");
#pragma DATA_ALIGN(w2, 2);       // Use dual MAC, align to 32 bits
#pragma DATA_SECTION(y2, "expdata0");
#pragma DATA_ALIGN(z1, 2);       // Use dual MAC, align to 32 bits
#pragma DATA_ALIGN(y2, 2);       // Use dual MAC, align to 32 bits

short deciFilt96to32[TAPS96to32]={
  #include "coef96to32.h"
};
short intpFilt48to96[TAPS48to96]={
  #include "coef48to96.h"
};

short w2[TAPS96to32+1];          // Use dual MAC, add one space
short x1[INT_NUM_DATA_IN],       // Input data
      x2[INT_NUM_DATA_OUT];      // Intermediate data
char  temp[DEC_NUM_DATA_IN*2];   // Temp buffer for file IO
short z1[(TAPS48to96/2)];
short y2[DEC_NUM_DATA_OUT];      // Output data


void main()
{
  FILE  *fpIn,*fpOut;
  short i,k,
        index1,                 // Delay line w1 index
        index2;                 // Delay line w2 index

  fpIn = fopen("..\\data\\tone1k_48000.pcm", "rb");
  fpOut = fopen("..\\data\\output1kHz32kHz.pcm", "wb");

  if (fpIn == NULL)
  {
    printf("Can't open input file\n");
    exit(0);
  }

  for (i=0; i<=TAPS96to32; i++)
  {
    w2[i] = 0;
  }
  for (i=0; i<TAPS48to96/2; i++)
  {
    z1[i] = 0;
  }

  index1 = 0;
  index2 = 0;

  // Begin filtering the data
  while (fread(temp, sizeof(char), INT_NUM_DATA_IN*2, fpIn) 
         == (INT_NUM_DATA_IN*2))
  {
    for (k=0, i=0; i<INT_NUM_DATA_IN; i++)
    {
      x1[i] = (temp[k]&0xFF)|(temp[k+1]<<8);
      k += 2;
    }
		
    // Interpolation 1:2
    interpolate(x1, INT_NUM_DATA_IN, 
                intpFilt48to96, TAPS48to96/2, 
                x2, 
                z1, &index1,
                2);

    // Decimation 3:1
    decimator(x2, DEC_NUM_DATA_OUT, 
              deciFilt96to32, TAPS96to32, 
              y2, 
              w2, &index2,
              3);

    for (k=0, i=0; i<DEC_NUM_DATA_OUT*2; i++)
    {
      temp[k++] = (y2[i]&0xFF);
      temp[k++] = (y2[i]>>8)&0xFF;
    }

    fwrite(temp, sizeof(char), (DEC_NUM_DATA_OUT*2), fpOut);
  }

  fclose(fpIn);
  fclose(fpOut);
}

⌨️ 快捷键说明

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