Merge pull request #1510 from ninjamuffin99/pitch
Audio pitch change implementation
This commit is contained in:
@@ -117,6 +117,17 @@ class FlashAudioSource
|
|||||||
return loops = value;
|
return loops = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPitch():Float
|
||||||
|
{
|
||||||
|
lime.utils.Log.verbose("Pitch is not supported in Flash.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPitch(value:Float):Float
|
||||||
|
{
|
||||||
|
return getPitch();
|
||||||
|
}
|
||||||
|
|
||||||
public function getPosition():Vector4
|
public function getPosition():Vector4
|
||||||
{
|
{
|
||||||
position.x = channel.soundTransform.pan;
|
position.x = channel.soundTransform.pan;
|
||||||
|
|||||||
@@ -204,6 +204,25 @@ class HTML5AudioSource
|
|||||||
return loops = value;
|
return loops = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPitch():Float
|
||||||
|
{
|
||||||
|
#if lime_howlerjs
|
||||||
|
return parent.buffer.__srcHowl.rate();
|
||||||
|
#else
|
||||||
|
return 1;
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPitch(value:Float):Float
|
||||||
|
{
|
||||||
|
#if lime_howlerjs
|
||||||
|
parent.buffer.__srcHowl.rate(value);
|
||||||
|
#end
|
||||||
|
|
||||||
|
return getPitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getPosition():Vector4
|
public function getPosition():Vector4
|
||||||
{
|
{
|
||||||
#if lime_howlerjs
|
#if lime_howlerjs
|
||||||
|
|||||||
@@ -387,6 +387,12 @@ class NativeAudioSource
|
|||||||
|
|
||||||
public function setCurrentTime(value:Int):Int
|
public function setCurrentTime(value:Int):Int
|
||||||
{
|
{
|
||||||
|
// `setCurrentTime()` has side effects and is never safe to skip.
|
||||||
|
/* if (value == getCurrentTime())
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
} */
|
||||||
|
|
||||||
if (handle != null)
|
if (handle != null)
|
||||||
{
|
{
|
||||||
if (stream)
|
if (stream)
|
||||||
@@ -425,7 +431,7 @@ class NativeAudioSource
|
|||||||
timer.stop();
|
timer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeRemaining = getLength() - value;
|
var timeRemaining = Std.int((getLength() - value) / getPitch());
|
||||||
|
|
||||||
if (timeRemaining > 0)
|
if (timeRemaining > 0)
|
||||||
{
|
{
|
||||||
@@ -484,7 +490,7 @@ class NativeAudioSource
|
|||||||
timer.stop();
|
timer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeRemaining = value - getCurrentTime();
|
var timeRemaining = Std.int((value - getCurrentTime()) / getPitch());
|
||||||
|
|
||||||
if (timeRemaining > 0)
|
if (timeRemaining > 0)
|
||||||
{
|
{
|
||||||
@@ -506,6 +512,44 @@ class NativeAudioSource
|
|||||||
return loops = value;
|
return loops = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPitch():Float
|
||||||
|
{
|
||||||
|
if (handle != null)
|
||||||
|
{
|
||||||
|
return AL.getSourcef(handle, AL.PITCH);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPitch(value:Float):Float
|
||||||
|
{
|
||||||
|
if (playing && value != getPitch())
|
||||||
|
{
|
||||||
|
if (timer != null)
|
||||||
|
{
|
||||||
|
timer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
var timeRemaining = Std.int((getLength() - getCurrentTime()) / value);
|
||||||
|
|
||||||
|
if (timeRemaining > 0)
|
||||||
|
{
|
||||||
|
timer = new Timer(timeRemaining);
|
||||||
|
timer.run = timer_onRun;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle != null)
|
||||||
|
{
|
||||||
|
AL.sourcef(handle, AL.PITCH, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPosition():Vector4
|
public function getPosition():Vector4
|
||||||
{
|
{
|
||||||
if (handle != null)
|
if (handle != null)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class AudioSource
|
|||||||
public var gain(get, set):Float;
|
public var gain(get, set):Float;
|
||||||
public var length(get, set):Int;
|
public var length(get, set):Int;
|
||||||
public var loops(get, set):Int;
|
public var loops(get, set):Int;
|
||||||
|
public var pitch(get, set):Float;
|
||||||
public var offset:Int;
|
public var offset:Int;
|
||||||
public var position(get, set):Vector4;
|
public var position(get, set):Vector4;
|
||||||
|
|
||||||
@@ -108,6 +109,16 @@ class AudioSource
|
|||||||
return __backend.setLoops(value);
|
return __backend.setLoops(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@:noCompletion private function get_pitch():Float
|
||||||
|
{
|
||||||
|
return __backend.getPitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@:noCompletion private function set_pitch(value:Float):Float
|
||||||
|
{
|
||||||
|
return __backend.setPitch(value);
|
||||||
|
}
|
||||||
|
|
||||||
@:noCompletion private function get_position():Vector4
|
@:noCompletion private function get_position():Vector4
|
||||||
{
|
{
|
||||||
return __backend.getPosition();
|
return __backend.getPosition();
|
||||||
|
|||||||
Reference in New Issue
Block a user