modified for changes
Dependents: AppBoard_Waveplayer
Fork of wave_player_appbd by
wave_player.h@4:4edd9db27009, 2015-03-03 (annotated)
- Committer:
- psahay
- Date:
- Tue Mar 03 19:51:08 2015 +0000
- Revision:
- 4:4edd9db27009
- Parent:
- 3:9681894c42cb
stop functionality
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:acc3e18e77ad | 12 | |
sravet | 1:acc3e18e77ad | 13 | /** wave file player class. |
sravet | 0:62c18ade9a60 | 14 | * |
sravet | 0:62c18ade9a60 | 15 | * Example: |
sravet | 0:62c18ade9a60 | 16 | * @code |
sravet | 1:acc3e18e77ad | 17 | * #include <mbed.h> |
sravet | 1:acc3e18e77ad | 18 | * #include <wave_player.h> |
sravet | 1:acc3e18e77ad | 19 | * |
sravet | 1:acc3e18e77ad | 20 | * AnalogOut DACout(p18); |
sravet | 1:acc3e18e77ad | 21 | * wave_player waver(&DACout); |
sravet | 1:acc3e18e77ad | 22 | * |
sravet | 0:62c18ade9a60 | 23 | * int main() { |
sravet | 0:62c18ade9a60 | 24 | * FILE *wave_file; |
sravet | 0:62c18ade9a60 | 25 | * |
sravet | 0:62c18ade9a60 | 26 | * printf("\n\n\nHello, wave world!\n"); |
sravet | 0:62c18ade9a60 | 27 | * wave_file=fopen("/sd/44_8_st.wav","r"); |
sravet | 0:62c18ade9a60 | 28 | * waver.play(wave_file); |
sravet | 0:62c18ade9a60 | 29 | * fclose(wave_file); |
sravet | 0:62c18ade9a60 | 30 | * } |
sravet | 0:62c18ade9a60 | 31 | * @endcode |
sravet | 0:62c18ade9a60 | 32 | */ |
sravet | 0:62c18ade9a60 | 33 | class wave_player { |
sravet | 0:62c18ade9a60 | 34 | |
sravet | 0:62c18ade9a60 | 35 | public: |
sravet | 0:62c18ade9a60 | 36 | /** Create a wave player using a pointer to the given AnalogOut object. |
sravet | 0:62c18ade9a60 | 37 | * |
sravet | 1:acc3e18e77ad | 38 | * @param _dac pointer to an AnalogOut object to which the samples are sent. |
sravet | 0:62c18ade9a60 | 39 | */ |
4180_1 | 2:b1cea7afcfd2 | 40 | wave_player(AnalogOut *_dac, PwmOut *_pwm); |
sravet | 0:62c18ade9a60 | 41 | |
sravet | 0:62c18ade9a60 | 42 | /** the player function. |
sravet | 0:62c18ade9a60 | 43 | * |
sravet | 0:62c18ade9a60 | 44 | * @param wavefile A pointer to an opened wave file |
sravet | 0:62c18ade9a60 | 45 | */ |
sravet | 0:62c18ade9a60 | 46 | void play(FILE *wavefile); |
sravet | 0:62c18ade9a60 | 47 | |
sravet | 0:62c18ade9a60 | 48 | /** Set the printf verbosity of the wave player. A nonzero verbosity level |
sravet | 0:62c18ade9a60 | 49 | * will put wave_player in a mode where the complete contents of the wave |
sravet | 0:62c18ade9a60 | 50 | * file are echoed to the screen, including header values, and including |
sravet | 0:62c18ade9a60 | 51 | * all of the sample values placed into the DAC FIFO, and the sample values |
sravet | 0:62c18ade9a60 | 52 | * removed from the DAC FIFO by the ISR. The sample output frequency is |
sravet | 0:62c18ade9a60 | 53 | * fixed at 2 Hz in this mode, so it's all very slow and the DAC output isn't |
sravet | 0:62c18ade9a60 | 54 | * very useful, but it lets you see what's going on and may help for debugging |
sravet | 0:62c18ade9a60 | 55 | * wave files that don't play correctly. |
sravet | 0:62c18ade9a60 | 56 | * |
sravet | 0:62c18ade9a60 | 57 | * @param v the verbosity level |
sravet | 0:62c18ade9a60 | 58 | */ |
sravet | 0:62c18ade9a60 | 59 | void set_verbosity(int v); |
sravet | 0:62c18ade9a60 | 60 | |
psahay | 4:4edd9db27009 | 61 | bool stop; |
psahay | 3:9681894c42cb | 62 | |
sravet | 0:62c18ade9a60 | 63 | private: |
sravet | 0:62c18ade9a60 | 64 | void dac_out(void); |
sravet | 0:62c18ade9a60 | 65 | int verbosity; |
sravet | 0:62c18ade9a60 | 66 | AnalogOut *wave_DAC; |
4180_1 | 2:b1cea7afcfd2 | 67 | PwmOut *wave_PWM; |
sravet | 0:62c18ade9a60 | 68 | Ticker tick; |
sravet | 0:62c18ade9a60 | 69 | unsigned short DAC_fifo[256]; |
sravet | 0:62c18ade9a60 | 70 | short DAC_wptr; |
sravet | 0:62c18ade9a60 | 71 | volatile short DAC_rptr; |
sravet | 0:62c18ade9a60 | 72 | short DAC_on; |
sravet | 0:62c18ade9a60 | 73 | }; |
sravet | 0:62c18ade9a60 | 74 | |
sravet | 0:62c18ade9a60 | 75 |