Merge pull request #779 from FunkinCrew/cutscene-volume-math-fix

proper audio scaling for hxcodec / desktop
This commit is contained in:
Cameron Taylor 2024-09-22 13:29:59 -04:00 committed by GitHub
commit 1937529c1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 45 additions and 11 deletions

View file

@ -0,0 +1,32 @@
package funkin.graphics.video;
import hxcodec.flixel.FlxVideoSprite;
/**
* Not to be confused with FlxVideo, this is a hxcodec based video class
* We override it simply to correct/control our volume easier.
*/
class FunkinVideoSprite extends FlxVideoSprite
{
public var volume(default, set):Float = 1;
public function new(x:Float = 0, y:Float = 0)
{
super(x, y);
set_volume(1);
}
override public function update(elapsed:Float):Void
{
super.update(elapsed);
set_volume(volume);
}
function set_volume(value:Float):Float
{
volume = value;
bitmap.volume = Std.int((FlxG.sound.muted ? 0 : 1) * (FlxG.sound.logToLinear(FlxG.sound.volume) * 100) * volume);
return volume;
}
}

View file

@ -11,7 +11,7 @@ import flixel.util.FlxTimer;
import funkin.graphics.video.FlxVideo;
#end
#if hxCodec
import hxcodec.flixel.FlxVideoSprite;
import funkin.graphics.video.FunkinVideoSprite;
#end
/**
@ -26,7 +26,7 @@ class VideoCutscene
static var vid:FlxVideo;
#end
#if hxCodec
static var vid:FlxVideoSprite;
static var vid:FunkinVideoSprite;
#end
/**
@ -138,7 +138,7 @@ class VideoCutscene
static function playVideoNative(filePath:String):Void
{
// Video displays OVER the FlxState.
vid = new FlxVideoSprite(0, 0);
vid = new FunkinVideoSprite(0, 0);
if (vid != null)
{

View file

@ -4,7 +4,7 @@ package funkin.ui.charSelect;
import funkin.graphics.video.FlxVideo;
#end
#if hxCodec
import hxcodec.flixel.FlxVideoSprite;
import funkin.graphics.video.FunkinVideoSprite;
#end
import funkin.ui.MusicBeatSubState;
import funkin.audio.FunkinSound;
@ -72,12 +72,12 @@ class IntroSubState extends MusicBeatSubState
#end
#if hxCodec
var vid:FlxVideoSprite;
var vid:FunkinVideoSprite;
function playVideoNative(filePath:String):Void
{
// Video displays OVER the FlxState.
vid = new FlxVideoSprite(0, 0);
vid = new FunkinVideoSprite(0, 0);
vid.scrollFactor.set();

View file

@ -79,10 +79,12 @@ class FunkinSoundTray extends FlxSoundTray
y = MathUtil.coolLerp(y, lerpYPos, 0.1);
alpha = MathUtil.coolLerp(alpha, alphaTarget, 0.25);
var shouldHide = (FlxG.sound.muted == false && FlxG.sound.volume > 0);
// Animate sound tray thing
if (_timer > 0)
{
_timer -= (MS / 1000);
if (shouldHide) _timer -= (MS / 1000);
alphaTarget = 1;
}
else if (y >= -height)
@ -121,7 +123,7 @@ class FunkinSoundTray extends FlxSoundTray
active = true;
var globalVolume:Int = Math.round(FlxG.sound.logToLinear(FlxG.sound.volume) * 10);
if (FlxG.sound.muted)
if (FlxG.sound.muted || FlxG.sound.volume == 0)
{
globalVolume = 0;
}

View file

@ -4,7 +4,7 @@ package funkin.ui.title;
import funkin.graphics.video.FlxVideo;
#end
#if hxCodec
import hxcodec.flixel.FlxVideoSprite;
import funkin.graphics.video.FunkinVideoSprite;
#end
import funkin.ui.MusicBeatState;
@ -62,12 +62,12 @@ class AttractState extends MusicBeatState
#end
#if hxCodec
var vid:FlxVideoSprite;
var vid:FunkinVideoSprite;
function playVideoNative(filePath:String):Void
{
// Video displays OVER the FlxState.
vid = new FlxVideoSprite(0, 0);
vid = new FunkinVideoSprite(0, 0);
if (vid != null)
{