15 #include "milesAudioStream.h" 16 #ifdef HAVE_RAD_MSS //[ 18 #include "milesAudioManager.h" 23 #undef miles_audio_debug 26 #define miles_audio_debug(x) \ 27 audio_debug("MilesAudioStream \""<<get_name()<<"\" "<< x ) 29 #define miles_audio_debug(x) ((void)0) 38 MilesAudioStream(MilesAudioManager *manager,
const string &file_name,
40 MilesAudioSound(manager, file_name),
54 miles_audio_debug(
"~MilesAudioStream()");
57 miles_audio_debug(
"~MilesAudioStream() done");
65 void MilesAudioStream::
67 miles_audio_debug(
"play()");
70 _manager->starting_sound(
this);
73 GlobalMilesManager *mgr = GlobalMilesManager::get_global_ptr();
74 _stream = AIL_open_stream(mgr->_digital_driver, _path.c_str(), 0);
76 milesAudio_cat.warning()
77 <<
"Could not play " << _file_name <<
": too many open streams\n";
80 AIL_set_stream_user_data(_stream, 0, (SINTa)
this);
81 AIL_register_stream_callback(_stream, finish_callback);
86 AIL_pause_stream(_stream, 1);
87 _manager->stop_service_stream(_stream);
91 nassertv(_stream != 0);
92 HSAMPLE sample = AIL_stream_sample_handle(_stream);
93 nassertv(sample != 0);
95 _original_playback_rate = AIL_sample_playback_rate(sample);
99 AIL_set_stream_loop_count(_stream, _loop_count);
101 AIL_start_stream(_stream);
102 if (_got_start_time) {
105 do_set_time(_start_time);
108 if (miles_audio_panda_threads) {
109 AIL_auto_service_stream(_stream, 0);
110 _manager->start_service_stream(_stream);
112 AIL_auto_service_stream(_stream, 1);
115 _got_start_time =
false;
119 audio_debug(
" paused "<<_file_name );
129 void MilesAudioStream::
131 if (_manager == (MilesAudioManager *)NULL) {
134 miles_audio_debug(
"stop()");
135 _manager->stopping_sound(
this);
144 _manager->stop_service_stream(_stream);
146 AIL_pause_stream(_stream, 1);
147 AIL_close_stream(_stream);
157 PN_stdfloat MilesAudioStream::
160 if (_got_start_time) {
167 AIL_stream_ms_position(_stream, NULL, ¤t_ms);
168 PN_stdfloat time = PN_stdfloat(current_ms * 0.001f);
178 void MilesAudioStream::
179 set_volume(PN_stdfloat volume) {
183 HSAMPLE sample = AIL_stream_sample_handle(_stream);
184 nassertv(sample != 0);
186 volume *= _manager->get_volume();
189 F32 milesVolume = volume;
190 milesVolume = min(milesVolume, 1.0f);
191 milesVolume = max(milesVolume, 0.0f);
194 F32 milesBalance = (F32)((_balance + 1.0f) * 0.5f);
196 AIL_set_sample_volume_pan(sample, milesVolume, milesBalance);
205 void MilesAudioStream::
206 set_balance(PN_stdfloat balance_right) {
207 _balance = balance_right;
218 void MilesAudioStream::
219 set_play_rate(PN_stdfloat play_rate) {
220 _play_rate = play_rate;
223 HSAMPLE sample = AIL_stream_sample_handle(_stream);
224 nassertv(sample != 0);
226 play_rate *= _manager->get_play_rate();
229 S32 speed = (S32)(play_rate * (PN_stdfloat)_original_playback_rate);
230 AIL_set_sample_playback_rate(sample, speed);
231 audio_debug(
" play_rate for this wav or mp3 is now " << speed);
240 PN_stdfloat MilesAudioStream::
244 GlobalMilesManager *mgr = GlobalMilesManager::get_global_ptr();
245 ((MilesAudioStream *)
this)->_stream = AIL_open_stream(mgr->_digital_driver, _path.c_str(), 0);
249 AIL_stream_ms_position(_stream, &length_ms, NULL);
250 _length = (PN_stdfloat)length_ms * 0.001f;
262 AudioSound::SoundStatus MilesAudioStream::
265 return AudioSound::READY;
268 switch (AIL_stream_status(_stream)) {
271 return AudioSound::READY;
273 case SMP_PLAYINGBUTRELEASED:
274 return AudioSound::PLAYING;
276 return AudioSound::BAD;
286 void MilesAudioStream::
292 nassertv(_stream == 0);
294 if (_manager != (MilesAudioManager *)NULL) {
295 _manager->release_sound(
this);
306 void AILCALLBACK MilesAudioStream::
307 finish_callback(HSTREAM stream) {
308 MilesAudioStream *
self = (MilesAudioStream *)AIL_stream_user_data(stream, 0);
309 if (milesAudio_cat.is_debug()) {
310 milesAudio_cat.debug()
311 <<
"finished " << *
self <<
"\n";
313 if (self->_manager == (MilesAudioManager *)NULL) {
316 self->_manager->_sounds_finished =
true;
324 void MilesAudioStream::
325 do_set_time(PN_stdfloat time) {
326 nassertv(_stream != 0);
328 S32 time_ms = (S32)(1000.0f * time);
332 AIL_stream_ms_position(_stream, &length_ms, NULL);
333 time_ms = min(time_ms, length_ms);
335 AIL_set_stream_ms_position(_stream, time_ms);
void set_volume(PN_stdfloat volume=1.0)
0.0 to 1.0 scale of volume converted to Fmod's internal 0.0 to 255.0 scale.
The name of a file, such as a texture file or an Egg file.
void set_play_rate(PN_stdfloat play_rate=1.0f)
Sets the speed at which a sound plays back.
void set_active(bool active=true)
Sets whether the sound is marked "active".
TypeHandle is the identifier used to differentiate C++ class types.