#ifndef SPEAKER_H #define SPEAKER_H #include #include #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include "freertos/task.h" #include "driver/i2s_std.h" #include "driver/gpio.h" #include "esp_check.h" #include "sdkconfig.h" #include "sd.h" #define SPEAKER_PIN_BCLK GPIO_NUM_46 #define SPEAKER_PIN_WS GPIO_NUM_9 #define SPEAKER_PIN_DOUT GPIO_NUM_3 #define SAMPLE_RATE 44100 #define PLAY_QUEUE_SIZE 8 // The maximum number of clips that can be playing at one time. #define PLAYING_CLIP_SIZE 8 // Audio will be processed in blocks of this many samples #define AUDIO_BLOCK_SIZE 2048 extern i2s_chan_handle_t tx_chan; typedef struct { /// A dynamically allocated string specifying the name of the /// file to play. The speaker system will free this once it /// is done. char* file_name; /// A number that all samples will be shifted right by. uint8_t prescaler; /// A flag for repeating. bool repeat; /// A flag for starting the clip immediatly, /// even if there is another clip playing. bool play_immediatly; } audio_clip_t; /// Plays a audio file stopping when something is received on `stop_handle` /// /// `stop_handle` should be of size `uint8_t`. esp_err_t play_raw_stop_queue(const char *fp, QueueHandle_t stop_handle); esp_err_t play_raw(const char *fp); /// @brief Initalizes the speaker void init_speaker(); void play_example(); #endif /* SPEAKER_H */