renamed all .h to .hpp
[supertux.git] / src / audio / sound_manager.hpp
1 #ifndef __SOUND_MANAGER_H__
2 #define __SOUND_MANAGER_H__
3
4 #include "math/vector.hpp"
5 #include <string>
6 #include <vector>
7 #include <map>
8
9 #include <AL/alc.h>
10 #include <AL/al.h>
11
12 typedef void* SoundHandle;
13
14 class SoundFile;
15 class SoundSource;
16 class StreamSoundSource;
17
18 class SoundManager
19 {
20 public:
21   SoundManager();
22   virtual ~SoundManager();
23
24   void enable_sound(bool sound_enabled);
25   /**
26    * Creates a new sound source object which plays the specified soundfile.
27    * You are responsible for deleting the sound source later (this will stop the
28    * sound).
29    * This function might throw exceptions. It returns 0 if no audio device is
30    * available.
31    */
32   SoundSource* create_sound_source(const std::string& filename);
33   /**
34    * Convenience function to simply play a sound at a given position.
35    * This functions prepends sounds/ to the name and adds .wav
36    */
37   void play(const std::string& name, const Vector& pos = Vector(-1, -1));
38
39   void set_listener_position(Vector position);
40   void set_listener_velocity(Vector velocity);
41
42   void enable_music(bool music_enabled);
43   void play_music(const std::string& filename);
44
45   void update();
46
47 private:
48   friend class SoundSource;
49   friend class StreamSoundSource;
50
51   static ALuint load_file_into_buffer(const std::string& filename);
52   static ALenum get_sample_format(SoundFile* file);
53
54   void print_openal_version();
55   void check_alc_error(const char* message);
56   static void check_al_error(const char* message);
57
58   ALCdevice* device;
59   ALCcontext* context;
60   bool sound_enabled;
61
62   typedef std::map<std::string, ALuint> SoundBuffers;
63   SoundBuffers buffers;
64   typedef std::vector<SoundSource*> SoundSources;
65   SoundSources sources;
66
67   StreamSoundSource* music_source;
68
69   bool music_enabled;
70   std::string current_music;
71 };
72
73 #endif
74