Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
bgm.hpp
1 //////////////////////////////
2 //
3 // File: lxs/audio/bgm.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Nov 2 2012
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_AUD_BGM
15 #define __LXS_AUD_BGM
16 #include "helper/openal.hpp"
17 #include <string>
18 #include "lxs/system/servicethread.hpp"
19 
20 #include "lxs/audio/oggdatasource.hpp"
21 #define BUFFER_SIZE (4*6144)
22 //8 * 1024)
23 #define BUFFER_COUNT 4
24 
25 namespace LxS
26 {
27  namespace Audio
28  {
29  //! state of track playback
31  {
32  //! not initialized
34  //! scheduled to play
36  //! currentlyu playing
38  //! pause scheduled
40  //! paused
42  //! stop scheduled
44  //! stopped
46  //! deinitialization planned
48 
49  };
50  //! background music
51  class BGM
52  {
54  char temp[BUFFER_SIZE];
55 
56  ALuint buffers[BUFFER_COUNT];
57  //bool initialized;
58  TrackState trackstate;
59  ALuint source; // openAL source - for BGM
60  float volume;
61  std::string now_playing;
62  // play actual track (in a thread)
63  void PlayTrackThread(const std::string & track, bool dontstop);
64  public:
65  BGM();
66  //! initialize audio played
67  void Initialize();
68 
69  //! enqueue trach to a BGM playlist
70  //! if dontstop is set to true, after playing this track (if it is last on the playlist) it will be reinserted onto the playlist)
71  void EnqueueTrack(const std::string & track, bool dontstop=false);
72  //! stop playback
73  void Stop();
74  //! uninitialize track
75  void UnloadResources();
76  //! set global bgm volume
77  void SetVolume(float _volume);
78  //! return track that is currently being played
79  std::string & GetNowPlaying();
80  //! is soundtrack being played
81  bool IsPlaying();
82 
83  ~BGM();
84  };
85  }
86 }
87 #endif