/*
 * sd-card or external file system player
 */

#ifndef MAIN_PLAYER_H_
#define MAIN_PLAYER_H_

#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"

#define CHIMES_MAX_SIZE_KB  512
#define ONE_MAX_SIZE_KB  256
#define BEEP_MAX_SIZE_KB  16


//listing order is important! see array sound_type_fn
typedef enum {
	SOUND_ALARM = 0,	//alarm signal. Must be 0 index!
	SOUND_CHIMES,		//the sound of chimes. Sounds before the chime of the hour bell.
	SOUND_ONE,			//Sound of the hour bell.
	SOUND_BEEP,			//Sound of the key press.
	SOUND_MAX,			//flag end list
} sound_type_t;

#define SOUND_ALARM_TAG		"alarm"
#define SOUND_EACH_TAG		"chimes"
#define SOUND_ONE_TAG		"each"
#define SOUND_BEEP_TAG		"beep"

#define SOUND_CHIMING_Q_LEN  13 	//chiming queue length

typedef void (*play_start_stop_cb)(sound_type_t file_name);

/**
 * @brief initialize player module
 * Call this once before using other player module features
 * @return
 *      - ESP_OK on success
 *      - not ESP_OK - init failure
 */
esp_err_t playerInit(void);
/**
 * @brief Check the format of the data in the buffer. If the data is in the correct audio format then return true.
 * @return
 *      - true - the correct audio format
 *      - false - not correct audio format
 */
//bool soundTypeIsSupport(char *buf, size_t size);
/**
 * @brief write the contents of the buffer to the end of the file. If the size is 0, then the file is closed.
 * @return
 * 	- ESP_OK - the file was opened successfully, the buffer was written successfully, or the file was closed successfully
 * 	- ESP_ERR_NOT_SUPPORTED - could not open file
 * 	- another error
 */
esp_err_t sound_file_write(const char *tag_name, const char *buf, const size_t size, const char *file_name);
/**
 * @brief get free size from type sound
 * @return return file size. return 0 if file not found or unknown type
 */
size_t sound_size_file(sound_type_t file_name);

/**
 * @brief Volume setting. Only works if the volume chip is installed. (see SOUND_OUT_I2S_CNTRL)
 * @param[in] value from 0. Maximum value unlimited, but stick to reasonable values.
 * Usually from 0 to 1, if you pass 10, then strong distortion is noticeable.
 * @return none
 */
void play_volume_set(float value);

/**
 * @brief Start playback of the specified file type. When starting or finished, call the callback function.
 * @return none
 */
void playFile(sound_type_t file_name, play_start_stop_cb start_play_func, play_start_stop_cb end_play_func);

/**
 * @brief Stop playback. If the file is not played, then it has no effect.
 * @return none
 */
void playStop(void);

#endif /* MAIN_PLAYER_H_ */
