Music Visualizer / Mbed 2 deprecated 4180FinalProject

Dependencies:   mbed SDFileSystem NeoStrip PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wave_player.h Source File

wave_player.h

00001 #include <mbed.h>
00002 
00003 typedef struct uFMT_STRUCT {
00004   short comp_code;
00005   short num_channels;
00006   unsigned sample_rate;
00007   unsigned avg_Bps;
00008   short block_align;
00009   short sig_bps;
00010 } FMT_STRUCT;
00011 
00012 
00013 /** wave file player class.
00014  *
00015  * Example:
00016  * @code
00017  * #include <mbed.h>
00018  * #include <wave_player.h>
00019  *
00020  * AnalogOut DACout(p18);
00021  * wave_player waver(&DACout);
00022  *
00023  * int main() {
00024  *  FILE *wave_file;
00025  *  
00026  *  printf("\n\n\nHello, wave world!\n");
00027  *  wave_file=fopen("/sd/44_8_st.wav","r");
00028  *  waver.play(wave_file);
00029  *  fclose(wave_file); 
00030  * }
00031  * @endcode
00032  */
00033 class wave_player {
00034 
00035 public:
00036 /** Create a wave player using a pointer to the given AnalogOut object.
00037  *
00038  * @param _dac pointer to an AnalogOut object to which the samples are sent.
00039  */
00040 wave_player(AnalogOut *_dac);
00041 
00042 /** the player function.
00043  *
00044  * @param wavefile  A pointer to an opened wave file
00045  */
00046 void play(FILE *wavefile);
00047 
00048 /** Set the printf verbosity of the wave player.  A nonzero verbosity level
00049  * will put wave_player in a mode where the complete contents of the wave
00050  * file are echoed to the screen, including header values, and including
00051  * all of the sample values placed into the DAC FIFO, and the sample values
00052  * removed from the DAC FIFO by the ISR.  The sample output frequency is
00053  * fixed at 2 Hz in this mode, so it's all very slow and the DAC output isn't
00054  * very useful, but it lets you see what's going on and may help for debugging
00055  * wave files that don't play correctly.
00056  *
00057  * @param v the verbosity level
00058  */
00059 void set_verbosity(int v);
00060 
00061 /**
00062  * Changes the playing state of the wave player
00063  * 0 = stop playiny (ends wave player)
00064  * 1 = continues playing the song
00065  * 2 = pauses the song
00066  */
00067 void set_play_state(int p);
00068 int get_play_state();
00069 
00070 public:
00071 void dac_out(void);
00072 int verbosity;
00073 AnalogOut *wave_DAC;
00074 Ticker tick;
00075 unsigned short DAC_fifo[256];
00076 unsigned short DAC_fifo2[256];
00077 short DAC_wptr;
00078 volatile short DAC_rptr;
00079 short DAC_on;
00080 int play_state;
00081 
00082 short unsigned dac_data;
00083 };
00084 
00085 
00086