Panda3D
 All Classes Functions Variables Enumerations
audioManager.h
1 // Filename: audioManager.h
2 // Created by: skyler (June 6, 2001)
3 // Prior system by: cary
4 //
5 ////////////////////////////////////////////////////////////////////
6 //
7 // PANDA 3D SOFTWARE
8 // Copyright (c) Carnegie Mellon University. All rights reserved.
9 //
10 // All use of this software is subject to the terms of the revised BSD
11 // license. You should have received a copy of this license along
12 // with this source code in a file named "LICENSE."
13 //
14 ////////////////////////////////////////////////////////////////////
15 
16 #ifndef __AUDIO_MANAGER_H__
17 #define __AUDIO_MANAGER_H__
18 
19 #include "config_audio.h"
20 #include "audioSound.h"
21 #include "luse.h"
22 #include "filterProperties.h"
23 #include "movieAudio.h"
24 #include "atomicAdjust.h"
25 
26 typedef AudioManager *Create_AudioManager_proc();
27 
28 
29 class EXPCL_PANDA_AUDIO AudioManager : public TypedReferenceCount {
30 PUBLISHED:
31 
32  enum SpeakerModeCategory {
33  // These enumerants line up one-to-one
34  // with the FMOD SPEAKERMODE enumerants.
35  SPEAKERMODE_raw,
36  SPEAKERMODE_mono,
37  SPEAKERMODE_stereo,
38  SPEAKERMODE_quad,
39  SPEAKERMODE_surround,
40  SPEAKERMODE_5point1,
41  SPEAKERMODE_7point1,
42  SPEAKERMODE_max,
43  SPEAKERMODE_COUNT
44  };
45 
46 
47  enum SpeakerId {
48  SPK_none,
49  SPK_frontleft,
50  SPK_frontright,
51  SPK_center,
52  SPK_sub,
53  SPK_backleft,
54  SPK_backright,
55  SPK_sideleft,
56  SPK_sideright,
57  SPK_COUNT,
58  };
59 
60  enum StreamMode {
61  SM_heuristic,
62  SM_sample,
63  SM_stream,
64  };
65 
66  virtual int getSpeakerSetup();
67  virtual void setSpeakerSetup(SpeakerModeCategory cat);
68  virtual bool configure_filters(FilterProperties *config);
69 
70  // Create an AudioManager for each category of sounds you have.
71  // E.g.
72  // MySoundEffects = create_AudioManager::AudioManager();
73  // MyMusicManager = create_AudioManager::AudioManager();
74  // ...
75  // my_sound = MySoundEffects.get_sound("neatSfx.mp3");
76  // my_music = MyMusicManager.get_sound("introTheme.mid");
77 
78  static PT(AudioManager) create_AudioManager();
79  virtual ~AudioManager();
80 
81  virtual void shutdown();
82 
83  // If you're interested in knowing whether this audio manager
84  // is valid, here's the call to do it. It is not necessary
85  // to check whether the audio manager is valid before making other
86  // calls. You are free to use an invalid sound manager, you
87  // may get silent sounds from it though. The sound manager and
88  // the sounds it creates should not crash the application even
89  // when the objects are not valid.
90  virtual bool is_valid() = 0;
91 
92  // Get a sound:
93  virtual PT(AudioSound) get_sound(const string& file_name, bool positional = false, int mode=SM_heuristic) = 0;
94  virtual PT(AudioSound) get_sound(MovieAudio *source, bool positional = false, int mode=SM_heuristic) = 0;
95 
96  PT(AudioSound) get_null_sound();
97 
98  // Tell the AudioManager there is no need to keep this one cached.
99  // This doesn't break any connection between AudioSounds that have
100  // already given by get_sound() from this manager. It's
101  // only affecting whether the AudioManager keeps a copy of the sound
102  // in its pool/cache.
103  virtual void uncache_sound(const string& file_name) = 0;
104  virtual void clear_cache() = 0;
105  virtual void set_cache_limit(unsigned int count) = 0;
106  virtual unsigned int get_cache_limit() const = 0;
107 
108  // Control volume:
109  // FYI:
110  // If you start a sound with the volume off and turn the volume
111  // up later, you'll hear the sound playing at that late point.
112  // 0 = minimum; 1.0 = maximum.
113  // inits to 1.0.
114  virtual void set_volume(PN_stdfloat volume) = 0;
115  virtual PN_stdfloat get_volume() const = 0;
116 
117  // Turn the manager on or off.
118  // If you play a sound while the manager is inactive, it won't start.
119  // If you deactivate the manager while sounds are playing, they'll
120  // stop.
121  // If you activate the manager while looping sounds are playing
122  // (those that have a loop_count of zero),
123  // they will start playing from the beginning of their loop.
124  // inits to true.
125  virtual void set_active(bool flag) = 0;
126  virtual bool get_active() const = 0;
127 
128  // This controls the number of sounds that you allow at once. This
129  // is more of a user choice -- it avoids talk over and the creation
130  // of a cacophony.
131  // It can also be used to help performance.
132  // 0 == unlimited.
133  // 1 == mutually exclusive (one sound at a time). Which is an example of:
134  // n == allow n sounds to be playing at the same time.
135  virtual void set_concurrent_sound_limit(unsigned int limit = 0) = 0;
136  virtual unsigned int get_concurrent_sound_limit() const = 0;
137 
138  // This is likely to be a utility function for the concurrent_sound_limit
139  // options. It is exposed as an API, because it's reasonable that it
140  // may be useful to be here. It reduces the number of concurrently
141  // playing sounds to count by some implementation specific means.
142  // If the number of sounds currently playing is at or below count then
143  // there is no effect.
144  virtual void reduce_sounds_playing_to(unsigned int count) = 0;
145 
146  // Stop playback on all sounds managed by this manager.
147  // This is effectively the same as reduce_sounds_playing_to(0), but
148  // this call may be for efficient on some implementations.
149  virtual void stop_all_sounds() = 0;
150 
151  // This should be called every frame. Failure to call could
152  // cause problems.
153  virtual void update();
154 
155  // This controls the "set of ears" that listens to 3D spacialized sound
156  // px, py, pz are position coordinates.
157  // vx, vy, vz are a velocity vector in UNITS PER SECOND (default: meters).
158  // fx, fy and fz are the respective components of a unit forward-vector
159  // ux, uy and uz are the respective components of a unit up-vector
160  virtual void audio_3d_set_listener_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz,
161  PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz,
162  PN_stdfloat fx, PN_stdfloat fy, PN_stdfloat fz,
163  PN_stdfloat ux, PN_stdfloat uy, PN_stdfloat uz);
164  virtual void audio_3d_get_listener_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *pz,
165  PN_stdfloat *vx, PN_stdfloat *vy, PN_stdfloat *vz,
166  PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz,
167  PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
168 
169  // Control the "relative scale that sets the distance factor" units for 3D spacialized audio. Default is 1.0
170  // Fmod uses meters internally, so give a float in Units-per meter
171  // Don't know what Miles uses.
172  // Default is 1.0 which is adjust in panda to be feet.
173  virtual void audio_3d_set_distance_factor(PN_stdfloat factor);
174  virtual PN_stdfloat audio_3d_get_distance_factor() const;
175 
176  // Control the presence of the Doppler effect. Default is 1.0
177  // Exaggerated Doppler, use >1.0
178  // Diminshed Doppler, use <1.0
179  virtual void audio_3d_set_doppler_factor(PN_stdfloat factor);
180  virtual PN_stdfloat audio_3d_get_doppler_factor() const;
181 
182  // Exaggerate or diminish the effect of distance on sound. Default is 1.0
183  // Valid range is 0 to 10
184  // Faster drop off, use >1.0
185  // Slower drop off, use <1.0
186  virtual void audio_3d_set_drop_off_factor(PN_stdfloat factor);
187  virtual PN_stdfloat audio_3d_get_drop_off_factor() const;
188 
189  static Filename get_dls_pathname();
190 
191  virtual void output(ostream &out) const;
192  virtual void write(ostream &out) const;
193 
194  // set_speaker_configuration is a Miles only method.
195  virtual void set_speaker_configuration(LVecBase3 *speaker1, LVecBase3 *speaker2=NULL, LVecBase3 *speaker3=NULL, LVecBase3 *speaker4=NULL, LVecBase3 *speaker5=NULL, LVecBase3 *speaker6=NULL, LVecBase3 *speaker7=NULL, LVecBase3 *speaker8=NULL, LVecBase3 *speaker9=NULL);
196 
197 public:
198  static void register_AudioManager_creator(Create_AudioManager_proc* proc);
199 
200 protected:
201  friend class AudioSound;
202 
203  // Avoid adding data members (instance variables) to this mostly abstract
204  // base class. This allows implementors of various sound systems the
205  // best flexibility.
206 
207  static Create_AudioManager_proc* _create_AudioManager;
208  AtomicAdjust::Pointer _null_sound;
209 
210  AudioManager();
211 
212 public:
213  static TypeHandle get_class_type() {
214  return _type_handle;
215  }
216  static void init_type() {
217  TypedReferenceCount::init_type();
218  register_type(_type_handle, "AudioManager",
219  TypedReferenceCount::get_class_type());
220  }
221  virtual TypeHandle get_type() const {
222  return get_class_type();
223  }
224  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
225 
226 private:
227  static TypeHandle _type_handle;
228 };
229 
230 inline ostream &
231 operator << (ostream &out, const AudioManager &mgr) {
232  mgr.output(out);
233  return out;
234 }
235 
236 #include "audioManager.I"
237 
238 #endif /* __AUDIO_MANAGER_H__ */
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Stores a configuration for a set of audio DSP filters.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A MovieAudio is actually any source that provides a sequence of audio samples.
Definition: movieAudio.h:48