hw

Dependents:   wave_player_mp3 4180_lab2_part9 4180_Lab3_rtos_basic PianoTiles

Committer:
zchen311
Date:
Sun Jul 14 20:29:36 2013 +0000
Revision:
0:353c78110e44
done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zchen311 0:353c78110e44 1 #include <mbed.h>
zchen311 0:353c78110e44 2
zchen311 0:353c78110e44 3 typedef struct uFMT_STRUCT {
zchen311 0:353c78110e44 4 short comp_code;
zchen311 0:353c78110e44 5 short num_channels;
zchen311 0:353c78110e44 6 unsigned sample_rate;
zchen311 0:353c78110e44 7 unsigned avg_Bps;
zchen311 0:353c78110e44 8 short block_align;
zchen311 0:353c78110e44 9 short sig_bps;
zchen311 0:353c78110e44 10 } FMT_STRUCT;
zchen311 0:353c78110e44 11
zchen311 0:353c78110e44 12
zchen311 0:353c78110e44 13 /** wave file player class.
zchen311 0:353c78110e44 14 *
zchen311 0:353c78110e44 15 * Example:
zchen311 0:353c78110e44 16 * @code
zchen311 0:353c78110e44 17 * #include <mbed.h>
zchen311 0:353c78110e44 18 * #include <wave_player.h>
zchen311 0:353c78110e44 19 *
zchen311 0:353c78110e44 20 * AnalogOut DACout(p18);
zchen311 0:353c78110e44 21 * wave_player waver(&DACout);
zchen311 0:353c78110e44 22 *
zchen311 0:353c78110e44 23 * int main() {
zchen311 0:353c78110e44 24 * FILE *wave_file;
zchen311 0:353c78110e44 25 *
zchen311 0:353c78110e44 26 * printf("\n\n\nHello, wave world!\n");
zchen311 0:353c78110e44 27 * wave_file=fopen("/sd/44_8_st.wav","r");
zchen311 0:353c78110e44 28 * waver.play(wave_file);
zchen311 0:353c78110e44 29 * fclose(wave_file);
zchen311 0:353c78110e44 30 * }
zchen311 0:353c78110e44 31 * @endcode
zchen311 0:353c78110e44 32 */
zchen311 0:353c78110e44 33 class wave_player {
zchen311 0:353c78110e44 34
zchen311 0:353c78110e44 35 public:
zchen311 0:353c78110e44 36 int* getVolumeMod();
zchen311 0:353c78110e44 37 /** Create a wave player using a pointer to the given AnalogOut object.
zchen311 0:353c78110e44 38 *
zchen311 0:353c78110e44 39 * @param _dac pointer to an AnalogOut object to which the samples are sent.
zchen311 0:353c78110e44 40 */
zchen311 0:353c78110e44 41 wave_player(AnalogOut *_dac);
zchen311 0:353c78110e44 42
zchen311 0:353c78110e44 43 /** the player function.
zchen311 0:353c78110e44 44 *
zchen311 0:353c78110e44 45 * @param wavefile A pointer to an opened wave file
zchen311 0:353c78110e44 46 */
zchen311 0:353c78110e44 47 void play(FILE *wavefile,bool *ptr);
zchen311 0:353c78110e44 48
zchen311 0:353c78110e44 49 /** Set the printf verbosity of the wave player. A nonzero verbosity level
zchen311 0:353c78110e44 50 * will put wave_player in a mode where the complete contents of the wave
zchen311 0:353c78110e44 51 * file are echoed to the screen, including header values, and including
zchen311 0:353c78110e44 52 * all of the sample values placed into the DAC FIFO, and the sample values
zchen311 0:353c78110e44 53 * removed from the DAC FIFO by the ISR. The sample output frequency is
zchen311 0:353c78110e44 54 * fixed at 2 Hz in this mode, so it's all very slow and the DAC output isn't
zchen311 0:353c78110e44 55 * very useful, but it lets you see what's going on and may help for debugging
zchen311 0:353c78110e44 56 * wave files that don't play correctly.
zchen311 0:353c78110e44 57 *
zchen311 0:353c78110e44 58 * @param v the verbosity level
zchen311 0:353c78110e44 59 */
zchen311 0:353c78110e44 60 void set_verbosity(int v);
zchen311 0:353c78110e44 61
zchen311 0:353c78110e44 62 private:
zchen311 0:353c78110e44 63 int volumeMod;
zchen311 0:353c78110e44 64 void dac_out(void);
zchen311 0:353c78110e44 65 int verbosity;
zchen311 0:353c78110e44 66 AnalogOut *wave_DAC;
zchen311 0:353c78110e44 67 Ticker tick;
zchen311 0:353c78110e44 68 unsigned short DAC_fifo[256];
zchen311 0:353c78110e44 69 short DAC_wptr;
zchen311 0:353c78110e44 70 volatile short DAC_rptr;
zchen311 0:353c78110e44 71 short DAC_on;
zchen311 0:353c78110e44 72 };
zchen311 0:353c78110e44 73
zchen311 0:353c78110e44 74