Wave playing code based of sravet/wave_player, but with mbed-os v5 support and additional PWM output

Dependents:   waveplayer_mbedOS_v5_helloworld

Committer:
sravet
Date:
Tue Jan 18 03:41:02 2011 +0000
Revision:
0:62c18ade9a60
Child:
1:acc3e18e77ad
Initial checkin

Who changed what in which revision?

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