From 8cadcd78f6e257cf569ba85016f26f87e24241eb Mon Sep 17 00:00:00 2001 From: Ralty <78720179+Raltyro@users.noreply.github.com> Date: Fri, 21 Nov 2025 19:19:52 +0700 Subject: [PATCH] Hopefully fixes the time parameter being 0? --- source/flixel/sound/FlxSound.hx | 39 ++++++++----------- .../backend/native/NativeAudioSource.hx | 4 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/source/flixel/sound/FlxSound.hx b/source/flixel/sound/FlxSound.hx index f514b5f7..fa86601c 100644 --- a/source/flixel/sound/FlxSound.hx +++ b/source/flixel/sound/FlxSound.hx @@ -769,7 +769,8 @@ class FlxSound extends FlxBasic { _lastTime = FlxG.game.getTicks(); _time = loopTime; } - else _channel.loops = 999; + else if (_source != null) + _source.loops = 999; } /** @@ -799,7 +800,7 @@ class FlxSound extends FlxBasic { } inline function get_playing():Bool @:privateAccess - return _channel != null && _channel.__isValid && _source.playing; + return _source != null && _source.playing; inline function get_volume():Float return _volume; @@ -832,12 +833,12 @@ class FlxSound extends FlxBasic { inline function get_buffer():AudioBuffer @:privateAccess return _sound != null ? _sound.__buffer : null; - function update_amplitude():Void @:privateAccess { - if (_channel == null || !_channel.__updatePeaks(get_time()) || !_amplitudeUpdate) return; - - _amplitudeUpdate = false; - _amplitudeLeft = _channel.__leftPeak; - _amplitudeRight = _channel.__rightPeak; + inline function update_amplitude():Void @:privateAccess { + if (_channel != null && _channel.__updatePeaks(get_time()) && _amplitudeUpdate) { + _amplitudeUpdate = false; + _amplitudeLeft = _channel.__leftPeak; + _amplitudeRight = _channel.__rightPeak; + } } inline function get_amplitudeLeft():Float { @@ -865,30 +866,27 @@ class FlxSound extends FlxBasic { inline function get_pitch():Float return _pitch; - function set_pitch(v:Float):Float { + inline function set_pitch(v:Float):Float { _realPitch = (_pitch = v) * _timeScaleAdjust; - if (_channel != null) _channel.pitch = _realPitch; + if (_source != null) _source.pitch = _realPitch; return _pitch; } #end function set_looped(v:Bool):Bool { - if (playing) { - if (v) _channel.loops = 999; - else _channel.loops = 0; - } + if (playing) _source.loops = v ? 999 : 0; return looped = v; } function set_loopTime(v:Float):Float { - if (playing) _channel.loopTime = v; + if (playing) _source.loopTime = v; return loopTime = v; } function set_endTime(v:Null):Null { if (playing) { - if (v != null && v > 0 && v < _length) _channel.endTime = v; - else _channel.endTime = null; + if (v != null && v > 0 && v < _length) _source.length = v; + else _source.length = null; } return endTime = v; } @@ -900,7 +898,7 @@ class FlxSound extends FlxBasic { return _time; } function get_time():Float { - if (_channel == null || @:privateAccess !_channel.__isValid || /*AudioManager.context == null*/funkin.backend.system.Main.audioDisconnected) return _time; + if (_source == null || /*AudioManager.context == null*/funkin.backend.system.Main.audioDisconnected) return _time; final sourceTime = _source.currentTime - _source.offset - _offset; if (!_source.playing || _realPitch <= 0) { @@ -948,10 +946,7 @@ class FlxSound extends FlxBasic { function get_length():Float return _length - _offset; - //function get_latency():Float { - // if (_channel != null) return _source.latency; - // return 0; - //} + //function get_latency():Float return _source != null ? _source.latency : 0; override function toString():String { return FlxStringUtil.getDebugString([ diff --git a/source/lime/_internal/backend/native/NativeAudioSource.hx b/source/lime/_internal/backend/native/NativeAudioSource.hx index c68c52d8..73bf5614 100644 --- a/source/lime/_internal/backend/native/NativeAudioSource.hx +++ b/source/lime/_internal/backend/native/NativeAudioSource.hx @@ -571,7 +571,7 @@ class NativeAudioSource { else if (completed) return getLength(); else if (!playing) return lastTime - parent.offset; - var time = AL.getSourcef(source, AL.SEC_OFFSET); + var time = AL.getSourcef(source, AL.SAMPLE_OFFSET) / sampleRate; if (streamed) { if (playing && streamEnded && AL.getSourcei(source, AL.SOURCE_STATE) == AL.STOPPED) { complete(); @@ -594,7 +594,7 @@ class NativeAudioSource { value = Math.isFinite(value) ? Math.max(Math.min(value + parent.offset, length), parent.offset) : parent.offset; if (streamed) AL.sourceStop(source); - else AL.sourcef(source, AL.SEC_OFFSET, value / 1000); + else AL.sourcef(source, AL.SAMPLE_OFFSET, value / 1000 * sampleRate); final timeRemaining = (length - value) / getPitch(); if (playing) {