2014-09-12 16:08:58 -04:00
|
|
|
/**
|
2013-12-24 20:17:44 -05:00
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2014-06-21 09:37:47 -04:00
|
|
|
#ifndef OCARINA_CORE_AUDIO_H
|
|
|
|
#define OCARINA_CORE_AUDIO_H
|
2013-12-24 20:17:44 -05:00
|
|
|
|
2014-12-02 08:16:22 -05:00
|
|
|
#include <core/tags/track.h>
|
2014-01-22 22:31:42 -05:00
|
|
|
#include <string>
|
2015-03-05 11:00:33 -05:00
|
|
|
#include <stdint.h>
|
2014-01-22 22:31:42 -05:00
|
|
|
|
2014-12-20 15:47:10 -05:00
|
|
|
|
2014-09-12 16:08:58 -04:00
|
|
|
/**
|
2014-12-20 15:47:10 -05:00
|
|
|
* The audio driver class gives us an interface for using multiple
|
|
|
|
* audio frameworks for audio playback.
|
2014-09-12 16:08:58 -04:00
|
|
|
*/
|
2014-12-20 15:47:10 -05:00
|
|
|
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.
|
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
virtual void load(struct track *track) = 0;
|
2014-12-20 15:47:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to begin playback on the currently loaded track.
|
|
|
|
*/
|
|
|
|
virtual void play() = 0;
|
2013-12-24 20:17:44 -05:00
|
|
|
|
2014-09-12 16:08:58 -04:00
|
|
|
/**
|
2014-12-20 15:47:10 -05:00
|
|
|
* Called to pause playback on the currently loaded track.
|
2014-09-12 16:08:58 -04:00
|
|
|
*/
|
2014-12-20 15:47:10 -05:00
|
|
|
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.
|
|
|
|
*/
|
2015-03-05 11:22:18 -05:00
|
|
|
virtual void seek_to(int64_t offset) = 0;
|
2014-12-20 15:47:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current position of the playback.
|
|
|
|
*
|
|
|
|
* @return The current playback position, in nanoseconds.
|
|
|
|
*/
|
2015-03-05 11:00:33 -05:00
|
|
|
virtual int64_t position() = 0;
|
2014-12-20 15:47:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the duration of the currently loaded track.
|
|
|
|
*
|
|
|
|
* @return The duration of the current track, in nanoseconds.
|
|
|
|
*/
|
2015-03-05 11:00:33 -05:00
|
|
|
virtual int64_t duration() = 0;
|
2014-12-20 15:47:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to handle reaching the end-of-stream.
|
|
|
|
*/
|
|
|
|
void eos();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Namespace for higher-level audio controls.
|
|
|
|
*/
|
|
|
|
namespace audio
|
|
|
|
{
|
2013-12-24 20:17:44 -05:00
|
|
|
|
2014-12-20 15:47:10 -05:00
|
|
|
void init(); /**< Initializes the audio layer. */
|
|
|
|
void play(); /**< Begin playback. */
|
|
|
|
void pause(); /**< Pause playback. */
|
2014-09-12 16:08:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Seek to a specific point in the track.
|
|
|
|
*
|
|
|
|
* @param pos Offset (in nanoseconds) from the beginning of the track.
|
|
|
|
*/
|
2015-03-05 11:22:18 -05:00
|
|
|
void seek_to(int64_t);
|
2014-09-12 16:08:58 -04:00
|
|
|
|
|
|
|
/**
|
2014-12-20 15:47:10 -05:00
|
|
|
* Stop playback and seek to the beginning of the track.
|
2014-09-12 16:08:58 -04:00
|
|
|
*/
|
2014-01-04 13:09:44 -05:00
|
|
|
void stop();
|
2013-12-24 20:17:44 -05:00
|
|
|
|
2014-09-12 16:08:58 -04:00
|
|
|
/**
|
|
|
|
* @return The current position of the audio playback (in nanoseconds).
|
|
|
|
*/
|
2015-03-05 11:00:33 -05:00
|
|
|
int64_t position();
|
2014-09-12 16:08:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The duration of the currently loaded track (in nanoseconds).
|
|
|
|
*/
|
2015-03-05 11:00:33 -05:00
|
|
|
int64_t duration();
|
2014-09-12 16:08:58 -04:00
|
|
|
|
2014-12-20 15:47:10 -05:00
|
|
|
void next(); /**< Find and load the next track that should be played. */
|
|
|
|
void prev(); /**< Call the deck :: previous() function and load the result. */
|
2014-09-12 16:08:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a specific track for playback.
|
2014-12-19 13:45:34 -05:00
|
|
|
*
|
|
|
|
* @param track The track that should be loaded.
|
2014-09-12 16:08:58 -04:00
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
void load_track(struct track *track);
|
2014-09-12 16:08:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return A pointer to the currently playing track object.
|
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *current_track();
|
2013-12-25 14:35:33 -05:00
|
|
|
|
2014-09-12 16:08:58 -04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-12-25 14:35:33 -05:00
|
|
|
void pause_after(bool, unsigned int);
|
2014-09-12 16:08:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call to find the current automatic pausing state.
|
|
|
|
*
|
|
|
|
* @return True if automatic pausing is enabled, false otherwise.
|
|
|
|
*/
|
2013-12-25 14:35:33 -05:00
|
|
|
bool pause_enabled();
|
2014-09-12 16:08:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call to find the number of tracks remaining before pausing.
|
|
|
|
*
|
|
|
|
* @return The number of tracks before pausing.
|
|
|
|
*/
|
2013-12-25 14:35:33 -05:00
|
|
|
unsigned int pause_count();
|
2014-12-19 14:53:42 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to access an audio driver.
|
|
|
|
*
|
|
|
|
* @return The current driver used by the application.
|
|
|
|
*/
|
2014-12-20 15:47:10 -05:00
|
|
|
AudioDriver *get_driver();
|
2013-12-24 20:17:44 -05:00
|
|
|
};
|
|
|
|
|
2014-06-21 09:37:47 -04:00
|
|
|
#endif /* OCARINA_CORE_AUDIO_H */
|