Created
May 29, 2013 20:16
-
-
Save aeickho/5673476 to your computer and use it in GitHub Desktop.
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
void playWav(char* filename, float samplerate) | |
{ | |
int fp= STDIN_FILENO; | |
if(filename[0]!='-') fp = open(filename, 'r'); | |
//int sz = lseek(fp, 0L, SEEK_END); | |
//lseek(fp, 0L, SEEK_SET); | |
//short* data = (short*)malloc(sz); | |
//read(fp, data, sz); | |
int bufPtr=0; | |
float datanew, dataold = 0; | |
short data; | |
for (int i=0; i<22; i++) | |
read(fp, &data, 2); // read past header | |
while (read(fp, &data, 2)) { | |
float fmconstant = samplerate * 50.0e-6; // for pre-emphisis filter. 50us time constant | |
int clocksPerSample = 22500.0/samplerate*1400.0; // for timing | |
datanew = (float)(data)/32767; | |
float sample = datanew + (dataold-datanew) / (1-fmconstant); // fir of 1 + s tau | |
sample = datanew; | |
float dval = sample*2; // actual transmitted sample. 15 is bandwidth (about 75 kHz) | |
int intval = (int)(round(dval)); // integer component | |
float frac = (dval - (float)intval)/2 + 0.5; | |
unsigned int fracval = frac*clocksPerSample; | |
// if (intval < 3) printf("%d %d\n",intval, fracval); | |
bufPtr++; | |
while( ACCESS(DMABASE + 0x04 /* CurBlock*/) == (int)(instrs[bufPtr].p)) usleep(1000); | |
((struct CB*)(instrs[bufPtr].v))->SOURCE_AD = (int)constPage.p + 2048 + intval*4 - 4 ; | |
bufPtr++; | |
while( ACCESS(DMABASE + 0x04 /* CurBlock*/) == (int)(instrs[bufPtr].p)) usleep(1000); | |
((struct CB*)(instrs[bufPtr].v))->TXFR_LEN = clocksPerSample-fracval; | |
bufPtr++; | |
while( ACCESS(DMABASE + 0x04 /* CurBlock*/) == (int)(instrs[bufPtr].p)) usleep(1000); | |
((struct CB*)(instrs[bufPtr].v))->SOURCE_AD = (int)constPage.p + 2048 + intval*4+4; | |
bufPtr=(bufPtr+1) % (1024); | |
while( ACCESS(DMABASE + 0x04 /* CurBlock*/) == (int)(instrs[bufPtr].p)) usleep(1000); | |
((struct CB*)(instrs[bufPtr].v))->TXFR_LEN = fracval; | |
dataold = datanew; | |
} | |
close(fp); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment