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