microSDカードからWaveファイルを再生するサンプルです。

Dependencies:   mbed FATFileSystem

Fork of JBB_WavePlayer_test by Jksoft Blue mbed Board Developer

Committer:
jksoft
Date:
Mon May 12 14:45:42 2014 +0000
Revision:
0:e9f196d85a46
First edition

Who changed what in which revision?

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