For BU9480F D-A Conv.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lynxeyed_atsu
Date:
Sat Sep 11 11:23:26 2010 +0000
Parent:
2:baf5bf51cd28
Commit message:

Changed in this revision

SDHCFileSystem.cpp 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
diff -r baf5bf51cd28 -r 64c3ed0fc4b4 SDHCFileSystem.cpp
--- a/SDHCFileSystem.cpp	Fri Sep 03 08:21:29 2010 +0000
+++ b/SDHCFileSystem.cpp	Sat Sep 11 11:23:26 2010 +0000
@@ -227,7 +227,7 @@
         return 1;
     }
         
-    _spi.frequency(1000000); // Set to 1MHz for data transfer
+    _spi.frequency(25000000/*1000000*/); // Set to 1MHz for data transfer
     return 0;
 }
 
diff -r baf5bf51cd28 -r 64c3ed0fc4b4 main.cpp
--- a/main.cpp	Fri Sep 03 08:21:29 2010 +0000
+++ b/main.cpp	Sat Sep 11 11:23:26 2010 +0000
@@ -1,10 +1,9 @@
 /* DPCM & Rice Golomb Lossless Audio Player and Realtime encoder */
 #include "SDHCFileSystem.h"
-
 #include "mbed.h"
 #include "string"
+#include "_bitio.h"
 
-#include "_bitio.h"
 //FILE    *infp,*outfp;
 SDFileSystem sd(p5, p6, p7, p8, "sd");
 DigitalOut led1(LED1);
@@ -12,25 +11,41 @@
 AnalogOut DACout(p18);
 Ticker tick;
 
+// BU9480F define
+SPI bu9480f(p11,p12,p13);
+DigitalOut LRCLK(p14);
+// BU9480F define.end
+
+
 // a FIFO for the DAC
-#define RAM_LENGTH 4096//8192
+#define TXFIFO_FULL 1
+#define RAM_LENGTH 8192//8192
 #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;
+volatile short DAC_diff=0;
 
 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) & (RAM_LIMIT);
-        DAC_diff--;
+    if (DAC_diff > 1) {
+        led2 = 0;        
+        
+        LRCLK = 0;
+        bu9480f.write(DAC_fifo[DAC_rptr++]);
+        DAC_rptr &= RAM_LIMIT;
+        
+        LRCLK = 1;
+        bu9480f.write(DAC_fifo[DAC_rptr++]);
+        DAC_rptr &= RAM_LIMIT;
+        
+        DAC_diff-=2;
+        
    }else led2 = 1;
 }
+
 void encode(long int n){
     int zero_shift = 0;
     
@@ -59,12 +74,12 @@
 
 
 void decode(void){
-    short dac_data;
+    //short dac_data;
     long int decode_buff;
     short diff,diff2;
     unsigned int buff_sign,zero_shift;
     //char flag;
-
+    
     diff = 0;
     diff2 = 0;
     // get sign(1 for positive, 0 for negative)
@@ -80,19 +95,13 @@
         if(!buff_sign)decode_buff =- decode_buff;
         /* return decode_buff; */
         diff =(diff + decode_buff);
-        
-        dac_data = ((int)diff + 32768) >> 1;
-        DAC_fifo[DAC_wptr]=dac_data;
-        DAC_wptr=(DAC_wptr+1) & (RAM_LIMIT);
-        DAC_diff=(DAC_diff+1);
+        DAC_fifo[DAC_wptr++]=(short)diff;
+        DAC_wptr &= RAM_LIMIT;
+        //DAC_diff++;
         while (DAC_diff > RAM_LIMIT){
             led1 = 1;
         }   //wait
         led1=0;
-        if(DAC_diff <= 0)
-            led2=1;
-        else led2=0;
- 
         
         if((buff_sign = getbit())==OVERRUN)break;
         zero_shift = 0;
@@ -105,11 +114,14 @@
         /* return decode_buff; */
         diff2 =(diff2 + decode_buff);
 
-       /* 
-        drawc((unsigned char)diff2 & 0xff);
-        drawc((unsigned char)((diff2>>8) &0xff));
-        */
-        //fwrite(&diff2, sizeof(short int), 1, outfp);
+        DAC_fifo[DAC_wptr++]=(short)diff2;
+        DAC_wptr &= RAM_LIMIT;
+        DAC_diff+=2;
+        
+        while (DAC_diff > RAM_LIMIT){
+            led1 = 1;
+        }   //wait
+        led1=0;
         
     
          
@@ -124,8 +136,13 @@
         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    
+    // bu9480f init
+    bu9480f.format(16,0);
+    bu9480f.frequency(16000000); //16MHz
+    // bu9480f init.end
+    
+      
+    tick.attach_us(&dac_out, 41); //set 24.000kHz sampling data   
     decode();
     tick.detach();