|
|
@@ -41,6 +41,8 @@ FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
|
|
|
audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: " << file_name );
|
|
|
|
|
|
_active = manager->get_active();
|
|
|
+ _paused = false;
|
|
|
+ _start_time = 0.0;
|
|
|
|
|
|
//Local Variables that are needed.
|
|
|
FMOD_RESULT result;
|
|
|
@@ -152,7 +154,7 @@ FmodAudioSound::
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void FmodAudioSound::
|
|
|
play() {
|
|
|
- set_time(0.0);
|
|
|
+ start_playing();
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
@@ -192,6 +194,7 @@ stop() {
|
|
|
}
|
|
|
fmod_audio_errcheck("_channel->stop()", result);
|
|
|
}
|
|
|
+ _start_time = 0.0;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -283,10 +286,72 @@ get_loop_count() const {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: FmodAudioSound::set_time
|
|
|
// Access: public
|
|
|
-// Description: Starts playing from the specified location.
|
|
|
+// Description: Sets the time at which the next play() operation will
|
|
|
+// begin. If we are already playing, skips to that time
|
|
|
+// immediatey.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void FmodAudioSound::
|
|
|
set_time(float start_time) {
|
|
|
+ _start_time = start_time;
|
|
|
+
|
|
|
+ if (status() == PLAYING) {
|
|
|
+ // Already playing; skip to the indicated time.
|
|
|
+ start_playing();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: FmodAudioSound::get_time
|
|
|
+// Access: public
|
|
|
+// Description: Gets the play position within the sound
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+float FmodAudioSound::
|
|
|
+get_time() const {
|
|
|
+ FMOD_RESULT result;
|
|
|
+ unsigned int current_time;
|
|
|
+
|
|
|
+ if (_channel == 0) {
|
|
|
+ return 0.0f;
|
|
|
+ }
|
|
|
+
|
|
|
+ result = _channel->getPosition( ¤t_time , FMOD_TIMEUNIT_MS );
|
|
|
+ if (result == FMOD_ERR_INVALID_HANDLE) {
|
|
|
+ return 0.0f;
|
|
|
+ }
|
|
|
+ fmod_audio_errcheck("_channel->getPosition()", result);
|
|
|
+
|
|
|
+ return ((double)current_time) / 1000.0;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: FmodAudioSound::set_volume(float vol)
|
|
|
+// Access: public
|
|
|
+// Description: 0.0 to 1.0 scale of volume converted to Fmod's
|
|
|
+// internal 0.0 to 255.0 scale.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+void FmodAudioSound::
|
|
|
+set_volume(float vol) {
|
|
|
+ _volume = vol;
|
|
|
+ set_volume_on_channel();
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: FmodAudioSound::get_volume
|
|
|
+// Access: public
|
|
|
+// Description: Gets the current volume of a sound. 1 is Max. O is Min.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+float FmodAudioSound::
|
|
|
+get_volume() const {
|
|
|
+ return _volume;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: FmodAudioSound::start_playing
|
|
|
+// Access: Private
|
|
|
+// Description: Starts the sound playing at _start_time.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+void FmodAudioSound::
|
|
|
+start_playing() {
|
|
|
FMOD_RESULT result;
|
|
|
|
|
|
if (!_active) {
|
|
|
@@ -294,7 +359,7 @@ set_time(float start_time) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- int startTime = (int)(start_time * 1000);
|
|
|
+ int startTime = (int)(_start_time * 1000);
|
|
|
|
|
|
if (_channel != 0) {
|
|
|
// try backing up current sound.
|
|
|
@@ -338,51 +403,6 @@ set_time(float start_time) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-// Function: FmodAudioSound::get_time
|
|
|
-// Access: public
|
|
|
-// Description: Gets the play position within the sound
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-float FmodAudioSound::
|
|
|
-get_time() const {
|
|
|
- FMOD_RESULT result;
|
|
|
- unsigned int current_time;
|
|
|
-
|
|
|
- if (_channel == 0) {
|
|
|
- return 0.0f;
|
|
|
- }
|
|
|
-
|
|
|
- result = _channel->getPosition( ¤t_time , FMOD_TIMEUNIT_MS );
|
|
|
- if (result == FMOD_ERR_INVALID_HANDLE) {
|
|
|
- return 0.0f;
|
|
|
- }
|
|
|
- fmod_audio_errcheck("_channel->getPosition()", result);
|
|
|
-
|
|
|
- return ((double)current_time) / 1000.0;
|
|
|
-}
|
|
|
-
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-// Function: FmodAudioSound::set_volume(float vol)
|
|
|
-// Access: public
|
|
|
-// Description: 0.0 to 1.0 scale of volume converted to Fmod's
|
|
|
-// internal 0.0 to 255.0 scale.
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-void FmodAudioSound::
|
|
|
-set_volume(float vol) {
|
|
|
- _volume = vol;
|
|
|
- set_volume_on_channel();
|
|
|
-}
|
|
|
-
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-// Function: FmodAudioSound::get_volume
|
|
|
-// Access: public
|
|
|
-// Description: Gets the current volume of a sound. 1 is Max. O is Min.
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
-float FmodAudioSound::
|
|
|
-get_volume() const {
|
|
|
- return _volume;
|
|
|
-}
|
|
|
-
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: FmodAudioSound::set_volume_on_channel()
|
|
|
// Access: Private
|
|
|
@@ -806,6 +826,7 @@ set_active(bool active) {
|
|
|
if (get_loop_count() == 0) {
|
|
|
// ...we're pausing a looping sound.
|
|
|
_paused = true;
|
|
|
+ _start_time = get_time();
|
|
|
}
|
|
|
stop();
|
|
|
}
|