Last active
August 29, 2015 14:06
-
-
Save jeremywrnr/1769b74f8f6a1ebcd30d to your computer and use it in GitHub Desktop.
discrete differential equations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DSP_Config.h" | |
#include "filter.h" | |
#define LEFT 0 | |
#define RIGHT 1 | |
// used for array length (bound defined) | |
#define N 4 | |
#define M 4 | |
volatile union { | |
Uint32 UINT; | |
Int16 Channel[2]; | |
} CodecDataIn, CodecDataOut; | |
/* add any global variables here */ | |
//audio signal storage | |
static int xPointer = 0; | |
static int yPointer = 0; | |
static float xLIn[M+1], xRIn[M+1]; | |
static float yLOut[N+1], yROut[N+1]; | |
// note: leftmost value allocated to x0,y1... | |
static const float a[5] = {1.0, 0.0, 0.0, 0.0, 0.0}; | |
static const float b[5] = {1.0, 0.5, 0.25, 0.125, 0.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, tempAddL, tempSubL, tempAddR, tempSubR; | |
// input location | |
int mIndex = M; | |
int xPos = xPointer; | |
// output location | |
int nIndex = N; | |
int yPos = yPointer; | |
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 */ | |
//take in codec data | |
xLeft = CodecDataIn.Channel[ LEFT]; | |
xRight = CodecDataIn.Channel[ RIGHT]; | |
xLIn[xPointer] = xLeft; | |
xRIn[xPointer] = xRight; | |
//updating input (x) buffer | |
tempAddL = 0; | |
tempAddR = 0; | |
for( mIndex = 0; mIndex <= M; mIndex++ ) | |
{ | |
if(xPos == M) xPos = 0; | |
tempAddL = tempAddL + (b[mIndex] * xLIn[xPos]); | |
tempAddR = tempAddR + (b[mIndex] * xRIn[xPos]); | |
xPos++; | |
} | |
//updating output (y) buffer | |
tempSubL = 0; | |
tempSubR = 0; | |
for( nIndex = 0; nIndex <= N; nIndex++ ) | |
{ | |
if(yPos == N) yPos = 0; | |
tempSubL = tempSubL + (a[nIndex] * yLOut[yPos]); | |
tempSubR = tempSubR + (a[nIndex] * yROut[yPos]); | |
yPos++; | |
} | |
//assign difference to y[0] index | |
yLOut[yPointer] = tempAddL - tempSubL; | |
yROut[yPointer] = tempAddR - tempSubR; | |
//rout to output | |
CodecDataOut.Channel[ LEFT] = tempAddL; | |
CodecDataOut.Channel[RIGHT] = tempAddR; | |
//CodecDataOut.Channel[ LEFT] = yLOut[yPointer]; | |
//CodecDataOut.Channel[RIGHT] = yROut[yPointer]; | |
WriteCodecData(CodecDataOut.UINT); // send output data to port | |
if(xPointer == M) { | |
xPointer = 0; | |
}else xPointer++; | |
if(yPointer == N) { | |
yPointer = 0; | |
}else yPointer++; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment