Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/sound/ogg_player.h @ 7917

Last change on this file since 7917 was 7331, checked in by bensch, 19 years ago

orxonox/trunk: small improved functoid

File size: 2.8 KB
Line 
1/*!
2 * @file ogg_player.h
3 * Ogg-Player definition
4 */
5
6
7#ifndef _OGG_PLAYER_H
8#define _OGG_PLAYER_H
9
10using namespace std;
11
12#include "base_object.h"
13
14#include "alincl.h"
15#include <ogg/ogg.h>
16#include <vorbis/vorbisfile.h>
17#include "threading.h"
18
19struct File;
20
21
22#define OGG_PLAYER_BUFFER_SIZE (8096 * 2)
23
24
25// the definition of a Ogg-Player
26class OggPlayer : public BaseObject
27{
28public:
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 {
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.
43  } State;
44
45  OggPlayer(const std::string& fileName = "");
46  virtual ~OggPlayer();
47  /** @param state compare this State with the internal State @returns true on match */
48  bool operator==(OggPlayer::State state) { return this->state & state; };
49
50  bool open(const std::string& fileName = "");
51
52  bool play();
53  void stop();
54  void pause();
55  void rewind(); // convenience
56  void jumpTo(float timeCode);
57
58  float length();
59  bool isPlaying();
60  bool getState() { return this->state; };
61
62  void debug() const;
63  void printState() const;
64  const char* getVorbisError(int code);
65
66
67private:
68  static int musicThread(void* oggPlayer);
69  bool playback();
70  void suspend();
71  bool update();
72
73  void release();
74
75  bool stream(ALuint buffer);
76  void empty();
77
78private:
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
83
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
87  unsigned int        state;                //!< The States the OggPlayer is in (this can be multiple entries from OggPlayer::State).
88
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.
91};
92
93
94#endif /* _OGG_PLAYER_H */
Note: See TracBrowser for help on using the repository browser.