/** * Copyright 2013 (c) Anna Schumaker. */ #ifndef OCARINA_CORE_AUDIO_H #define OCARINA_CORE_AUDIO_H #include #include #include /** * The audio driver class gives us an interface for using multiple * audio frameworks for audio playback. */ class AudioDriver { protected: void (*on_error) (); /**< Error handling callback function. */ public: AudioDriver(); /**< Default AudioDriver constructor. */ virtual ~AudioDriver(); /**< AudioDriver destructor. */ /** * Loads an audio file for playback. * * @param track The Track to load. */ virtual void load(Track *track) = 0; /** * Called to begin playback on the currently loaded track. */ virtual void play() = 0; /** * Called to pause playback on the currently loaded track. */ virtual void pause() = 0; /** * Called to check if the audio library is currently playing a track. * * @return True if audio library is playing, false otherwise. */ virtual bool is_playing() = 0; /** * Seek to a specific position in the current track. * * @param offset Position from the beginning of the track where we will seek to, in nanoseconds. */ virtual void seek_to(int64_t offset) = 0; /** * Return the current position of the playback. * * @return The current playback position, in nanoseconds. */ virtual int64_t position() = 0; /** * Return the duration of the currently loaded track. * * @return The duration of the current track, in nanoseconds. */ virtual int64_t duration() = 0; /** * Called to handle reaching the end-of-stream. */ void eos(); }; /** * Namespace for higher-level audio controls. */ namespace audio { void init(); /**< Initializes the audio layer. */ void play(); /**< Begin playback. */ void pause(); /**< Pause playback. */ /** * Seek to a specific point in the track. * * @param pos Offset (in nanoseconds) from the beginning of the track. */ void seek_to(int64_t); /** * Stop playback and seek to the beginning of the track. */ void stop(); /** * @return The current position of the audio playback (in nanoseconds). */ int64_t position(); /** * @return The duration of the currently loaded track (in nanoseconds). */ int64_t duration(); void next(); /**< Find and load the next track that should be played. */ void prev(); /**< Call the deck :: previous() function and load the result. */ /** * Load a specific track for playback. * * @param track The track that should be loaded. */ void load_track(Track *track); /** * @return A pointer to the currently playing track object. */ Track *current_track(); /** * Configure the automatic pausing feature. * * @param enabled Set to true to enable pausing, false to disable. * @param n Number of tracks to play before pausing. */ void pause_after(bool, unsigned int); /** * Call to find the current automatic pausing state. * * @return True if automatic pausing is enabled, false otherwise. */ bool pause_enabled(); /** * Call to find the number of tracks remaining before pausing. * * @return The number of tracks before pausing. */ unsigned int pause_count(); /** * Called to access an audio driver. * * @return The current driver used by the application. */ AudioDriver *get_driver(); }; #endif /* OCARINA_CORE_AUDIO_H */