console: implement AudioSource.gain

This commit is contained in:
James Gray
2016-05-24 03:58:30 -05:00
parent 278fec8e45
commit f7422f59bb
2 changed files with 25 additions and 5 deletions

View File

@@ -46,6 +46,7 @@ class AudioSource {
private var channel:SoundChannel; private var channel:SoundChannel;
#elseif lime_console #elseif lime_console
private var channel:FMODChannel; private var channel:FMODChannel;
private var __gain:Float = 1.0;
#end #end
#if (cpp || neko || nodejs) #if (cpp || neko || nodejs)
@@ -164,7 +165,10 @@ class AudioSource {
} else { } else {
channel = buffer.src.play (); channel = buffer.src.play ();
channel.setLoopCount (this.__loops); channel.setLoopCount (__loops);
if (__gain < 1.0) {
channel.setVolume (__gain);
}
var old = setFmodActive (channel, this); var old = setFmodActive (channel, this);
@@ -484,8 +488,13 @@ class AudioSource {
#elseif lime_console #elseif lime_console
lime.Lib.notImplemented ("AudioSource.get_gain"); if (channel.valid) {
return 1;
__gain = channel.getVolume ();
}
return __gain;
#else #else
@@ -511,8 +520,13 @@ class AudioSource {
#elseif lime_console #elseif lime_console
lime.Lib.notImplemented ("AudioSource.set_gain"); if (channel.valid) {
return value;
channel.setVolume (value);
}
return __gain = value;
#else #else

View File

@@ -31,6 +31,12 @@ extern class FMODChannel {
// setLoopCount sets the channel to loop count times before stopping. // setLoopCount sets the channel to loop count times before stopping.
public function setLoopCount (count:Int):Void; public function setLoopCount (count:Int):Void;
// getVolume retrieves the current linear volume level of the channel.
public function getVolume ():cpp.Float32;
// setVolume sets the channel's linear volume level.
public function setVolume (volume:cpp.Float32):Void;
// INVALID represents an invalid channel handle // INVALID represents an invalid channel handle
public static var INVALID (get, never):FMODChannel; public static var INVALID (get, never):FMODChannel;