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