xeye_ atsu
/
RiceGolombDPCM_Player
For BU9480F D-A Conv.
Diff: main.cpp
- Revision:
- 1:02bfb013660c
- Parent:
- 0:805cffac956b
- Child:
- 2:baf5bf51cd28
--- a/main.cpp Thu Aug 26 12:48:50 2010 +0000 +++ b/main.cpp Fri Sep 03 08:01:53 2010 +0000 @@ -1,57 +1,33 @@ /* DPCM & Rice Golomb Lossless Audio Player and Realtime encoder */ +#include "SDHCFileSystem.h" + #include "mbed.h" #include "string" -#include "SDHCFileSystem.h" + #include "_bitio.h" //FILE *infp,*outfp; -SDFileSystem sd(p11, p12, p13, p14, "sd"); +SDFileSystem sd(p5, p6, p7, p8, "sd"); DigitalOut led1(LED1); DigitalOut led2(LED2); AnalogOut DACout(p18); Ticker tick; // a FIFO for the DAC -volatile short DAC_fifo[1024]; +#define RAM_LENGTH 4096 +#define RAM_LIMIT (RAM_LENGTH - 1) +volatile short DAC_fifo[RAM_LENGTH]; volatile short DAC_wptr=0; volatile short DAC_rptr=0; volatile short DAC_on; volatile short int DAC_diff=0; - -void encode(long int n); -void decode(void); -void dac_out(); - - - - -int main() { - - - if ( NULL == (infp = fopen( "/sd/test.rgm", "rb" )) ) { - printf( "\r\nError: The message file cannot be accessed\r\n" ); - return -1; - } - //tick.detach(); - tick.attach_us(&dac_out, 45); //set 22.050kHz sampling data - decode(); - tick.detach(); - - fclose( infp ); - //fclose( outfp ); - - - - while (1); -} - void dac_out() { // printf("\t%d\r\n",DAC_diff); if (DAC_diff > 0) { led2 = 0; DACout.write_u16(DAC_fifo[DAC_rptr]); - DAC_rptr=(DAC_rptr+1) & 0x3ff; + DAC_rptr=(DAC_rptr+1) & (RAM_LIMIT); DAC_diff--; }else led2 = 1; } @@ -107,9 +83,9 @@ dac_data = ((int)diff + 32768) >> 1; DAC_fifo[DAC_wptr]=dac_data; - DAC_wptr=(DAC_wptr+1) & 0x3ff; + DAC_wptr=(DAC_wptr+1) & (RAM_LIMIT); DAC_diff=(DAC_diff+1); - while (DAC_diff >= 1023){ + while (DAC_diff > RAM_LIMIT){ led1 = 1; } //wait led1=0; @@ -139,3 +115,25 @@ } } + + +int main() { + + + if ( NULL == (infp = fopen( "/sd/test.rgm", "rb" )) ) { + printf( "\r\nError: The message file cannot be accessed\r\n" ); + return -1; + } + //tick.detach(); + tick.attach_us(&dac_out, 45); //set 22.050kHz sampling data + decode(); + tick.detach(); + + fclose( infp ); + //fclose( outfp ); + + + + while (1); +} +