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

📄 thrprocess.c

📁 在DM642上实现基于reference frame5的语音处理完整工程
💻 C
📖 第 1 页 / 共 2 页
字号:
            inputIcc  = (ICC_Handle)ICC_linearCreate( 
                                   thrProcess.bufInput[ chanNum ], 
                                   FRAMELEN * sizeof( Sample ) );
            UTL_assert( inputIcc != NULL);

            outputIcc = (ICC_Handle)ICC_linearCreate( 
                                                thrProcess.bufIntermediate,
                                                FRAMELEN * sizeof( Sample ) );
            UTL_assert( outputIcc != NULL);

            // Only one input and one output ICC are needed.
            rc = CHAN_regCell( cell, &inputIcc, 1, &outputIcc, 1 );
            
            /*
             *  cell 1 - VOL: create an input linear ICC buffer that points to
             *  the intermediate buffer, bufIntermediate, and an output linear 
             *  ICC buffer that points to bufOutput[ <channel number> ].
             *  the cell will always look for data in those buffers.
             */
            cell = &thrProcess.cellList[ (chanNum * NUMCELLS) + CELLVOL ];
            *cell                = defaultCell;            
            cell->name           = "VOL";
            cell->cellFxns       = &VOL_CELLFXNS;            
            cell->algFxns        = (IALG_Fxns *)&VOL_IVOL;
            cell->algParams      = (IALG_Params *)&volParams;
            cell->scrBucketIndex = THRPROCESSSCRBUCKET;

            inputIcc  = outputIcc;

            outputIcc = (ICC_Handle)ICC_linearCreate(
                                thrProcess.bufOutput[ chanNum ], 
                                FRAMELEN * sizeof( Sample ) );
            UTL_assert( outputIcc != NULL);

            // Only one input and one output ICC are needed.
            rc = CHAN_regCell( cell, &inputIcc, 1, &outputIcc, 1 );
        }
        else {

            /*
             *  Since firParams and volParams are local variables, they need to
             *  be set-up again for proper creation of the algorithms.
             */ 
            thrProcess.cellList[ (chanNum * NUMCELLS) + CELLFIR ].algParams = 
                (IALG_Params *)&firParams;
            thrProcess.cellList[ (chanNum * NUMCELLS) + CELLVOL ].algParams = 
                (IALG_Params *)&volParams;

            UTL_logDebug1("Channel Number: %d", chanNum);

            // open the channel: this causes the algorithms to be created
            rc = CHAN_open( &thrProcess.chanList[ chanNum ], 
                            &thrProcess.cellList[ chanNum * NUMCELLS ], 
                            NUMCELLS,
                            NULL );
        }
        UTL_assert( rc == TRUE );
    }
}


/*
 *  ======== checkMsg ========
 *
 *  Checks if there are any messages for the process and acts on them.
 *  Called from the thread's run() function.
 */
static Void checkMsg()
{
    CtrlMsg rxMsg;

    while( MBX_pend( mbxProcess, &rxMsg, 0) ) {
        Int chanNum;
        ICELL_Handle hCell;

        /* 
         *  The format we expect for a message, i.e. {cmd, arg1, arg2} is 
         *  1. volume change message: { MSGNEWVOL,   channel #, volume value },
         *  2. filter change message: { MSGNEWCOEFF, channel #, filter type}
         *     where filter type is 0: low pass, 1: high pass, 2: passthrough.
         */
        chanNum = rxMsg.arg1;
        UTL_assert( (chanNum >= 0) && (chanNum < NUMCHANNELS) );

        switch (rxMsg.cmd) {        
            case MSGNEWVOL:
                {
                    IVOL_Status volStatus;

                    /* get handle for channel chanNum's VOL cell */
                    hCell = &thrProcess.cellList[CELLVOL + chanNum * NUMCELLS];
                    UTL_assert( hCell != NULL );

                    /* 
                     *  get current contents of the control structure 
                     *  to avoid overriding non-modified ones 
                     */
                    VOL_cellControl( hCell, IVOL_GETSTATUS, 
                                     (IALG_Status *)&volStatus );
                    volStatus.gainPercentage = rxMsg.arg2; 
                    VOL_cellControl( hCell, IVOL_SETSTATUS, 
                                     (IALG_Status *)&volStatus );
                }
                break;

            case MSGNEWCOEFF:
                {
                    IFIR_Status firStatus;
                    Short *coeffPtr;

                    /* pick the right set of coefficients, use arg2 as index */
                    UTL_assert( rxMsg.arg2 <= 2 );
                    coeffPtr = filterCoeffList[ rxMsg.arg2 ];

                    /* get handle for channel chanNum's FIR cell */
                    hCell = &thrProcess.cellList[CELLFIR + chanNum * NUMCELLS];
                    UTL_assert( hCell != NULL );

                    /* 
                     *  get current contents of the control structure 
                     *  to avoid overriding non-modified ones 
                     */
                    FIR_cellControl( hCell, IFIR_GETSTATUS, 
                                     (IALG_Status *)&firStatus );
                    firStatus.coeffPtr  = coeffPtr; 
                    FIR_cellControl( hCell, IFIR_SETSTATUS, 
                                     (IALG_Status *)&firStatus );
                }
                break;

            default:
                break;
        }
    }
}


/*
 *  ======== thrProcessRun ========
 *
 *  Main function of the Process thread.
 */
Void thrProcessRun()
{
    Int i, chanNum;
    Bool rc;    

    /* open SCOM queues for sending messages to RxSplit and TxJoin tasks */
    SCOM_Handle scomReceiveFromRx = SCOM_open( "scomToProcessFromRx");
    SCOM_Handle scomReceiveFromTx = SCOM_open( "scomToProcessFromTx");
    SCOM_Handle scomSendToRx      = SCOM_open( "scomRxSplit" );
    SCOM_Handle scomSendToTx      = SCOM_open( "scomTxJoin"  );

    UTL_assert( scomReceiveFromRx != NULL );
    UTL_assert( scomReceiveFromTx != NULL );
    UTL_assert( scomSendToRx      != NULL );
    UTL_assert( scomSendToTx      != NULL );

    // Fill in the SCOM messages
    for (i = 0; i < NUMCHANNELS; i++) {
        thrProcess.scomMsgRx.bufChannel[i] = thrProcess.bufInput[i];
        thrProcess.scomMsgTx.bufChannel[i] = thrProcess.bufOutput[i];
    }

    // put the Rx message on the SCOM queue for RxSplit thread
    SCOM_putMsg( scomSendToRx, &(thrProcess.scomMsgRx) );

    // put the Tx message on the queue to yourself, i.e. from TxJoin thread
    SCOM_putMsg( scomReceiveFromTx, &(thrProcess.scomMsgTx) );

    // Main loop
    while (TRUE) {
        ScomBufChannels *scomMsgRx, *scomMsgTx;

        // check for control (MBX) messages (not to be confused with SCOM msgs)
        checkMsg();

        // get the message describing full input buffers from Rx
        scomMsgRx = (ScomBufChannels *)SCOM_getMsg( scomReceiveFromRx, 
            SYS_FOREVER );

        // get the message describing empty output buffers from Tx
        scomMsgTx = (ScomBufChannels *)SCOM_getMsg( scomReceiveFromTx, 
            SYS_FOREVER );

        // record the time period between two frames of data in stsTime0
        UTL_stsPeriod( stsTime0 );

        // process the data
        for( chanNum = 0; chanNum < NUMCHANNELS; chanNum++ ) {

            CHAN_Handle chanHandle = &thrProcess.chanList[ chanNum ];

            // Set the input ICC buffer for FIR cell for each channel
            ICC_setBuf(chanHandle->cellSet[CELLFIR].inputIcc[0],
                       scomMsgRx->bufChannel[chanNum], 
                       FRAMELEN * sizeof( Sample ) );

            // Set the output ICC buffer for VOL cell for each channel
            ICC_setBuf(chanHandle->cellSet[CELLVOL].outputIcc[0],
                       scomMsgTx->bufChannel[chanNum], 
                       FRAMELEN * sizeof( Sample ) );

            // execute the channel 
            UTL_stsStart( stsTime1 );  // start the stopwatch
            rc = CHAN_execute( chanHandle, NULL );
            UTL_assert( rc == TRUE );
            UTL_stsStop( stsTime1 );   // elapsed time goes to this STS 
        }
        
        // send the message describing full output buffers to Tx
        SCOM_putMsg( scomSendToTx, scomMsgTx );
        
        // send the message describing consumed input buffers to Rx
        SCOM_putMsg( scomSendToRx, scomMsgRx );
    }
}

⌨️ 快捷键说明

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