1 | /*! |
---|
2 | * @file ogg_player.h |
---|
3 | * Ogg-Player definition |
---|
4 | */ |
---|
5 | |
---|
6 | |
---|
7 | #ifndef _OGG_PLAYER_H |
---|
8 | #define _OGG_PLAYER_H |
---|
9 | |
---|
10 | #include "base_object.h" |
---|
11 | |
---|
12 | #include "alincl.h" |
---|
13 | #include <ogg/ogg.h> |
---|
14 | #include <vorbis/vorbisfile.h> |
---|
15 | #include "threading.h" |
---|
16 | |
---|
17 | struct File; |
---|
18 | |
---|
19 | |
---|
20 | #define OGG_PLAYER_BUFFER_SIZE (8096 * 2) |
---|
21 | |
---|
22 | namespace OrxSound |
---|
23 | { |
---|
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; |
---|
43 | |
---|
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; }; |
---|
48 | |
---|
49 | bool open(const std::string& fileName = ""); |
---|
50 | |
---|
51 | bool play(); |
---|
52 | void stop(); |
---|
53 | void pause(); |
---|
54 | void rewind(); // convenience |
---|
55 | void jumpTo(float timeCode); |
---|
56 | |
---|
57 | float length(); |
---|
58 | bool isPlaying(); |
---|
59 | bool getState() { return this->state; }; |
---|
60 | |
---|
61 | const std::string& artist() const { return this->_artist; }; |
---|
62 | const std::string& title() const { return this->_title; }; |
---|
63 | const std::string& album() const { return this->_album; }; |
---|
64 | |
---|
65 | |
---|
66 | void debug() const; |
---|
67 | void printState() const; |
---|
68 | const char* getVorbisError(int code); |
---|
69 | |
---|
70 | |
---|
71 | private: |
---|
72 | static int musicThread(void* oggPlayer); |
---|
73 | bool playback(); |
---|
74 | void suspend(); |
---|
75 | bool update(); |
---|
76 | |
---|
77 | void release(); |
---|
78 | |
---|
79 | bool stream(ALuint buffer); |
---|
80 | void empty(); |
---|
81 | |
---|
82 | void retrieveFileInfo(OggVorbis_File* file); |
---|
83 | |
---|
84 | private: |
---|
85 | FILE* oggFile; //!< general file-handler, to open the sound-file |
---|
86 | OggVorbis_File oggStream; //!< The stream this Ogg-player is playing back |
---|
87 | vorbis_info* vorbisInfo; //!< The information held in the opened ogg-file |
---|
88 | vorbis_comment* vorbisComment; //!< Comments about the ogg-file |
---|
89 | |
---|
90 | ALuint buffers[2]; //!< buffers that handle sequentially buffering of the audio |
---|
91 | ALuint source; //!< The source we play back on |
---|
92 | ALenum format; //!< The format we play back |
---|
93 | unsigned int state; //!< The States the OggPlayer is in (this can be multiple entries from OggPlayer::State). |
---|
94 | |
---|
95 | SDL_Thread* musicThreadID; //!< The Thread in which music is Played back. |
---|
96 | OrxThread::Mutex musicMutex; //!< A Mutex so that the two threads do not interfere. |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | std::string _title; |
---|
101 | std::string _artist; |
---|
102 | std::string _album; |
---|
103 | std::string _vendor; |
---|
104 | }; |
---|
105 | |
---|
106 | } |
---|
107 | #endif /* _OGG_PLAYER_H */ |
---|