Calculate time remaining based on pitch

This commit is contained in:
player-03
2021-12-29 18:33:07 -05:00
committed by GitHub
parent cd2ab1600e
commit f65eedf28e

View File

@@ -424,7 +424,7 @@ class NativeAudioSource
timer.stop(); timer.stop();
} }
var timeRemaining = getLength() - value; var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch());
if (timeRemaining > 0) if (timeRemaining > 0)
{ {
@@ -483,7 +483,7 @@ class NativeAudioSource
timer.stop(); timer.stop();
} }
var timeRemaining = value - getCurrentTime(); var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch());
if (timeRemaining > 0) if (timeRemaining > 0)
{ {
@@ -514,6 +514,22 @@ class NativeAudioSource
{ {
AL.sourcef(handle, AL.PITCH, value); AL.sourcef(handle, AL.PITCH, value);
if (playing)
{
if (timer != null)
{
timer.stop();
}
var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch());
if (timeRemaining > 0)
{
timer = new Timer(timeRemaining);
timer.run = timer_onRun;
}
}
return getPitch(); return getPitch();
} }