16 #ifdef HAVE_RAD_MSS //[ 23 #undef miles_audio_debug 26 #define miles_audio_debug(x) \ 27 audio_debug("MilesAudioSequence \""<<get_name()<<"\" "<< x ) 29 #define miles_audio_debug(x) ((void)0) 36 MilesAudioSequence(MilesAudioManager *manager, MilesAudioManager::SoundData *sd,
37 const std::string &file_name) :
38 MilesAudioSound(manager, file_name),
41 nassertv(sd !=
nullptr);
42 audio_debug(
"MilesAudioSequence(manager=0x"<<(
void*)&manager
43 <<
", sd=0x"<<(
void*)sd<<
", file_name="<<file_name<<
")");
53 ~MilesAudioSequence() {
54 miles_audio_debug(
"~MilesAudioSequence()");
56 _manager->release_sound(
this);
57 miles_audio_debug(
"~MilesAudioSequence() done");
63 void MilesAudioSequence::
65 miles_audio_debug(
"play()");
69 if (_sd->_raw_data.empty()) {
70 milesAudio_cat.warning()
71 <<
"Could not play " << _file_name <<
": no data\n";
73 _manager->starting_sound(
this);
74 nassertv(_sequence == 0);
76 GlobalMilesManager *mgr = GlobalMilesManager::get_global_ptr();
77 if (!mgr->get_sequence(_sequence, _sequence_index,
this)){
78 milesAudio_cat.warning()
79 <<
"Could not play " << _file_name <<
": too many open sequences\n";
82 AIL_init_sequence(_sequence, &_sd->_raw_data[0], 0);
83 AIL_set_sequence_user_data(_sequence, 0, (SINTa)
this);
84 AIL_register_sequence_callback(_sequence, finish_callback);
87 set_play_rate(_play_rate);
88 AIL_set_sequence_loop_count(_sequence, _loop_count);
90 if (_got_start_time) {
91 do_set_time(_start_time);
92 AIL_resume_sequence(_sequence);
94 AIL_start_sequence(_sequence);
98 _got_start_time =
false;
102 audio_debug(
" paused "<<_file_name );
110 void MilesAudioSequence::
112 miles_audio_debug(
"stop()");
113 _manager->stopping_sound(
this);
121 if (_sequence != 0) {
122 AIL_end_sequence(_sequence);
124 GlobalMilesManager *mgr = GlobalMilesManager::get_global_ptr();
125 mgr->release_sequence(_sequence_index,
this);
135 PN_stdfloat MilesAudioSequence::
137 if (_sequence == 0) {
138 if (_got_start_time) {
145 AIL_sequence_ms_position(_sequence,
nullptr, ¤t_ms);
146 PN_stdfloat time = PN_stdfloat(current_ms * 0.001f);
154 void MilesAudioSequence::
155 set_volume(PN_stdfloat volume) {
156 miles_audio_debug(
"set_volume(volume="<<volume<<
")");
164 if (_sequence != 0) {
165 volume *= _manager->get_volume();
168 S32 milesVolume = (S32)(volume * 127.0f);
169 milesVolume = std::min(milesVolume, 127);
170 milesVolume = std::max(milesVolume, 0);
172 AIL_set_sequence_volume(_sequence, milesVolume, 0);
179 void MilesAudioSequence::
180 set_balance(PN_stdfloat balance_right) {
181 miles_audio_debug(
"set_balance(balance_right="<<balance_right<<
")");
182 _balance = balance_right;
190 void MilesAudioSequence::
191 set_play_rate(PN_stdfloat play_rate) {
192 miles_audio_debug(
"set_play_rate(play_rate="<<play_rate<<
")");
195 _play_rate = play_rate;
197 if (_sequence != 0) {
198 play_rate *= _manager->get_play_rate();
200 S32 percent = (S32)(play_rate * 100.0f);
201 AIL_set_sequence_tempo(_sequence, percent, 0);
208 PN_stdfloat MilesAudioSequence::
210 if (_sequence == 0) {
213 if (!_sd->_has_length) {
216 ((MilesAudioSequence *)
this)->determine_length();
219 return _sd->get_length();
224 AIL_sequence_ms_position(_sequence, &length_ms,
nullptr);
225 PN_stdfloat time = (PN_stdfloat)length_ms * 0.001f;
232 AudioSound::SoundStatus MilesAudioSequence::
234 if (_sequence == 0) {
235 return AudioSound::READY;
237 switch (AIL_sequence_status(_sequence)) {
241 return AudioSound::READY;
244 case SEQ_PLAYINGBUTRELEASED:
245 return AudioSound::PLAYING;
248 return AudioSound::BAD;
256 void MilesAudioSequence::
265 void MilesAudioSequence::
275 void AILCALLBACK MilesAudioSequence::
276 finish_callback(HSEQUENCE sequence) {
277 MilesAudioSequence *
self = (MilesAudioSequence *)AIL_sequence_user_data(sequence, 0);
278 if (milesAudio_cat.is_debug()) {
279 milesAudio_cat.debug()
280 <<
"finished " << *
self <<
"\n";
282 self->_manager->_sounds_finished =
true;
288 void MilesAudioSequence::
289 do_set_time(PN_stdfloat time) {
290 miles_audio_debug(
"do_set_time(time="<<time<<
")");
292 nassertv(_sequence != 0);
294 S32 time_ms = (S32)(1000.0f * time);
298 AIL_sequence_ms_position(_sequence, &length_ms,
nullptr);
299 time_ms = std::min(time_ms, length_ms);
301 AIL_set_sequence_ms_position(_sequence, time_ms);
309 void MilesAudioSequence::
311 nassertv(_sequence == 0);
313 GlobalMilesManager *mgr = GlobalMilesManager::get_global_ptr();
314 if (!mgr->get_sequence(_sequence, _sequence_index,
this)){
315 milesAudio_cat.warning()
316 <<
"Could not determine length of " << _file_name <<
": too many open sequences\n";
319 AIL_init_sequence(_sequence, &_sd->_raw_data[0], 0);
321 AIL_sequence_ms_position(_sequence, &length_ms,
nullptr);
322 PN_stdfloat time = (PN_stdfloat)length_ms * 0.001f;
323 mgr->release_sequence(_sequence_index,
this);
327 _sd->set_length(time);
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.