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

📄 thrprocess.c

📁 在DM642上实现基于reference frame5的语音处理完整工程
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) ReferenceFrameworks 2.10.00.11 04-30-03 (swat-d15)" */
/*
 *  ======== thrProcess.c ========
 *
 *  Implementation of the Process thread.  
 *  This thread is a typical data processing thread. It consists of NUMCHANNELS
 *  RF5 channels, each consisting of two RF5 cells. An RF5 cell is a wrapper
 *  around an XDAIS algorithm that gives it a uniform data processing interface.
 *  (since XDAIS algorithms have different processing functions with different
 *  signatures). An RF5 channel is a collection of cells, which execute in 
 *  series. 
 */

#include <std.h>

// DSP/BIOS includes
#include <mbx.h>
#include <sys.h>

// RF5 module includes
#include <chan.h>
#include <icell.h>
#include <scom.h>
#include <icc.h>
#include <icc_linear.h>
#include <utl.h>

// application includes
#include "appResources.h"
#include "appThreads.h"

// Thread include
#include "thrProcess.h"

// Cell includes
#include "fir/cellFir.h"
#include "vol/cellVol.h"


/*
 *   Incoming data goes into bufInputs.
 *   Outgoing data goes into bufOutputs.
 *   bufIntermediate is used in the intermediate processing.
 *
 *   The intermediate buffer is shared across all channels.
 *   In this appl., we need only one because there are only 2 cells
 *   per channel and there is only 1 output buffer for the first
 *   cell of each channel.  If there were more cells per channel
 *   or if there were more inputs/outputs per cell, additional 
 *   intermediate buffers are needed as appropriate.
 */
static Sample bufInput[ NUMCHANNELS ][ FRAMELEN ];
static Sample bufOutput[ NUMCHANNELS ][ FRAMELEN ];
static Sample bufIntermediate[ FRAMELEN ];

/*
 *  Thread process object which encapsulates the state information 
 *  of the thread.
 */ 
ThrProcess thrProcess;

/* 
 * Handle to mailbox for control messages 
 */
MBX_Handle mbxProcess;

/* 
 *  FIR filter coefficients: each channel runs a different instance of
 *  the FIR algorithm, and we initialize each instance with a different
 *  filter, i.e. with a different set of coefficients.
 */

// number of filter taps
#define NUMFIRTAPS  32

/* 
 * The following filters have been designed with the compromise to let
 * through a reasonable amount of audio content when used with sampling 
 * rates from 8 to 48 kHz. This is due to the wide variety of default 
 * sampling rates supported in the various ports of RF5.
 */
static Short filterCoeffLowPass[ NUMFIRTAPS ] = {
    // Low-pass, 32 taps, passband 0 to 500 Hz for sampling rate of 8kHz
    0x08FC, 0xF6DE, 0xF92A, 0xFA50, 0xFB17, 0xFBF0, 0xFD2A, 0xFECF,
    0x00EC, 0x036C, 0x0623, 0x08E1, 0x0B6E, 0x0D91, 0x0F1A, 0x0FE9,
    0x0FE9, 0x0F1A, 0x0D91, 0x0B6E, 0x08E1, 0x0623, 0x036C, 0x00EC,
    0xFECF, 0xFD2A, 0xFBF0, 0xFB17, 0xFA50, 0xF92A, 0xF6DE, 0x08FC
};
static Short filterCoeffHighPass[ NUMFIRTAPS ] = {
    // High-pass, 32 taps, passband 500 Hz to 4 kHz for sampling rate of 8kHz
    0x08B6, 0xFC32, 0xFC41, 0x09CF, 0x0467, 0x0B2E, 0x0099, 0x05FB, 
    0xF920, 0x014E, 0xF1B4, 0xFF3F, 0xE8F9, 0x02AB, 0xD626, 0x41EB, 
    0x41EB, 0xD626, 0x02AB, 0xE8F9, 0xFF3F, 0xF1B4, 0x014E, 0xF920,
    0x05FB, 0x0099, 0x0B2E, 0x0467, 0x09CF, 0xFC41, 0xFC32, 0x08B6
};
static Short filterCoeffPassThrough[ NUMFIRTAPS ] = {
    // Pass-through, 32 taps
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FFF
};

/* the list of all coefficient arrays */
static Short * filterCoeffList[] = { 
    filterCoeffLowPass, filterCoeffHighPass, filterCoeffPassThrough
};


// Local function prototypes
static Void setParamsAndStartChannels( Bool doChannelOpen );

/*
 *  ======== thrProcessInit ========
 *
 *  Initialization of the thread's object structure, creation of
 *  SCOM queues, and registration of cells (via setParamsAndStartChannels()
 *  function below).
 */
Void thrProcessInit()
{
    Int i;
    SCOM_Handle scomReceiveFromRx;
    SCOM_Handle scomReceiveFromTx;

    /* Set-up the threads's buffer pointers. */
    for (i = 0; i < NUMCHANNELS; i++) {
        thrProcess.bufInput[i]  = bufInput[i];
        thrProcess.bufOutput[i] = bufOutput[i];
    }
    thrProcess.bufIntermediate = bufIntermediate;

    /* create named SCOM queues for receiving messages from other tasks */
    scomReceiveFromRx = SCOM_create( "scomToProcessFromRx", NULL );
    scomReceiveFromTx = SCOM_create( "scomToProcessFromTx", NULL );
    UTL_assert( scomReceiveFromRx != NULL );
    UTL_assert( scomReceiveFromTx != NULL );    
    
    /* create mailbox for control messages */
    mbxProcess = MBX_create(sizeof(CtrlMsg), THRPROCESS_MBXLENGTH, NULL);  
    UTL_assert( mbxProcess != NULL );

    setParamsAndStartChannels( FALSE );
}

/*
 *  ======== thrProcessStartup ========
 *
 *  Thread startup: post-initialization activation. Cells that were 
 *  registered in thrProcessInit(), via setParamsAndStartChannels(),
 *  are now actually created when the channel is created.
 */
Void thrProcessStartup()
{
    setParamsAndStartChannels( TRUE );
}


/*
 *  ======== setParamsAndStartChannels ========
 *
 *  This function creates channels/cells from the list. It's called twice:
 *  once from init (with FALSE passed as the argument), and once from 
 *  startup (with TRUE). Both times it has to create cell parameters
 *  and keep it on the stack -- but the first time it registers the cells,
 *  whereas the second time it opens the channel, which causes the XDAIS
 *  algorithms in the cells to be created.
 */
static Void setParamsAndStartChannels( Bool doChannelOpen ) 
{
    IFIR_Params firParams;
    IVOL_Params volParams;    
    Int         chanNum;
    ICELL_Obj  *cell;
    Bool        rc;    
    ICC_Handle  inputIcc;
    ICC_Handle  outputIcc;
    

    for (chanNum = 0; chanNum < NUMCHANNELS; chanNum++) {

        // prepare parameters for FIR and VOL
        firParams           = IFIR_PARAMS;        // copy the defaults
        firParams.coeffPtr  = filterCoeffLowPass; // and override different fields
        firParams.filterLen = NUMFIRTAPS;
        firParams.frameLen  = FRAMELEN;

        volParams           = IVOL_PARAMS;
        volParams.frameSize = FRAMELEN;        

        /* 
         *  register the cells: define what will be input buffers and
         *  what will be output buffers for each cell.
         */
        if (doChannelOpen == FALSE) {
            
            /* Setup a default cell used to initialize the actual cells */
            ICELL_Obj   defaultCell = ICELL_DEFAULT;

            /*
             *  cell 0 - FIR: create an input linear ICC buffer that points to
             *  bufInput[ <channel number> ], and an output linear ICC buffer
             *  that points to the intermediate buffer, bufIntermediate;
             *  the cell will always look for data in those buffers.
             */
            cell = &thrProcess.cellList[ (chanNum * NUMCELLS) + CELLFIR ];
            *cell                = defaultCell;
            cell->name           = "FIR";
            cell->cellFxns       = &FIR_CELLFXNS;            
            cell->algFxns        = (IALG_Fxns *)&FIR_IFIR;
            cell->algParams      = (IALG_Params *)&firParams;
            cell->scrBucketIndex = THRPROCESSSCRBUCKET;

⌨️ 快捷键说明

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