Only Yesterday 制御プログラム

Dependencies:   mbed FATFileSystem

Fork of OnlyYestaerday by Junichi Katsu

Committer:
jksoft
Date:
Wed Apr 02 01:43:55 2014 +0000
Revision:
0:5975af170e43
1st Prototype

Who changed what in which revision?

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