mirror of
https://github.com/godotengine/godot
synced 2024-09-16 00:48:15 +00:00
Merge pull request #45036 from vix597/issue-45025
Fix `AudioServer.get_time_since_last_mix()` returning incorrect value when accessing from another thread
This commit is contained in:
commit
49b5776e8b
|
@ -71,13 +71,20 @@ void AudioDriver::update_mix_time(int p_frames) {
|
|||
}
|
||||
}
|
||||
|
||||
double AudioDriver::get_time_since_last_mix() const {
|
||||
return (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0;
|
||||
double AudioDriver::get_time_since_last_mix() {
|
||||
lock();
|
||||
uint64_t last_mix_time = _last_mix_time;
|
||||
unlock();
|
||||
return (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;
|
||||
}
|
||||
|
||||
double AudioDriver::get_time_to_next_mix() const {
|
||||
double total = (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0;
|
||||
double mix_buffer = _last_mix_frames / (double)get_mix_rate();
|
||||
double AudioDriver::get_time_to_next_mix() {
|
||||
lock();
|
||||
uint64_t last_mix_time = _last_mix_time;
|
||||
uint64_t last_mix_frames = _last_mix_frames;
|
||||
unlock();
|
||||
double total = (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;
|
||||
double mix_buffer = last_mix_frames / (double)get_mix_rate();
|
||||
return mix_buffer - total;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,8 +70,8 @@ protected:
|
|||
#endif
|
||||
|
||||
public:
|
||||
double get_time_since_last_mix() const; //useful for video -> audio sync
|
||||
double get_time_to_next_mix() const;
|
||||
double get_time_since_last_mix(); //useful for video -> audio sync
|
||||
double get_time_to_next_mix();
|
||||
|
||||
enum SpeakerMode {
|
||||
SPEAKER_MODE_STEREO,
|
||||
|
|
Loading…
Reference in a new issue