Panda3D
|
00001 // Filename: openalAudioSound.I 00002 // Created by: Ben Buchwald <bb2@alumni.cmu.edu> 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 //////////////////////////////////////////////////////////////////// 00016 // Function: OpenALAudioSound::set_calibrated_clock 00017 // Access: public 00018 // Description: Sets the sound's calibrated clock. 00019 // 00020 // OpenAL is not very accurate at reporting how much 00021 // time has elapsed within a buffer. However, it does 00022 // accurately report when it has finished playing a 00023 // buffer. So we use a hybrid clock algorithm. 00024 // When OpenAL is in the middle of a buffer, 00025 // we use a real-time-clock to estimate how far the 00026 // sound has gotten. Each time OpenAL reaches the end 00027 // of a buffer (which it does every 1/4 second or so), 00028 // we calibrate our real-time-clock by speeding it up 00029 // or slowing it down. 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE void OpenALAudioSound:: 00032 set_calibrated_clock(double rtc, double t, double accel) { 00033 _calibrated_clock_scale = _playing_rate * accel; 00034 _calibrated_clock_base = rtc - (t / _calibrated_clock_scale); 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: OpenALAudioSound::get_calibrated_clock 00039 // Access: public 00040 // Description: Returns the value of the calibrated clock. 00041 //////////////////////////////////////////////////////////////////// 00042 INLINE double OpenALAudioSound:: 00043 get_calibrated_clock(double rtc) const { 00044 return (rtc - _calibrated_clock_base) * _calibrated_clock_scale; 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: OpenALAudioSound::require_sound_data 00049 // Access: Private 00050 // Description: Makes sure the sound data record is present, 00051 // and if not, obtains it. 00052 //////////////////////////////////////////////////////////////////// 00053 void OpenALAudioSound:: 00054 require_sound_data() { 00055 if (_sd==0) { 00056 _sd = _manager->get_sound_data(_movie, _desired_mode); 00057 if (_sd==0) { 00058 audio_error("Could not open audio " << _movie->get_filename()); 00059 cleanup(); 00060 } 00061 } 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: OpenALAudioSound::release_sound_data 00066 // Access: Private 00067 // Description: Checks if the sound data record is present and 00068 // releasable, and if so, releases it. 00069 //////////////////////////////////////////////////////////////////// 00070 void OpenALAudioSound:: 00071 release_sound_data() { 00072 if ((_sd!=0) && (!_movie->get_filename().empty())) { 00073 _manager->decrement_client_count(_sd); 00074 _sd = 0; 00075 } 00076 }