87 lines
2.0 KiB
C++
87 lines
2.0 KiB
C++
/**
|
|
* @file
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#ifndef OCARINA_CORE_DRIVER_H
|
|
#define OCARINA_CORE_DRIVER_H
|
|
|
|
#include <string>
|
|
|
|
/** Use to convert nanoseconds to seconds */
|
|
static const unsigned long O_SECOND = 1000000000;
|
|
|
|
|
|
/**
|
|
* The audio driver class gives us an interface for using multiple
|
|
* audio frameworks for audio playback.
|
|
*/
|
|
class Driver {
|
|
protected:
|
|
void (*on_eos) (); /**< End-of-stream callback function. */
|
|
void (*on_error) (); /**< Error handling callback function. */
|
|
|
|
public:
|
|
Driver(); /**< Default Driver constructor. */
|
|
virtual ~Driver(); /**< Driver destructor. */
|
|
|
|
/**
|
|
* Initialize an audio driver.
|
|
*
|
|
* @param eos_cb End-of-stream callback function.
|
|
*/
|
|
virtual void init(void (*eos_cb)()) = 0;
|
|
|
|
|
|
/**
|
|
* Loads an audio file for playback.
|
|
*
|
|
* @param file Filepath of the track to load.
|
|
*/
|
|
virtual void load(const std::string &file) = 0;
|
|
|
|
/**
|
|
* Called to begin playback on the currently loaded track.
|
|
*
|
|
* @return True if playback state was changed successfully, false otherwise.
|
|
*/
|
|
virtual bool play() = 0;
|
|
|
|
/**
|
|
* Called to pause playback on the currently loaded track.
|
|
*
|
|
* @return True if playback state was changed successfully, false otherwise.
|
|
*/
|
|
virtual bool 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(long offset) = 0;
|
|
|
|
/**
|
|
* Return the current position of the playback.
|
|
*
|
|
* @return The current playback position, in nanoseconds.
|
|
*/
|
|
virtual long position() = 0;
|
|
|
|
/**
|
|
* Return the duration of the currently loaded track.
|
|
*
|
|
* @return The duration of the current track, in nanoseconds.
|
|
*/
|
|
virtual long duration() = 0;
|
|
};
|
|
|
|
#endif /* OCARINA_CORE_DRIVER_H */
|