118 lines
2.6 KiB
C++
118 lines
2.6 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 argc Argc passed to the application's main() function.
|
|
* @param argv Argv passed to the applicaiton's main() function.
|
|
* @param eos_cb End-of-stream callback function.
|
|
* @param error_cb Callback function used when the audio library encounters an error.
|
|
*/
|
|
virtual void init(int *argc, char ***argv, void (*eos_cb)(), void (*error_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;
|
|
};
|
|
|
|
|
|
#ifdef CONFIG_TEST
|
|
class TestDriver : public Driver
|
|
{
|
|
public:
|
|
bool playing;
|
|
long cur_pos;
|
|
long cur_duration;
|
|
std::string cur_file;
|
|
|
|
TestDriver();
|
|
~TestDriver();
|
|
void init(int *, char ***, void (*)(), void (*)());
|
|
|
|
void load(const std::string &);
|
|
bool play();
|
|
bool pause();
|
|
bool is_playing();
|
|
|
|
void seek_to(long);
|
|
long position();
|
|
long duration();
|
|
|
|
void eos();
|
|
void error();
|
|
};
|
|
#endif /* CONFIG_TEST */
|
|
|
|
#endif /* OCARINA_CORE_DRIVER_H */
|