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