Hi all,
Can you help me figure out how to include previous samples in FIR filter. According to the TMS320C67x DSP Library Programmers Ref. Guide SPRU657C, the input array starts at x(-nh+1) and ends at x(nr-1).
To test the filter, I'm using the mcaspPlayBk.c from the StarterWare C6748_StarterWare_1_20_04_01.
To construct the input array for the FIR filter, I'm increasing the buffer size from its default of 2000 samples to 2015 for a 16-tap filter. The problem I have (I think) is that I don't know how to insert (nh-1) previous samples to the head of buffer. Since the data comes in frames, I'm trying to save the last (nh-1) sample from the previous frame then using them in the "current" frame. But this isn't working.
Here is my code, which is modified version of mcaspPlayBk.c:
while(1) { if(lastFullRxBuf != lastSentTxBuf) { /* ** Start the transmission from the link paramset. The param set ** 1 will be linked to param set at PAR_TX_START. So do not ** update paRAM set1. */ parToSend = PAR_TX_START + (parOffTxToSend % NUM_PAR); parOffTxToSend = (parOffTxToSend + 1) % NUM_PAR; parToLink = PAR_TX_START + parOffTxToSend; lastSentTxBuf = (lastSentTxBuf + 1) % NUM_BUF; // is this necessary? memcpy(tempCharBuf, (void *)rxBufPtr[lastFullRxBuf], AUDIO_BUF_SIZE); /* **convert char array to short signed int array starting at NH */ unpackMcASPBuf(tempCharBuf, NUM_SAMPLES_PER_AUDIO_BUF, NH, singleChannelInt); counter++; //for debugging /* ** insert previous samples to front of rx frame buffer for FIR filter */ insertPrevSamples(singleChannelInt, previousSamples, NH); /* ** save trailing NH samples for next frame */ saveTrailingSamples(singleChannelInt, NUM_SAMPLES_PER_AUDIO_BUF, previousSamples, NH); /* ** convert to sp float for FIR filter */ intToFloat(singleChannelInt, NUM_SAMPLES_PER_AUDIO_BUF + NH, DSPInputSignal); /* **FIR filter */ DSPF_sp_fir_gen(DSPInputSignal, filterCoefs, DSPOutputSignal, NH, NUM_SAMPLES_PER_AUDIO_BUF ); /* ** convert back to int for txBuf */ floatToInt(DSPOutputSignal, NUM_SAMPLES_PER_AUDIO_BUF, tempIntBuf); /* ** interleave back into txBuf short int to char conversion */ packMcASPBuf(tempIntBuf, NUM_SAMPLES_PER_AUDIO_BUF, tempCharBuf); memcpy((void *)txBufPtr[lastSentTxBuf], tempCharBuf, AUDIO_BUF_SIZE); /* ** Send the buffer by setting the DMA params accordingly. ** Here the buffer to send and number of samples are passed as ** parameters. This is important, if only transmit section ** is to be used. */ BufferTxDMAActivate(lastSentTxBuf, NUM_SAMPLES_PER_AUDIO_BUF, } }
The functions are:
void insertPrevSamples(short signed int* x, short signed int* p, int np){ //p = previous int i=0; for(i= 0; i < np - 1 ; ++i) x[i] = p[i]; } void saveTrailingSamples(short signed int* x, int nx, short signed int* p, int np){ //p = previous int i=0; for(i= 0; i < np - 1; i++) p[i] = x[nx + i]; }
void unpackMcASPBuf(unsigned char* x, int nx, int nh, short signed int* y){ int i=0; int indx=0; for(i = nh; i < nx + nh; i++){ y[i] = x[indx+1] << 8; y[i] |= x[indx+0] << 0; indx += 8; } } void packMcASPBuf(short int* in, int size, unsigned char* out){ int i=0; int indx=0; int byte0; int byte1; int byte4; int byte5; for(i=0; i< size/2; i++){ out[indx+2] = 0; out[indx+3] = 0; out[indx+6] = 0; out[indx+7] = 0; byte0 = ( in[i] >> 0 ); byte1 = ( in[i] >> 8 ); byte4 = ( in[i] >> 16 ); byte5 = ( in[i] >> 24 ); out[indx+0] = (char)byte0; out[indx+1] = (char)byte1; out[indx+4] = (char)byte4; out[indx+5] = (char)byte5; indx += 8; } }
Also included is a waveform showing the corrupted nh-1 samples at the head of the buffer.
I hope this makes sense and sorry for the lengthy explanation and code.
thank you,
Scott