SuperTuxKart
sfx_buffer.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2010-2015 Marianne Gagnon
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_SFX_BUFFER_HPP
20 #define HEADER_SFX_BUFFER_HPP
21 
22 #ifdef ENABLE_SOUND
23 # include <AL/al.h>
24 # include <AL/alc.h>
25 #else
26 typedef unsigned int ALuint;
27 #endif
28 
29 #include "utils/no_copy.hpp"
30 #include "utils/vec3.hpp"
31 #include "utils/leak_check.hpp"
32 
33 #include <string>
34 #include <memory>
35 
36 class SFXBase;
37 class XMLNode;
38 
43 class SFXBuffer
44 {
45 private:
46 
47  LEAK_CHECK()
48 
49 
50  bool m_loaded;
51 
53  std::string m_file;
54 
56  ALuint m_buffer;
57 
60 
62  float m_rolloff;
63 
65  float m_gain;
66 
68  float m_max_dist;
69 
71  float m_duration;
72 
73  bool loadVorbisBuffer(const std::string &name, ALuint buffer);
74 
75 public:
76 
77  SFXBuffer(const std::string& file,
78  bool positional,
79  float rolloff,
80  float max_width,
81  float gain);
82 
83  SFXBuffer(const std::string& file,
84  const XMLNode* node);
85  ~SFXBuffer()
86  {
87  } // ~SFXBuffer
88 
89 
90  bool load();
91  void unload();
92 
93  // ------------------------------------------------------------------------
95  bool isLoaded() const { return m_loaded; }
96  // ------------------------------------------------------------------------
98  ALuint getBufferID() const { return m_buffer; }
99  // ------------------------------------------------------------------------
101  bool isPositional() const { return m_positional; }
102  // ------------------------------------------------------------------------
104  float getRolloff() const { return m_rolloff; }
105  // ------------------------------------------------------------------------
107  float getGain() const { return m_gain; }
108  // ------------------------------------------------------------------------
110  float getMaxDist() const { return m_max_dist; }
111  // ------------------------------------------------------------------------
113  const std::string& getFileName() const { return m_file; }
114  // ------------------------------------------------------------------------
116  void setPositional(bool positional) { m_positional = positional; }
117  // ------------------------------------------------------------------------
119  float getDuration() const { return m_duration; }
120 
121 }; // class SFXBuffer
122 
123 
124 #endif // HEADER_SFX_BUFFER_HPP
125 
void setPositional(bool positional)
Sets if this buffer is positional or not.
Definition: sfx_buffer.hpp:116
float getGain() const
Returns the gain for this sfx.
Definition: sfx_buffer.hpp:107
bool isPositional() const
Returns if the buffer is positional.
Definition: sfx_buffer.hpp:101
float m_gain
The volume gain value.
Definition: sfx_buffer.hpp:65
ALuint m_buffer
The openal buffer id.
Definition: sfx_buffer.hpp:56
ALuint getBufferID() const
Only returns a valid buffer if isLoaded() returned true.
Definition: sfx_buffer.hpp:98
bool isLoaded() const
Definition: sfx_buffer.hpp:95
The buffer (data) for one kind of sound effects.
Definition: sfx_buffer.hpp:43
float getMaxDist() const
Returns the maximum distance this sfx can be heard.
Definition: sfx_buffer.hpp:110
void unload()
Frees the loaded buffer.
Definition: sfx_buffer.cpp:128
std::string m_file
The file that contains the OGG audio data.
Definition: sfx_buffer.hpp:53
float m_rolloff
The roll-off value.
Definition: sfx_buffer.hpp:62
float getRolloff() const
Returns the rolloff value of this buffer.
Definition: sfx_buffer.hpp:104
bool m_positional
If the sound is positional.
Definition: sfx_buffer.hpp:59
bool m_loaded
Whether the contents of the file was loaded.
Definition: sfx_buffer.hpp:50
utility class used to parse XML files
Definition: xml_node.hpp:47
float m_duration
Duration of the sfx.
Definition: sfx_buffer.hpp:71
float m_max_dist
Maximum distance the sfx can be heard.
Definition: sfx_buffer.hpp:68
bool loadVorbisBuffer(const std::string &name, ALuint buffer)
Load a vorbis file into an OpenAL buffer based on a routine by Peter Mulholland, used with permission...
Definition: sfx_buffer.cpp:148
bool load()
load the buffer from file into OpenAL.
Definition: sfx_buffer.cpp:89
The base class for sound effects.
Definition: sfx_base.hpp:42
float getDuration() const
Returns how long this buffer will play.
Definition: sfx_buffer.hpp:119
const std::string & getFileName() const
Returns the file name of this buffer.
Definition: sfx_buffer.hpp:113