/*! * @file ogg_player.h * Ogg-Player definition */ #ifndef _OGG_PLAYER_H #define _OGG_PLAYER_H #include "base_object.h" #include "alincl.h" #include #include #include "util/threads/threading.h" struct File; #define OGG_PLAYER_BUFFER_SIZE (8096 * 2) namespace OrxSound { // the definition of a Ogg-Player class OggPlayer : public BaseObject { ObjectListDeclaration(OggPlayer); public: /** * An enumerator defining in what State the OggPlayer is. * The OggPlayer can be in multiple States listed here. * It can as an example be in FileOpened and Stopped. */ typedef enum { None = 0x000, //!< Initialized FileOpened = 0x100, //!< File is Opened SourceAllocated = 0x200, //!< Source is Allocated. BuffersAllocated = 0x400, //!< 2 Buffers are Allocated. Stopped = 0x010, //!< OggPlayer is stopped. Playing = 0x020, //!< OggPlayer is Playing. Paused = 0x040, //!< OggPlayer is Paused. Error = 0x001, //!< An Error has occured. } State; OggPlayer(const std::string& fileName = ""); virtual ~OggPlayer(); /** @param state compare this State with the internal State @returns true on match */ bool operator==(OggPlayer::State state) { return this->state & state; }; bool open(const std::string& fileName = ""); bool play(); void stop(); void pause(); void rewind(); // convenience void jumpTo(float timeCode); float length(); bool isPlaying(); bool getState() { return this->state; }; const std::string& artist() const { return this->_artist; }; const std::string& title() const { return this->_title; }; const std::string& album() const { return this->_album; }; void debug() const; void printState() const; const char* getVorbisError(int code); private: static int musicThread(void* oggPlayer); bool playback(); void suspend(); bool update(); void release(); bool stream(ALuint buffer); void empty(); void retrieveFileInfo(OggVorbis_File* file); private: FILE* oggFile; //!< general file-handler, to open the sound-file OggVorbis_File oggStream; //!< The stream this Ogg-player is playing back vorbis_info* vorbisInfo; //!< The information held in the opened ogg-file vorbis_comment* vorbisComment; //!< Comments about the ogg-file ALuint buffers[2]; //!< buffers that handle sequentially buffering of the audio ALuint source; //!< The source we play back on ALenum format; //!< The format we play back unsigned int state; //!< The States the OggPlayer is in (this can be multiple entries from OggPlayer::State). SDL_Thread* musicThreadID; //!< The Thread in which music is Played back. OrxThread::Mutex musicMutex; //!< A Mutex so that the two threads do not interfere. std::string _title; //!< Song Title. std::string _artist; //!< Artist Name of the current song. std::string _album; //!< Album Name of the current song. std::string _vendor; //!< Vendor Name of the current song. }; } #endif /* _OGG_PLAYER_H */