From 690f3090b728a84a91e2878412eaf9049c1d8116 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 20 Sep 2024 20:11:12 -0400 Subject: [PATCH 1/3] proper audio scaling for hxcodec / desktop --- .../graphics/video/FunkinVideoSprite.hx | 32 +++++++++++++++++++ source/funkin/play/cutscene/VideoCutscene.hx | 6 ++-- source/funkin/ui/charSelect/IntroSubState.hx | 6 ++-- source/funkin/ui/title/AttractState.hx | 6 ++-- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 source/funkin/graphics/video/FunkinVideoSprite.hx diff --git a/source/funkin/graphics/video/FunkinVideoSprite.hx b/source/funkin/graphics/video/FunkinVideoSprite.hx new file mode 100644 index 000000000..e0086784b --- /dev/null +++ b/source/funkin/graphics/video/FunkinVideoSprite.hx @@ -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; + } +} diff --git a/source/funkin/play/cutscene/VideoCutscene.hx b/source/funkin/play/cutscene/VideoCutscene.hx index 60454b881..b6e04004b 100644 --- a/source/funkin/play/cutscene/VideoCutscene.hx +++ b/source/funkin/play/cutscene/VideoCutscene.hx @@ -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) { diff --git a/source/funkin/ui/charSelect/IntroSubState.hx b/source/funkin/ui/charSelect/IntroSubState.hx index 2c2908473..e731e5e9a 100644 --- a/source/funkin/ui/charSelect/IntroSubState.hx +++ b/source/funkin/ui/charSelect/IntroSubState.hx @@ -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(); diff --git a/source/funkin/ui/title/AttractState.hx b/source/funkin/ui/title/AttractState.hx index c5a3d0504..f5f266b0d 100644 --- a/source/funkin/ui/title/AttractState.hx +++ b/source/funkin/ui/title/AttractState.hx @@ -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) { From 29a7005d8a5ca63f69531792b86d9ec457efae09 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Sun, 22 Sep 2024 00:44:57 -0400 Subject: [PATCH 2/3] Fix a bug where you can hear the game a little when setting the volume to 0 ticks --- source/funkin/ui/options/FunkinSoundTray.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/funkin/ui/options/FunkinSoundTray.hx b/source/funkin/ui/options/FunkinSoundTray.hx index 8ae53524a..eea30ae17 100644 --- a/source/funkin/ui/options/FunkinSoundTray.hx +++ b/source/funkin/ui/options/FunkinSoundTray.hx @@ -121,7 +121,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; } From c7238fcfd114352924a6cca436e069523a86cced Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Sun, 22 Sep 2024 00:45:30 -0400 Subject: [PATCH 3/3] Stop the volume tray from hiding as long as the game is muted --- source/funkin/ui/options/FunkinSoundTray.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/funkin/ui/options/FunkinSoundTray.hx b/source/funkin/ui/options/FunkinSoundTray.hx index eea30ae17..b2fb7fc04 100644 --- a/source/funkin/ui/options/FunkinSoundTray.hx +++ b/source/funkin/ui/options/FunkinSoundTray.hx @@ -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)