00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __OPENAL_AUDIO_SOUND_H__
00019 #define __OPENAL_AUDIO_SOUND_H__
00020
00021 #include "pandabase.h"
00022
00023 #ifdef HAVE_OPENAL //[
00024
00025 #include "audioSound.h"
00026 #include "movieAudioCursor.h"
00027 #include "trueClock.h"
00028
00029
00030 #ifdef IS_OSX
00031 #include <OpenAL/al.h>
00032 #include <OpenAL/alc.h>
00033 #else
00034 #include <AL/al.h>
00035 #include <AL/alc.h>
00036 #endif
00037
00038 class EXPCL_OPENAL_AUDIO OpenALAudioSound : public AudioSound {
00039 friend class OpenALAudioManager;
00040
00041 public:
00042
00043 ~OpenALAudioSound();
00044
00045
00046
00047
00048
00049 void play();
00050 void stop();
00051
00052
00053
00054 void set_loop(bool loop=true);
00055 bool get_loop() const;
00056
00057
00058
00059 void set_loop_count(unsigned long loop_count=1);
00060 unsigned long get_loop_count() const;
00061
00062
00063
00064 void set_time(PN_stdfloat time=0.0);
00065 PN_stdfloat get_time() const;
00066
00067
00068
00069 void set_volume(PN_stdfloat volume=1.0);
00070 PN_stdfloat get_volume() const;
00071
00072
00073
00074
00075
00076 void set_balance(PN_stdfloat balance_right=0.0);
00077 PN_stdfloat get_balance() const;
00078
00079
00080
00081 void set_play_rate(PN_stdfloat play_rate=1.0f);
00082 PN_stdfloat get_play_rate() const;
00083
00084
00085 void set_active(bool active=true);
00086 bool get_active() const;
00087
00088
00089
00090
00091 void set_finished_event(const string& event);
00092 const string& get_finished_event() const;
00093
00094 const string &get_name() const;
00095
00096
00097 PN_stdfloat length() const;
00098
00099
00100
00101
00102 void set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz);
00103 void get_3d_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *pz, PN_stdfloat *vx, PN_stdfloat *vy, PN_stdfloat *vz);
00104
00105 void set_3d_min_distance(PN_stdfloat dist);
00106 PN_stdfloat get_3d_min_distance() const;
00107
00108 void set_3d_max_distance(PN_stdfloat dist);
00109 PN_stdfloat get_3d_max_distance() const;
00110
00111 void set_3d_drop_off_factor(PN_stdfloat factor);
00112 PN_stdfloat get_3d_drop_off_factor() const;
00113
00114 AudioSound::SoundStatus status() const;
00115
00116 void finished();
00117
00118 private:
00119 OpenALAudioSound(OpenALAudioManager* manager,
00120 MovieAudio *movie,
00121 bool positional,
00122 int mode);
00123 INLINE void set_calibrated_clock(double rtc, double t, double playrate);
00124 INLINE double get_calibrated_clock(double rtc) const;
00125 void correct_calibrated_clock(double rtc, double t);
00126 void cache_time(double rtc);
00127 void cleanup();
00128 void restart_stalled_audio();
00129 void delete_queued_buffers();
00130 ALuint make_buffer(int samples, int channels, int rate, unsigned char *data);
00131 void queue_buffer(ALuint buffer, int samples, int loop_index, double time_offset);
00132 int read_stream_data(int bytelen, unsigned char *data);
00133 void pull_used_buffers();
00134 void push_fresh_buffers();
00135 INLINE void require_sound_data();
00136 INLINE void release_sound_data();
00137
00138 private:
00139
00140 void do_stop();
00141
00142 PT(MovieAudio) _movie;
00143 OpenALAudioManager::SoundData *_sd;
00144
00145 struct QueuedBuffer {
00146 ALuint _buffer;
00147 int _samples;
00148 int _loop_index;
00149 double _time_offset;
00150 };
00151
00152 int _playing_loops;
00153 PN_stdfloat _playing_rate;
00154
00155 pdeque<QueuedBuffer> _stream_queued;
00156 int _loops_completed;
00157
00158 ALuint _source;
00159 PT(OpenALAudioManager) _manager;
00160
00161 PN_stdfloat _volume;
00162 PN_stdfloat _balance;
00163 PN_stdfloat _play_rate;
00164
00165 bool _positional;
00166 ALfloat _location[3];
00167 ALfloat _velocity[3];
00168
00169 PN_stdfloat _min_dist;
00170 PN_stdfloat _max_dist;
00171 PN_stdfloat _drop_off_factor;
00172
00173 double _length;
00174 int _loop_count;
00175
00176 int _desired_mode;
00177
00178
00179
00180
00181 double _calibrated_clock_base;
00182 double _calibrated_clock_scale;
00183 double _calibrated_clock_decavg;
00184
00185
00186 double _start_time;
00187
00188
00189
00190
00191
00192 PN_stdfloat _current_time;
00193
00194
00195
00196
00197 string _finished_event;
00198
00199 Filename _basename;
00200
00201
00202
00203
00204
00205 bool _active;
00206 bool _paused;
00207
00208 public:
00209 static TypeHandle get_class_type() {
00210 return _type_handle;
00211 }
00212 static void init_type() {
00213 AudioSound::init_type();
00214 register_type(_type_handle, "OpenALAudioSound", AudioSound::get_class_type());
00215 }
00216 virtual TypeHandle get_type() const {
00217 return get_class_type();
00218 }
00219 virtual TypeHandle force_init_type() {
00220 init_type();
00221 return get_class_type();
00222 }
00223
00224 private:
00225 static TypeHandle _type_handle;
00226
00227
00228
00229
00230 };
00231
00232 #include "openalAudioSound.I"
00233
00234 #endif //]
00235
00236 #endif