mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
set_play_rate
This commit is contained in:
parent
79d6ab214c
commit
e2db8d8349
@ -79,6 +79,11 @@ PUBLISHED:
|
||||
// inits to 0.0.
|
||||
virtual void set_balance(float balance_right=0.0) = 0;
|
||||
virtual float get_balance() const = 0;
|
||||
|
||||
// play_rate is any positive float value.
|
||||
// inits to 1.0.
|
||||
virtual void set_play_rate(float play_rate=1.0f) = 0;
|
||||
virtual float get_play_rate() const = 0;
|
||||
|
||||
// inits to manager's state.
|
||||
virtual void set_active(bool flag=true) = 0;
|
||||
|
@ -127,6 +127,26 @@ get_volume() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NullAudioManager::set_play_rate
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void NullAudioManager::
|
||||
set_play_rate(float) {
|
||||
// intentionally blank.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NullAudioManager::get_play_rate
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
float NullAudioManager::
|
||||
get_play_rate() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NullAudioManager::set_active
|
||||
// Access: Public
|
||||
|
@ -42,6 +42,9 @@ public:
|
||||
|
||||
virtual void set_volume(float);
|
||||
virtual float get_volume() const;
|
||||
|
||||
virtual void set_play_rate(float);
|
||||
virtual float get_play_rate() const;
|
||||
|
||||
virtual void set_active(bool);
|
||||
virtual bool get_active() const;
|
||||
|
@ -86,6 +86,14 @@ float NullAudioSound::get_balance() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NullAudioSound::set_play_rate(float) {
|
||||
// Intentionally blank.
|
||||
}
|
||||
|
||||
float NullAudioSound::get_play_rate() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NullAudioSound::set_active(bool) {
|
||||
// Intentionally blank.
|
||||
}
|
||||
|
@ -51,6 +51,9 @@ public:
|
||||
|
||||
void set_balance(float);
|
||||
float get_balance() const;
|
||||
|
||||
void set_play_rate(float);
|
||||
float get_play_rate() const;
|
||||
|
||||
void set_active(bool);
|
||||
bool get_active() const;
|
||||
|
@ -69,6 +69,7 @@ MilesAudioManager() {
|
||||
_cleanup_required = true;
|
||||
_active = audio_active;
|
||||
_volume = audio_volume;
|
||||
_play_rate = 1.0f;
|
||||
_cache_limit = audio_cache_limit;
|
||||
_concurrent_sound_limit = 0;
|
||||
_is_valid = true;
|
||||
@ -531,6 +532,35 @@ get_volume() const {
|
||||
return _volume;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioManager::set_play_rate
|
||||
// Access: Public
|
||||
// Description: set the overall play rate
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void MilesAudioManager::
|
||||
set_play_rate(float play_rate) {
|
||||
audio_debug("MilesAudioManager::set_play_rate(play_rate="<<play_rate<<")");
|
||||
if (_play_rate!=play_rate) {
|
||||
_play_rate = play_rate;
|
||||
// Tell our AudioSounds to adjust:
|
||||
AudioSet::iterator i=_sounds_on_loan.begin();
|
||||
for (; i!=_sounds_on_loan.end(); ++i) {
|
||||
(**i).set_play_rate((**i).get_play_rate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioManager::get_play_rate
|
||||
// Access: Public
|
||||
// Description: get the overall speed/pitch/play rate
|
||||
////////////////////////////////////////////////////////////////////
|
||||
float MilesAudioManager::
|
||||
get_play_rate() const {
|
||||
audio_debug("MilesAudioManager::get_play_rate() returning "<<_play_rate);
|
||||
return _play_rate;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioManager::set_active
|
||||
// Access: Public
|
||||
|
@ -50,6 +50,9 @@ public:
|
||||
|
||||
void set_volume(float volume);
|
||||
float get_volume() const;
|
||||
|
||||
void set_play_rate(float play_rate);
|
||||
float get_play_rate() const;
|
||||
|
||||
void set_active(bool active);
|
||||
bool get_active() const;
|
||||
@ -92,6 +95,7 @@ private:
|
||||
LRU _lru;
|
||||
// State:
|
||||
float _volume;
|
||||
float _play_rate;
|
||||
bool _active;
|
||||
int _cache_limit;
|
||||
bool _cleanup_required;
|
||||
|
@ -151,6 +151,24 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
S32
|
||||
Get_playback_rate(HAUDIO audio) {
|
||||
if (audio) {
|
||||
switch (audio->type) {
|
||||
case AIL_QUICK_XMIDI_TYPE:
|
||||
case AIL_QUICK_DLS_XMIDI_TYPE:
|
||||
return AIL_sequence_tempo((HSEQUENCE)audio->handle);
|
||||
break;
|
||||
case AIL_QUICK_DIGITAL_TYPE:
|
||||
case AIL_QUICK_MPEG_DIGITAL_TYPE:
|
||||
return AIL_sample_playback_rate((HSAMPLE)audio->handle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -171,6 +189,8 @@ MilesAudioSound(MilesAudioManager* manager,
|
||||
<<", sd=0x"<<(void*)sd<<", file_name="<<file_name<<")");
|
||||
// Make our own copy of the sound header data:
|
||||
_audio=AIL_quick_copy(sd->_audio);
|
||||
_play_rate = 1.0f;
|
||||
_original_playback_rate = Get_playback_rate(_audio);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -413,6 +433,53 @@ get_volume() const {
|
||||
return _volume;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioSound::
|
||||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void MilesAudioSound::
|
||||
set_play_rate(float play_rate) {
|
||||
miles_audio_debug("set_play_rate(play_rate="<<play_rate<<")");
|
||||
// Set the play_rate:
|
||||
_play_rate=play_rate;
|
||||
if (_audio) {
|
||||
// Account for the category of sound:
|
||||
play_rate*=_manager->get_play_rate();
|
||||
switch (_audio->type) {
|
||||
case AIL_QUICK_XMIDI_TYPE:
|
||||
case AIL_QUICK_DLS_XMIDI_TYPE:
|
||||
// midi uses whole percentage values 100 == 100%
|
||||
_audio->speed = S32(play_rate*100.0f);
|
||||
if ((_audio->speed != -1) && (AIL_quick_status(_audio) == QSTAT_PLAYING)) {
|
||||
AIL_set_sequence_tempo((HSEQUENCE)_audio->handle, _audio->speed, 0);
|
||||
}
|
||||
audio_debug(" play_rate for this midi is now "<<_audio->speed);
|
||||
break;
|
||||
case AIL_QUICK_DIGITAL_TYPE:
|
||||
case AIL_QUICK_MPEG_DIGITAL_TYPE:
|
||||
// wave and mp3 use sample rate (e.g. 44100)
|
||||
_audio->speed = S32(play_rate*_original_playback_rate);
|
||||
if ((_audio->speed != -1) && (AIL_quick_status(_audio) == QSTAT_PLAYING)) {
|
||||
AIL_set_sample_playback_rate((HSAMPLE)_audio->handle, _audio->speed);
|
||||
}
|
||||
audio_debug(" play_rate for this wav or mp3 is now "<<_audio->speed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioSound::get_play_rate
|
||||
// Access:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
float MilesAudioSound::
|
||||
get_play_rate() const {
|
||||
miles_audio_debug("get_play_rate() returning "<<_play_rate);
|
||||
return _play_rate;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MilesAudioSound::set_balance
|
||||
// Access:
|
||||
|
@ -92,6 +92,11 @@ public:
|
||||
// inits to 0.0.
|
||||
void set_balance(float balance_right=0.0f);
|
||||
float get_balance() const;
|
||||
|
||||
// play_rate is any positive float value.
|
||||
// inits to 1.0.
|
||||
void set_play_rate(float play_rate=1.0f);
|
||||
float get_play_rate() const;
|
||||
|
||||
// inits to manager's state.
|
||||
void set_active(bool active=true);
|
||||
@ -121,8 +126,10 @@ private:
|
||||
PT(MilesAudioManager) _manager;
|
||||
float _volume; // 0..1.0
|
||||
float _balance; // -1..1
|
||||
float _play_rate; // 0..1.0
|
||||
mutable float _length; // in seconds.
|
||||
unsigned long _loop_count;
|
||||
S32 _original_playback_rate;
|
||||
|
||||
// This is the string that throw_event() will throw
|
||||
// when the sound finishes playing. It is not triggered
|
||||
|
Loading…
x
Reference in New Issue
Block a user