For BU9480F D-A Conv.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lynxeyed_atsu
Date:
Fri Sep 03 08:01:53 2010 +0000
Parent:
0:805cffac956b
Child:
2:baf5bf51cd28
Commit message:

Changed in this revision

_bitio.cpp Show annotated file Show diff for this revision Revisions of this file
_bitio.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/_bitio.cpp	Thu Aug 26 12:48:50 2010 +0000
+++ b/_bitio.cpp	Fri Sep 03 08:01:53 2010 +0000
@@ -3,15 +3,6 @@
 #include "_bitio.h"
 
 
-/*
-#define TRUE     1
-#define FALSE    0
-*/
-#define rightbits(n, x) ((x) & ((1U << (n)) - 1U))  
-/*
-typedef unsigned int  Uint;
-typedef unsigned char Uchar;
-*/
 FILE *infp, *outfp;
 int  getcount, putcount;
 Uint bitbuf;
--- a/_bitio.h	Thu Aug 26 12:48:50 2010 +0000
+++ b/_bitio.h	Fri Sep 03 08:01:53 2010 +0000
@@ -1,8 +1,9 @@
 #ifndef    ___BITIO_H__
 #define    ___BITIO_H__
-
+/*
 #define TRUE     1
 #define FALSE    0
+*/
 #define rightbits(n, x) ((x) & ((1U << (n)) - 1U)) 
 
 #define OVERRUN 0xffff
--- 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);
+}
+