Esempio n. 1
0
interrupt void Codec_ISR()
///////////////////////////////////////////////////////////////////////
// Purpose:   Codec interface interrupt service routine  
//
// Input:     None
//
// Returns:   Nothing
//
// Calls:     CheckForOverrun, ReadCodecData, WriteCodecData
//
// Notes:     None
///////////////////////////////////////////////////////////////////////
{                    
	/* add any local variables here */
    static Uint8 fill_index = INITIAL_FILL_INDEX; // index of buffer to fill
    static Uint8 dump_index = INITIAL_DUMP_INDEX; // index of buffer to dump
    static Uint32 sample_count = 0; // current sample count in buffer

 	if(CheckForOverrun())					// overrun error occurred (i.e. halted DSP)
		return;								// so serial port is reset to recover

  	CodecDataIn.UINT = ReadCodecData();		// get input data samples
	
	/* add your code starting here */

    // store input in buffer
    buffer[fill_index][ LEFT][sample_count] = CodecDataIn.Channel[ LEFT];
    buffer[fill_index][RIGHT][sample_count] = CodecDataIn.Channel[RIGHT];
    
 	// bound output data before packing
	// use saturation of SPINT to limit to 16-bits
	CodecDataOut.Channel[ LEFT] = _spint(buffer[dump_index][ LEFT][sample_count] * 65536) >> 16;
	CodecDataOut.Channel[RIGHT] = _spint(buffer[dump_index][RIGHT][sample_count] * 65536) >> 16;
    // pack output data without bounding 
//  CodecDataOut.channel[ LEFT] = buffer[dump_index][LEFT][sample_count];
//  CodecDataOut.channel[RIGHT] = buffer[dump_index][RIGHT][sample_count];

   // update sample count and swap buffers when filled 
    if(++sample_count >= BUFFER_LENGTH) {
        sample_count = 0;
        ready_index = fill_index;
        if(++fill_index >= NUM_BUFFERS)
            fill_index = 0;
        if(++dump_index >= NUM_BUFFERS)
            dump_index = 0;
        if(buffer_ready == 1) // set a flag if buffer isn't processed in time 
            over_run = 1;
        buffer_ready = 1;
    }


	/* end your code here */

	WriteCodecData(CodecDataOut.UINT);		// send output data to  port
}
Esempio n. 2
0
interrupt void Codec_ISR()
///////////////////////////////////////////////////////////////////////
// Purpose:   Codec interface interrupt service routine  
//
// Input:     None
//
// Returns:   Nothing
//
// Calls:     CheckForOverrun, ReadCodecData, WriteCodecData
//
// Notes:     None
///////////////////////////////////////////////////////////////////////
{                    
	/* add any local variables here */
	float output; //, *p;
	int indLeft, indRight;

 	if(CheckForOverrun())					// overrun error occurred (i.e. halted DSP)
		return;								// so serial port is reset to recover

  	CodecDataIn.UINT = ReadCodecData();		// get input data samples
	
	/* I added my mono FIR filter routine here */
  	xLeft[sampleInd] = CodecDataIn.Channel[LEFT];

	output = 0;								// set up for LEFT channel
	indLeft = sampleInd;
	indRight = sampleInd + 1;
	if(++sampleInd > N)
		sampleInd = 0;
	if(indRight > N)
		indRight = 0;
	for (i = 0; i < (N+1)/2; i++) {				// do LEFT channel FIR
			output += ( ( xLeft[indLeft--] * B[i] ) + ( xLeft[indRight++] * B[i] ) );
			if(indLeft < 0)
				indLeft = N;
			if(indRight > N)
				indRight = 0;
	}

	if( ( N % 2 ) == 0 )
	{
		output += ( xLeft[ indLeft-- ] * B[ ( N/2 )] );
	}

	CodecDataOut.Channel[LEFT]  = output; // store filtered value		
	CodecDataOut.Channel[RIGHT] = output; // store filtered value	
	/* end of my mono FIR filter routine */	

	WriteCodecData(CodecDataOut.UINT);		// send output data to  port
}
Esempio n. 3
0
interrupt void Codec_ISR()
///////////////////////////////////////////////////////////////////////
// Purpose:   Codec interface interrupt service routine  
//
// Input:     None
//
// Returns:   Nothing
//
// Calls:     CheckForOverrun, ReadCodecData, WriteCodecData
//
// Notes:     None
///////////////////////////////////////////////////////////////////////
{                    
	/* add any local variables here */
    int sTemp;
    float left = 0.0f;
    float right = 0.0f;
    float out = 0.0f;
    float currentIn = 0.0f;

 	if(CheckForOverrun())					// overrun error occurred (i.e. halted DSP)
		return;								// so serial port is reset to recover

  	CodecDataIn.UINT = ReadCodecData();		// get input data samples
  	currentIn = CodecDataIn.Channel[LEFT];
  	delayed[0] = currentIn;

  	left = delayed[0];

  	for(i = 1; i < N; i++)
  	{
  		left -= (A[i] * delayed[i]);
  	}

  	delayed[0] = left;

  	for(i = 0; i < N; i++)
  	{
  		right += ( B[i] * delayed[i] );
  	}

  	for(i = N; i > 0; i--)
  		delayed[i] = delayed[i-1];

  	CodecDataOut.Channel[LEFT] = right;

	WriteCodecData(CodecDataOut.UINT);		// send output data to  port

	return;
}
Esempio n. 4
0
interrupt void Codec_ISR()
///////////////////////////////////////////////////////////////////////
// Purpose:   Codec interface interrupt service routine  
//
// Input:     None
//
// Returns:   Nothing
//
// Calls:     CheckForOverrun, ReadCodecData, WriteCodecData
//
// Notes:     None
///////////////////////////////////////////////////////////////////////
{                    
	/* add any local variables here */
	float xLeft, xRight, yLeft, yRight;


 	if(CheckForOverrun())					// overrun error occurred (i.e. halted DSP)
		return;								// so serial port is reset to recover

  	CodecDataIn.UINT = ReadCodecData();		// get input data samples
	
	/* add your code starting here */

	// this example simply copies sample data from in to out
	xLeft  = CodecDataIn.Channel[ LEFT];
	xRight = CodecDataIn.Channel[ RIGHT];

	yLeft  = xLeft;
	yRight = xRight;

	CodecDataOut.Channel[ LEFT] = yLeft;
	CodecDataOut.Channel[RIGHT] = yRight;

	/* end your code here */

	WriteCodecData(CodecDataOut.UINT);		// send output data to  port
}
interrupt void Codec_ISR()
///////////////////////////////////////////////////////////////////////
// Purpose:   Codec interface interrupt service routine  
//
// Input:     None
//
// Returns:   Nothing
//
// Calls:     CheckForOverrun, ReadCodecData, WriteCodecData
//
// Notes:     None
///////////////////////////////////////////////////////////////////////
{                    
	/* add any local variables here */
	Int32 symbol;
	Int32 i;

 	if(CheckForOverrun())					// overrun error occurred (i.e. halted DSP)
		return;								// so serial port is reset to recover

  	CodecDataIn.UINT = ReadCodecData();		// get input data samples
	
	/* add your code starting here */

	// I added my impulse modulated, QPSK routine here
	if (counter == 0) {
		symbol = rand() & 3; /* generate 2 random bits */
		xI[0]  = QPSK_LUT[symbol][RIGHT];  // lookup the I symbol
		xQ[0]  = QPSK_LUT[symbol][ LEFT];  // lookup the Q symbol
	}

	output = 0;
	switch(counter & 3) {
	case  0: // perform the I impulse modulation based on the FIR filter, B[N] 
		for (i = 0; i < 6; i++) {
			output += xI[i]*B[counter + 20*i]; // perform the "I" dot-product
		}
		break;
	case 1: // perform the Q impulse modulation based on the FIR filter, B[N] 
		for (i = 0; i < 6; i++) {
			output -= xQ[i]*B[counter + 20*i]; // perform the "Q" dot-product
		}
		break;
	case 2: // perform the -I impulse modulation based on the FIR filter, B[N] 
		for (i = 0; i < 6; i++) {
			output -= xI[i]*B[counter + 20*i]; // perform the "-I" dot-product
		}
		break;
	default: // perform the -Q impulse modulation based on the FIR filter, B[N] 
		for (i = 0; i < 6; i++) {
			output += xQ[i]*B[counter + 20*i]; // perform the "-Q" dot-product
		}
		break;
	}
	if (counter == (samplesPerSymbol - 2)) {
		/* shift xI[] in preparation to receive the next I input */
		for (i = 5; i > 0; i--) {
			xI[i] = xI[i-1];  // setup xI[] for the next input value
		}
	}
	else if (counter >= (samplesPerSymbol - 1)) {
		counter = -1;  // reset in preparation for the next set of bits
		/* shift xQ[] in preparation to receive the next Q input */
		for (i = 5; i > 0; i--) {
			xQ[i] = xQ[i-1];  // setup xQ[] for the next input value
		}
	}

	counter++;

	CodecDataOut.Channel[LEFT]  = output_gain*output; // setup the LEFT output value	
	CodecDataOut.Channel[RIGHT] = CodecDataOut.Channel[LEFT]; // copy to RIGHT
    // end of my impulse modulated, QPSK routine here

	/* end your code here */

	WriteCodecData(CodecDataOut.UINT);		// send output data to  port
}