13#ifndef __OPENAL_AUDIO_MANAGER_H__
14#define __OPENAL_AUDIO_MANAGER_H__
26#ifdef HAVE_OPENAL_FRAMEWORK
27 #include <OpenAL/al.h>
28 #include <OpenAL/alc.h>
36extern void al_audio_errcheck(
const char *context);
37extern void alc_audio_errcheck(
const char *context,ALCdevice* device);
39class EXPCL_OPENAL_AUDIO OpenALAudioManager :
public AudioManager {
42 friend class OpenALAudioSound;
43 friend class OpenALSoundData;
48 virtual ~OpenALAudioManager();
54 virtual PT(AudioSound) get_sound(
const Filename &,
bool positional =
false,
int mode=SM_heuristic);
55 virtual PT(AudioSound) get_sound(
MovieAudio *sound,
bool positional =
false,
int mode=SM_heuristic);
60 virtual unsigned int get_cache_limit()
const;
69 virtual bool get_active()
const;
78 PN_stdfloat vx, PN_stdfloat xy, PN_stdfloat xz,
79 PN_stdfloat fx, PN_stdfloat fy, PN_stdfloat fz,
80 PN_stdfloat ux, PN_stdfloat uy, PN_stdfloat uz);
83 PN_stdfloat *vx, PN_stdfloat *vy, PN_stdfloat *vz,
84 PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz,
85 PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
101 virtual PN_stdfloat audio_3d_get_doppler_factor()
const;
106 virtual PN_stdfloat audio_3d_get_drop_off_factor()
const;
108 virtual void set_concurrent_sound_limit(
unsigned int limit = 0);
109 virtual unsigned int get_concurrent_sound_limit()
const;
110 virtual void reduce_sounds_playing_to(
unsigned int count);
117 std::string select_audio_device();
119 void make_current()
const;
124 SoundData *get_sound_data(
MovieAudio *source,
int mode);
127 void release_sound(OpenALAudioSound* audioSound);
128 void increment_client_count(SoundData *sd);
129 void decrement_client_count(SoundData *sd);
130 void discard_excess_cache(
int limit);
132 void delete_buffer(ALuint buffer);
134 void starting_sound(OpenALAudioSound* audio);
135 void stopping_sound(OpenALAudioSound* audio);
148 ExpirationQueue _expiring_samples;
149 ExpirationQueue _expiring_streams;
166 OpenALAudioManager* _manager;
174 ExpirationQueue::iterator _expire;
178 typedef phash_map<std::string, SoundData *> SampleCache;
179 SampleCache _sample_cache;
181 typedef phash_set<PT(OpenALAudioSound)> SoundsPlaying;
182 SoundsPlaying _sounds_playing;
184 typedef phash_set<OpenALAudioSound *> AllSounds;
185 AllSounds _all_sounds;
190 PN_stdfloat _play_rate;
192 bool _cleanup_required;
194 static int _active_managers;
195 static bool _openal_active;
196 unsigned int _concurrent_sound_limit;
200 typedef pset<OpenALAudioManager *> Managers;
201 static Managers *_managers;
203 static ALCdevice* _device;
204 static ALCcontext* _context;
207 typedef pset<ALuint > SourceCache;
208 static SourceCache *_al_sources;
210 PN_stdfloat _distance_factor;
211 PN_stdfloat _doppler_factor;
212 PN_stdfloat _drop_off_factor;
214 ALfloat _position[3];
215 ALfloat _velocity[3];
216 ALfloat _forward_up[6];
224 static void init_type() {
225 AudioManager::init_type();
226 register_type(_type_handle,
"OpenALAudioManager", AudioManager::get_class_type());
229 return get_class_type();
233 return get_class_type();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void shutdown()
Call this at exit time to shut down the audio system.
virtual void update()
Must be called every frame.
The name of a file, such as a texture file or an Egg file.
A MovieAudio is actually any source that provides a sequence of audio samples.
A MovieAudio is actually any source that provides a sequence of audio samples.
virtual void set_active(bool)
Turn on/off Warning: not implemented.
virtual void audio_3d_get_listener_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *pz, PN_stdfloat *vx, PN_stdfloat *vy, PN_stdfloat *vz, PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz, PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz)
Get position of the "ear" that picks up 3d sounds.
virtual void set_cache_limit(unsigned int count)
Set the number of sounds that the cache can hold.
virtual void uncache_sound(const Filename &)
Deletes a sample from the expiration queues.
virtual void stop_all_sounds()
Stop playback on all sounds managed by this manager.
virtual bool is_valid()
This is mostly for debugging, but it it could be used to detect errors in a release build if you don'...
virtual PN_stdfloat audio_3d_get_distance_factor() const
Get value in units per meter.
virtual void clear_cache()
Clear out the sound cache.
virtual PN_stdfloat get_volume() const
Gets listener gain.
void set_play_rate(PN_stdfloat play_rate)
set the overall play rate
virtual void audio_3d_set_doppler_factor(PN_stdfloat factor)
Exaggerates or diminishes the Doppler effect.
virtual void audio_3d_set_distance_factor(PN_stdfloat factor)
Set value in units per meter WARNING: OpenAL has no distance factor but we use this as a scale on the...
PN_stdfloat get_play_rate() const
get the overall speed/pitch/play rate
virtual void audio_3d_set_drop_off_factor(PN_stdfloat factor)
Control the effect distance has on audability.
virtual void audio_3d_set_listener_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx, PN_stdfloat xy, PN_stdfloat xz, PN_stdfloat fx, PN_stdfloat fy, PN_stdfloat fz, PN_stdfloat ux, PN_stdfloat uy, PN_stdfloat uz)
Set position of the "ear" that picks up 3d sounds NOW LISTEN UP!
virtual void set_volume(PN_stdfloat)
Sets listener gain.
TypeHandle is the identifier used to differentiate C++ class types.
This is our own Panda specialization on the default STL list.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EXPCL_OPENAL_AUDIO AudioManager * Create_OpenALAudioManager()
Factory Function.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...