
#ifndef H_SFL_MIXER_
#define H_SFL_MIXER_

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

struct sflSound_t;

#define SFL_MIXER_NUM_SLOT 8
#define SFL_MIXER_NEXT_SLOT (-1)
#define SFL_MIXER_ALL_SLOT (-1)
#define SFL_MIXER_VOLUME_MAX 0x8000

typedef void (*sflMixerCallback)(int slot, int args, void *argp);

/**
 * Initialize sflMixer
 * @return 0 on success, -1 on error.
 */
int sflMixerInit(void);

/**
 * Finalize sflMixer
 */
void sflMixerQuit(void);

/**
 * Play sound on a particular slot
 * @param slot A slot number. if slot is -1, mixer searchs available slot automatically.
 * @return A slot number where sound is played on. If no slot is available, -1 returns.
 */
int sflMixerPlaySound(int slot, struct sflSound_t *sound);

/**
 * Pause playing on a particular slot
 * @param slot Pause a slot. if -1, pause all slots
 */
void sflMixerPauseSound(int slot);

/**
 * Resume playing on a particular slot
 * @param slot Resume a slot. if -1, resume all slots
 */
void sflMixerResumeSound(int slot);

/**
 * Stop playing on a particular slot
 * @param slot Stop a slot. if -1, stop all slots
 */
void sflMixerStopSound(int slot);

/**
 * Query if sound is played on a particular slot
 * @return if playing 1, else 0
 */
int sflMixerIsPlaying(int slot);

/**
 * Query if sound is paused on a particular slot
 * @return 1 if paused, else 0
 */
int sflMixerIsPaused(int slot);

/**
 * Query if sound is stopped on a particular slot
 * @return 1 if stopped, else 0
 */
int sflMixerIsStopped(int slot);

/**
 * Set volume of a particular slot
 */
void sflMixerSetVolume(int slot, int left, int right);

int sflMixerSetPositionBySamples(int slot, int offset, int whence);
int sflMixerSetPositionBySeconds(int slot, float offset, int whence);

int sflMixerGetPositionBySamples(int slot);
float sflMixerGetPositionBySeconds(int slot);

/**
 * Set a callback function called when sound is end
 * @param slot
 * @param callback
 * @param args
 * @param argp
 */
void sflMixerSetCallback(int slot, void (*callback)(int, int, void*), int args, void *argp);

#ifdef __cplusplus
}
#endif

#endif

