[4836] | 1 | /*! |
---|
| 2 | * @file ogg_player.h |
---|
[4961] | 3 | * Ogg-Player definition |
---|
[4836] | 4 | */ |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | #ifndef _OGG_PLAYER_H |
---|
| 8 | #define _OGG_PLAYER_H |
---|
| 9 | |
---|
[4961] | 10 | #include "base_object.h" |
---|
| 11 | |
---|
[5279] | 12 | #include "alincl.h" |
---|
[4836] | 13 | #include <ogg/ogg.h> |
---|
| 14 | #include <vorbis/vorbisfile.h> |
---|
[10618] | 15 | #include "util/threads/mutex_locker.h" |
---|
[4836] | 16 | |
---|
[5282] | 17 | struct File; |
---|
[4836] | 18 | |
---|
| 19 | |
---|
[7308] | 20 | #define OGG_PLAYER_BUFFER_SIZE (8096 * 2) |
---|
[4836] | 21 | |
---|
[7460] | 22 | namespace OrxSound |
---|
[6871] | 23 | { |
---|
[7460] | 24 | // the definition of a Ogg-Player |
---|
| 25 | class OggPlayer : public BaseObject |
---|
| 26 | { |
---|
[9869] | 27 | ObjectListDeclaration(OggPlayer); |
---|
| 28 | |
---|
[7460] | 29 | public: |
---|
| 30 | /** |
---|
| 31 | * An enumerator defining in what State the OggPlayer is. |
---|
| 32 | * The OggPlayer can be in multiple States listed here. |
---|
| 33 | * It can as an example be in FileOpened and Stopped. |
---|
| 34 | */ |
---|
| 35 | typedef enum { |
---|
| 36 | None = 0x000, //!< Initialized |
---|
| 37 | FileOpened = 0x100, //!< File is Opened |
---|
| 38 | SourceAllocated = 0x200, //!< Source is Allocated. |
---|
| 39 | BuffersAllocated = 0x400, //!< 2 Buffers are Allocated. |
---|
| 40 | Stopped = 0x010, //!< OggPlayer is stopped. |
---|
| 41 | Playing = 0x020, //!< OggPlayer is Playing. |
---|
| 42 | Paused = 0x040, //!< OggPlayer is Paused. |
---|
| 43 | Error = 0x001, //!< An Error has occured. |
---|
| 44 | } State; |
---|
[7305] | 45 | |
---|
[7460] | 46 | OggPlayer(const std::string& fileName = ""); |
---|
| 47 | virtual ~OggPlayer(); |
---|
| 48 | /** @param state compare this State with the internal State @returns true on match */ |
---|
| 49 | bool operator==(OggPlayer::State state) { return this->state & state; }; |
---|
[4836] | 50 | |
---|
[7460] | 51 | bool open(const std::string& fileName = ""); |
---|
[7305] | 52 | |
---|
[7460] | 53 | bool play(); |
---|
| 54 | void stop(); |
---|
| 55 | void pause(); |
---|
| 56 | void rewind(); // convenience |
---|
| 57 | void jumpTo(float timeCode); |
---|
[7303] | 58 | |
---|
[7460] | 59 | float length(); |
---|
| 60 | bool isPlaying(); |
---|
| 61 | bool getState() { return this->state; }; |
---|
[7295] | 62 | |
---|
[9019] | 63 | const std::string& artist() const { return this->_artist; }; |
---|
| 64 | const std::string& title() const { return this->_title; }; |
---|
| 65 | const std::string& album() const { return this->_album; }; |
---|
| 66 | |
---|
| 67 | |
---|
[7460] | 68 | void debug() const; |
---|
| 69 | void printState() const; |
---|
| 70 | const char* getVorbisError(int code); |
---|
[7305] | 71 | |
---|
| 72 | |
---|
[7460] | 73 | private: |
---|
| 74 | static int musicThread(void* oggPlayer); |
---|
| 75 | bool playback(); |
---|
| 76 | void suspend(); |
---|
| 77 | bool update(); |
---|
[7304] | 78 | |
---|
[7460] | 79 | void release(); |
---|
[7304] | 80 | |
---|
[7460] | 81 | bool stream(ALuint buffer); |
---|
| 82 | void empty(); |
---|
[4836] | 83 | |
---|
[9019] | 84 | void retrieveFileInfo(OggVorbis_File* file); |
---|
| 85 | |
---|
[7460] | 86 | private: |
---|
| 87 | FILE* oggFile; //!< general file-handler, to open the sound-file |
---|
| 88 | OggVorbis_File oggStream; //!< The stream this Ogg-player is playing back |
---|
| 89 | vorbis_info* vorbisInfo; //!< The information held in the opened ogg-file |
---|
| 90 | vorbis_comment* vorbisComment; //!< Comments about the ogg-file |
---|
[4836] | 91 | |
---|
[7460] | 92 | ALuint buffers[2]; //!< buffers that handle sequentially buffering of the audio |
---|
| 93 | ALuint source; //!< The source we play back on |
---|
| 94 | ALenum format; //!< The format we play back |
---|
| 95 | unsigned int state; //!< The States the OggPlayer is in (this can be multiple entries from OggPlayer::State). |
---|
[7304] | 96 | |
---|
[7460] | 97 | SDL_Thread* musicThreadID; //!< The Thread in which music is Played back. |
---|
[7737] | 98 | OrxThread::Mutex musicMutex; //!< A Mutex so that the two threads do not interfere. |
---|
[9019] | 99 | |
---|
| 100 | |
---|
| 101 | |
---|
[9869] | 102 | std::string _title; //!< Song Title. |
---|
| 103 | std::string _artist; //!< Artist Name of the current song. |
---|
| 104 | std::string _album; //!< Album Name of the current song. |
---|
| 105 | std::string _vendor; //!< Vendor Name of the current song. |
---|
[7460] | 106 | }; |
---|
[4836] | 107 | |
---|
[7460] | 108 | } |
---|
[4836] | 109 | #endif /* _OGG_PLAYER_H */ |
---|