15 #ifdef HAVE_RAD_MSS //[ 22 #undef miles_audio_debug 25 #define miles_audio_debug(x) \ 26 audio_debug("MilesAudioStream \""<<get_name()<<"\" "<< x ) 28 #define miles_audio_debug(x) ((void)0) 35 MilesAudioStream(MilesAudioManager *manager,
const std::string &file_name,
37 MilesAudioSound(manager, file_name),
49 miles_audio_debug(
"~MilesAudioStream()");
52 miles_audio_debug(
"~MilesAudioStream() done");
58 void MilesAudioStream::
60 miles_audio_debug(
"play()");
63 _manager->starting_sound(
this);
66 GlobalMilesManager *mgr = GlobalMilesManager::get_global_ptr();
67 _stream = AIL_open_stream(mgr->_digital_driver, _path.c_str(), 0);
69 milesAudio_cat.warning()
70 <<
"Could not play " << _file_name <<
": too many open streams\n";
73 AIL_set_stream_user_data(_stream, 0, (SINTa)
this);
74 AIL_register_stream_callback(_stream, finish_callback);
78 AIL_pause_stream(_stream, 1);
79 _manager->stop_service_stream(_stream);
83 nassertv(_stream != 0);
84 HSAMPLE sample = AIL_stream_sample_handle(_stream);
85 nassertv(sample != 0);
87 _original_playback_rate = AIL_sample_playback_rate(sample);
89 set_play_rate(_play_rate);
91 AIL_set_stream_loop_count(_stream, _loop_count);
93 AIL_start_stream(_stream);
94 if (_got_start_time) {
97 do_set_time(_start_time);
100 if (miles_audio_panda_threads) {
101 AIL_auto_service_stream(_stream, 0);
102 _manager->start_service_stream(_stream);
104 AIL_auto_service_stream(_stream, 1);
107 _got_start_time =
false;
111 audio_debug(
" paused "<<_file_name );
119 void MilesAudioStream::
121 if (_manager ==
nullptr) {
124 miles_audio_debug(
"stop()");
125 _manager->stopping_sound(
this);
134 _manager->stop_service_stream(_stream);
136 AIL_pause_stream(_stream, 1);
137 AIL_close_stream(_stream);
145 PN_stdfloat MilesAudioStream::
148 if (_got_start_time) {
155 AIL_stream_ms_position(_stream,
nullptr, ¤t_ms);
156 PN_stdfloat time = PN_stdfloat(current_ms * 0.001f);
164 void MilesAudioStream::
165 set_volume(PN_stdfloat volume) {
169 HSAMPLE sample = AIL_stream_sample_handle(_stream);
170 nassertv(sample != 0);
172 volume *= _manager->get_volume();
175 F32 milesVolume = volume;
176 milesVolume = std::min(milesVolume, 1.0f);
177 milesVolume = std::max(milesVolume, 0.0f);
180 F32 milesBalance = (F32)((_balance + 1.0f) * 0.5f);
182 AIL_set_sample_volume_pan(sample, milesVolume, milesBalance);
189 void MilesAudioStream::
190 set_balance(PN_stdfloat balance_right) {
191 _balance = balance_right;
200 void MilesAudioStream::
201 set_play_rate(PN_stdfloat play_rate) {
202 _play_rate = play_rate;
205 HSAMPLE sample = AIL_stream_sample_handle(_stream);
206 nassertv(sample != 0);
208 play_rate *= _manager->get_play_rate();
211 S32 speed = (S32)(play_rate * (PN_stdfloat)_original_playback_rate);
212 AIL_set_sample_playback_rate(sample, speed);
213 audio_debug(
" play_rate for this wav or mp3 is now " << speed);
220 PN_stdfloat MilesAudioStream::
224 GlobalMilesManager *mgr = GlobalMilesManager::get_global_ptr();
225 ((MilesAudioStream *)
this)->_stream = AIL_open_stream(mgr->_digital_driver, _path.c_str(), 0);
229 AIL_stream_ms_position(_stream, &length_ms,
nullptr);
230 _length = (PN_stdfloat)length_ms * 0.001f;
240 AudioSound::SoundStatus MilesAudioStream::
243 return AudioSound::READY;
246 switch (AIL_stream_status(_stream)) {
249 return AudioSound::READY;
251 case SMP_PLAYINGBUTRELEASED:
252 return AudioSound::PLAYING;
254 return AudioSound::BAD;
261 void MilesAudioStream::
267 nassertv(_stream == 0);
269 if (_manager !=
nullptr) {
270 _manager->release_sound(
this);
279 void AILCALLBACK MilesAudioStream::
280 finish_callback(HSTREAM stream) {
281 MilesAudioStream *
self = (MilesAudioStream *)AIL_stream_user_data(stream, 0);
282 if (milesAudio_cat.is_debug()) {
283 milesAudio_cat.debug()
284 <<
"finished " << *
self <<
"\n";
286 if (self->_manager ==
nullptr) {
289 self->_manager->_sounds_finished =
true;
295 void MilesAudioStream::
296 do_set_time(PN_stdfloat time) {
297 nassertv(_stream != 0);
299 S32 time_ms = (S32)(1000.0f * time);
303 AIL_stream_ms_position(_stream, &length_ms,
nullptr);
304 time_ms = std::min(time_ms, length_ms);
306 AIL_set_stream_ms_position(_stream, time_ms);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.