Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/sound/ogg_player.h @ 10432

Last change on this file since 10432 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.5 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
10#include "base_object.h"
11
12#include "alincl.h"
13#include <ogg/ogg.h>
14#include <vorbis/vorbisfile.h>
15#include "util/threading.h"
16
17struct File;
18
19
20#define OGG_PLAYER_BUFFER_SIZE (8096 * 2)
21
22namespace OrxSound
23{
24  // the definition of a Ogg-Player
25  class OggPlayer : public BaseObject
26  {
27    ObjectListDeclaration(OggPlayer);
28
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;
45
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; };
50
51    bool open(const std::string& fileName = "");
52
53    bool play();
54    void stop();
55    void pause();
56    void rewind(); // convenience
57    void jumpTo(float timeCode);
58
59    float length();
60    bool isPlaying();
61    bool getState() { return this->state; };
62
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
68    void debug() const;
69    void printState() const;
70    const char* getVorbisError(int code);
71
72
73  private:
74    static int musicThread(void* oggPlayer);
75    bool playback();
76    void suspend();
77    bool update();
78
79    void release();
80
81    bool stream(ALuint buffer);
82    void empty();
83
84    void retrieveFileInfo(OggVorbis_File* file);
85
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
91
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).
96
97    SDL_Thread*         musicThreadID;        //!< The Thread in which music is Played back.
98    OrxThread::Mutex    musicMutex;           //!< A Mutex so that the two threads do not interfere.
99
100
101
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.
106  };
107
108}
109#endif /* _OGG_PLAYER_H */
Note: See TracBrowser for help on using the repository browser.