Music Visualizer

Dependencies:   mbed SDFileSystem NeoStrip PinDetect

Committer:
spatel465
Date:
Thu Apr 30 04:00:33 2020 +0000
Revision:
9:0e16d1e33c4b
Parent:
0:adce77867281
cleaned up comments

Who changed what in which revision?

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