diff --git a/lime/audio/AudioSource.hx b/lime/audio/AudioSource.hx index 95359c913..8a1a5f0c8 100644 --- a/lime/audio/AudioSource.hx +++ b/lime/audio/AudioSource.hx @@ -46,6 +46,7 @@ class AudioSource { private var channel:SoundChannel; #elseif lime_console private var channel:FMODChannel; + private var __gain:Float = 1.0; #end #if (cpp || neko || nodejs) @@ -164,7 +165,10 @@ class AudioSource { } else { channel = buffer.src.play (); - channel.setLoopCount (this.__loops); + channel.setLoopCount (__loops); + if (__gain < 1.0) { + channel.setVolume (__gain); + } var old = setFmodActive (channel, this); @@ -484,8 +488,13 @@ class AudioSource { #elseif lime_console - lime.Lib.notImplemented ("AudioSource.get_gain"); - return 1; + if (channel.valid) { + + __gain = channel.getVolume (); + + } + + return __gain; #else @@ -511,8 +520,13 @@ class AudioSource { #elseif lime_console - lime.Lib.notImplemented ("AudioSource.set_gain"); - return value; + if (channel.valid) { + + channel.setVolume (value); + + } + + return __gain = value; #else diff --git a/lime/audio/fmod/FMODChannel.hx b/lime/audio/fmod/FMODChannel.hx index 8b0d045f7..26c7dd71c 100644 --- a/lime/audio/fmod/FMODChannel.hx +++ b/lime/audio/fmod/FMODChannel.hx @@ -31,6 +31,12 @@ extern class FMODChannel { // setLoopCount sets the channel to loop count times before stopping. 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 public static var INVALID (get, never):FMODChannel;