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

📄 realtime_srctest.c

📁 CHP 4 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 4.5.8 Implementation of sample rate convertor in real-time - Chapter 4
//  File name: exp4.5.8_realtime_SRC.c   
//
//  Description: This is the test program for the real-time 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
//
//
//
//  This example demonstrates the use of LIO drivers with PIPs and the 
//  lio_pip adapter code. 
//
//  The application performs a sample rate convertion loopback, that
//  reads audio data from rx PIP connected to an input LIO channel, 
//  the data is converted by sample rate convertor and then written back 
//  out to a PIP connected to an output LIO channel.
//
//  The following objects need to be created in the DSP/BIOS
//  configuration for this application:
//
//  1 A SWI object named swiAudioProcess. 
//    Configure the function as _audioProcess and the mailbox value as 3.
//
//  2 Two PIP objects, one named pipTx, the other pipRx. The length of the
//    buffers should be the same and in a common multiple of the frame size 
//    for using decimation and interpolation.  Our example requires 80*6=480.
//    See the comments by the declarations below of pipTx and pipRx for the 
//    writer and reader notify function settings.
//


#include <std.h>

#include <pip.h>
#include <swi.h>
#include <sys.h>

#include <lio.h>
#include <plio.h>

#include "dsk5510_led.h"


// Set CONTROLLER_FXN_TABLE in the linker command file 
#define CONTROLLER_FXN_TABLE DSK5510_DMA_AIC23_ILIO

extern LIO_Fxns CONTROLLER_FXN_TABLE;
static LIO_Fxns *controller = &CONTROLLER_FXN_TABLE;

extern PIP_Obj pipRx; // writerNotify -> PLIO_rxPrime(plioRx)
                      // readerNotify -> SWI_andn(swiEcho,1)  
extern PIP_Obj pipTx; // writerNotify -> SWI_andn(swiEcho,2)
                      // readerNotify -> PLIO_txPrime(plioTx)  

// 'plioRx' and 'plioTx' objects will be initialized by PLIO_new(). 
PLIO_Obj plioRx, plioTx;


// Decimation coefficients and variables
#include "decimation.h"
short deciFilt48to24[TAPS48to24]={
   #include "coef48to24.h"
};
short deciFilt24to8[TAPS24to8]={
   #include "coef24to8.h"
};

short w1[TAPS48to24+1];          // Use dual MAC, add one space
short w2[TAPS24to8+1];           // Use dual MAC, add one space
short x2[DEC_NUM_DATA2],         // Intermediate data
	  y[DEC_NUM_DATA_OUT];       // Output data
short index1=0,                  // Delay line w1 index
	  index2=0;                  // Delay line w2 index

// Interpolation coefficients and variables
#include "interpolation.h"
short intpFilt8to16[TAPS8to16]={
   #include "coef8to16.h"
};

short intpFilt16to48[TAPS16to48]={
   #include "coef16to48.h"
};

short z1[(TAPS8to16/2)+1];
short z2[(TAPS16to48/3)+1];
short x4[INT_NUM_DATA2];
short indx1=0,                   // Delay line z2 index
	  indx2=0;                   // Delay line z2 index

// Dummy applicaiton - user can replace it for a specific application
void user_application(void);


void main()
{
  short i;
    
  // Initializes the AIC23 device 
  DSK5510_DMA_AIC23_init();
    
  // AIC23 configures, if parameter is NULL  
  // then the default settings will be used 48000 Hz sampling rate.
  DSK5510_DMA_AIC23_setup();
    
  // Link the PIPs to LIO channels 
  PLIO_new(&plioRx, &pipRx, LIO_INPUT, controller, NULL);
  PLIO_new(&plioTx, &pipTx, LIO_OUTPUT, controller, NULL);

  //
  // Prime the transmit side with buffers of silence.
  // The transmitter should be started before the receiver.
  // This results in input-to-output latency being one full
  // buffer period if the pipes is configured for 2 frames.
  //
  PLIO_txStart(&plioTx, PIP_getWriterNumFrames(&pipTx), 0);

  // Prime the receive side with empty buffers to be filled. 
  PLIO_rxStart(&plioRx, PIP_getWriterNumFrames(&pipRx));

  // Initialize for filtering process
  for (i=0; i<=TAPS48to24; i++)
  {
    w1[i] = 0;
  }
  for (i=0; i<=TAPS24to8; i++)
  {
    w2[i] = 0;
  }
  for (i=0; i<TAPS8to16/2; i++)
  {
    z1[i] = 0;
  }
  for (i=0; i<TAPS16to48/3; i++)
  {
    z2[i] = 0;
  }
}


//
//  This function (swiAudioProcess) is executed from DSP/BIOS SWI thread  
//  created statically with the DSP/BIOS configuration tool. 
//
//  The PLIO adapter posts the swi when an input PIP has a buffer of data 
//  and the output PIP has an empty buffer to put new data into. 
//
//  This function passes the input PIP to the sample rate convertor for 
//  sample rate decimation, process, and interpolation, and then places the
//  processed and interpolated samples to output PIP. 
//

Void audioProcess(Void)
{
  unsigned short *src, *dst, size;

  // Get the full rx buffer from the receive PIP 
  PIP_get(&pipRx);
  src = PIP_getReaderAddr(&pipRx);
  size = PIP_getReaderSize(&pipRx) * sizeof(short);

  // Get the empty tx buffer from the transmit PIP 
  PIP_alloc(&pipTx);
  dst = PIP_getWriterAddr(&pipTx);

  // Decimaiton 
  decimator(src, size/2, deciFilt48to24, TAPS48to24, x2, w1, &index1, 2);
  decimator( x2, size/6, deciFilt24to8,  TAPS24to8,   y, w2, &index2, 3);

  // User can add applicaitons here 
  user_application();
    
  // Interpolation  
  interpolate( y, size/6, intpFilt8to16,  TAPS8to16/2,   x4, z1, &indx1, 2);
  interpolate(x4, size/3, intpFilt16to48, TAPS16to48/3, dst, z2, &indx2, 3);

  // Record the amount of actual data being sent 
  PIP_setWriterSize(&pipTx, PIP_getReaderSize(&pipRx));

  // Free the receive buffer, put the transmit buffer 
  PIP_free(&pipRx);
  PIP_put(&pipTx);
}

void user_application(void)
{
  // This is the user application using samples at lower sampling rate
  // This application can process data at 8000 Hz sampling rate.
  return;  
}

⌨️ 快捷键说明

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