music main

Dependencies:   USBHost mbed

Fork of AppBoard_Waveplayer by jim hamblen

main.cpp

Committer:
niv17
Date:
2015-04-09
Revision:
10:6eefc37bfa23
Parent:
9:f1aebfbe7e78
Child:
11:e48cb1e38995

File content as of revision 10:6eefc37bfa23:

#include "mbed.h"
#include "USBHostMSD.h"
#include "wave_player.h"
#include "MMA7660.h"
#include "rtos.h"

//mbed Application board waveplayer demo
//Plays the wave file "sample.wav" on the USB flash drive
//Outputs to onboard speaker (but at very low volume)
//and the Audio Out jack for connection to a set of amplified PC speakers (at higher volume)
//Needs a USB flash drive inserted with the wav file on it to run

//Analog Out Jack
AnalogOut DACout(p18);
//On Board Speaker
PwmOut PWMout(p26);
int music = 0;
void readbuf();
Serial pc(USBTX,USBRX);
MMA7660 MMA(p28, p27);
AnalogIn sound(p17);
PwmOut r (p23);
PwmOut g (p24);
PwmOut b (p25);
 FILE *wave_file;
 void readbuf(void const *args);
 unsigned short * waveArray;
 DigitalIn fire(p14);
 void changemusic(void const *args);
 void changecolor(void const *args);
 int randomval = 0;
 int start = 0;
 Ticker fillbuf;
unsigned short * buf;
 wave_player waver(&DACout,&PWMout, &waveArray[0]);
int main()
{
    USBHostMSD msd("usb");
   // for(int i = 0; i<256; i++)
//        { 
//       waveArray[i] = 0;
//        }
    
    r.period(0.001);
    //setup PWM hardware for a Class D style audio output
    PWMout.period(1.0/400000.0);
    printf("\r\n\nHello, wave world!\n");
    // wait until connected to a USB device
    while(!msd.connect()) {
        Thread::wait(500);
    }
    //open wav file and play it

     
      pc.printf("\r\nenter wavefile\n\n"); 
      wave_file =  fopen("/usb/sample.wav","r");
      
     // waver.set_verbosity(1);
    Thread thread(readbuf);
      waver.play(wave_file);
      
    fclose(wave_file);
       
       pc.printf("\r\n END OF FILE\n");
        pc.printf("\r\n\n BUFFER:::\n");
       
         
    
   while(1);
   
}
void readbuf(void const * args){
   
    while(1){
         wait_ms(11.0);
   
    waver.getFIFO(buf);
    
    //for(int i = 0; i<256; i++) {
//       printf("%hu\r\n",buf[i]); 
//       }
   }
    
}