From f46ed3dc7e6f6a1e9f4bdc538ffe4368dfa036ba Mon Sep 17 00:00:00 2001 From: player-03 Date: Fri, 7 Jan 2022 19:02:43 -0500 Subject: [PATCH] Standardize setters in `NativeAudioSource`. These setters now: (1) start by checking if anything changed, (2) use the new value in calculations, and (3) perform the assignment only at the end. --- .../backend/native/NativeAudioSource.hx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lime/_internal/backend/native/NativeAudioSource.hx b/src/lime/_internal/backend/native/NativeAudioSource.hx index c1d7de086..00ccc24fd 100644 --- a/src/lime/_internal/backend/native/NativeAudioSource.hx +++ b/src/lime/_internal/backend/native/NativeAudioSource.hx @@ -386,6 +386,11 @@ class NativeAudioSource public function setCurrentTime(value:Int):Int { + if (value == getCurrentTime()) + { + return value; + } + if (handle != null) { if (stream) @@ -424,7 +429,7 @@ class NativeAudioSource timer.stop(); } - var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch()); + var timeRemaining = Std.int((getLength() - value) / getPitch()); if (timeRemaining > 0) { @@ -483,7 +488,7 @@ class NativeAudioSource timer.stop(); } - var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch()); + var timeRemaining = Std.int((value - getCurrentTime()) / getPitch()); if (timeRemaining > 0) { @@ -512,16 +517,14 @@ class NativeAudioSource public function setPitch(value:Float):Float { - AL.sourcef(handle, AL.PITCH, value); - - if (playing) + if (playing && value != getPitch()) { if (timer != null) { timer.stop(); } - var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch()); + var timeRemaining = Std.int((getLength() - getCurrentTime()) / value); if (timeRemaining > 0) { @@ -530,7 +533,9 @@ class NativeAudioSource } } - return getPitch(); + AL.sourcef(handle, AL.PITCH, value); + + return value; } public function getPosition():Vector4