Skip to content

Commit

Permalink
Sound Backend Bugfixes and Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Raltyro committed Mar 11, 2023
2 parents ff9db60 + 6aa05c5 commit bb17c5c
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: 0.6.3-p0.2.3
tag_name: 0.6.3-p0.2.4
draft: true
files: ./artifacts/*
env:
Expand Down
2 changes: 1 addition & 1 deletion Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@

<!-- _______________________________ Libraries ______________________________ -->

<!-- <haxedev set='webgl'/> -->
<haxedev set='webgl'/>

<haxelib name="flixel"/>
<haxelib name="flixel-addons"/>
Expand Down
45 changes: 38 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
### ill rework readme later

# Friday Night Funkin' - Psike Engine
Psych Engine Fork that included bugfixes, minor QOL features, and performance to make the game runs better.
Psych Engine Fork that included bugfixes, minor QOL features, and performance to make the game runs better, such as
```
Hardware Caching (uses GPU to store images)
Streaming Musics (simultaneously load music data while its playing)
Tweaked Gameplay (you can revert some of the fixes, features in the options gameplay category)
Proper Gamepad Support (not tested, if there any issues, please open up in the repo asap!)
Reworked Menus (only some of it yet)
Lag Latency Fixes
Audio Backend Fixes
Garbage Collector/Memory Handling Fixes
Cleaner formatting on FPS Counter
and etc...
```


## Fork Installation:
You must have raltyro haxelib forks of hxCodec and linc_luajit
You can install raltyro forks of lime, and openfl, well its optional btw
for now you can just click update.bat to automatically install needed haxelibs to compile
You must have the newest haxe version above 4.1.5, and raltyro haxelib forks of hxCodec and linc_luajit

And you can also install raltyro forks of lime, and openfl if you want to

Just incase if your too lazy, you can run update.bat to automatically install the needed haxelibs to compile

## Credits:

## Fork Credits:
* [Raltyro](https://twitter.com/raltyro) - Maintainer
* [Doggo](https://github.com/doggogit) - Programming Help, Grammar Error Fixes, and Emotional Support
* [Eventretta](https://twitter.com/Eventretta) - Clean-up Codes and Cool Stuff
* [EyeDaleHim](https://twitter.com/him_dale) - Programming Help and Emotional Support

## Psych Engine Credits:
* Shadow Mario - Programmer
* RiverOaken - Artist
* Yoshubs - Assistant Programmer

### Special Thanks
* [Stilic](https://twitter.com/stilic_dev) - Sustains Length Fix
* [TheWorldMachinima](https://github.com/TheWorldMachinima) - Softcoded ClientPrefs
* [sayofthelor](https://github.com/sayofthelor) - Border FPS Counter
* [UnholyWanderer](https://gamebanana.com/members/1908754) - Game Over Quotes
* [happyforever/cutzye](https://twitter.com/happyisntfunny) - Game Over Quotes
* [Betopia](https://twitter.com/betpowo) - Game Over Quotes
* shrimpsketti#7483 - Game Over Quotes
* bbpanzu - Ex-Programmer
* Yoshubs - New Input System
* SqirraRNG - Crash Handler and Base code for Chart Editor's Waveform
Expand All @@ -23,3 +51,6 @@ for now you can just click update.bat to automatically install needed haxelibs t
* Keoiki - Note Splash Animations
* Smokey - Sprite Atlas Support
* Nebula the Zorua - LUA JIT Fork and some Lua reworks


[And the Contributors!!](https://github.com/Raltyro/FNF-PsikeEngine/graphs/contributors)
Binary file added art/flashFiles/ralt-gf-new.fla
Binary file not shown.
2 changes: 1 addition & 1 deletion psikeVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.3
0.2.4
4 changes: 2 additions & 2 deletions source/CreditsState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class CreditsState extends MusicBeatState
['Raltyro', 'raltyro', 'Maintainer of Psike Engine', 'https://twitter.com/raltyro', 'F3F3F3'],
[''],
['Fork Contributors'],
['Doggo', 'doggo', 'Programming Help, Grammar Error Fixes\nand Emotional Support', 'https://github.com/doggogit', 'B7CDFF'],
['Doggo', 'doggo', 'Programming Help, Grammar Error Fixes,\nand Emotional Support','https://github.com/doggogit', 'B7CDFF'],
['Eventretta', 'eventy', 'Clean-up Codes and Cool Stuff', 'https://twitter.com/Eventretta', '6B7D94'],
['EyeDaleHim', 'eyedale', 'Programming Help and Emotional Support', 'https://twitter.com/him_dale', 'FF9300'],
['Stilic', 'stilic', 'Sustains Length Fix', 'https://twitter.com/stilic_dev', 'E7A13F'],
[''],
['Special Thanks'],
['Stilic', 'stilic', 'Sustains Length Fix', 'https://twitter.com/stilic_dev', 'E7A13F'],
['TheWorldMachinima', 'twm', 'Softcoded ClientPrefs', 'https://github.com/TheWorldMachinima', '7B6D92'],
['Kirbitus', 'kirbitus', 'Cool Friend :)', 'https://gamebanana.com/members/1853621', 'F3F3F3'],
['sayofthelor', 'sayof', 'Border FPS Counter', 'https://github.com/sayofthelor', 'F3F3F3'],
Expand Down
2 changes: 1 addition & 1 deletion source/MainMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using StringTools;
class MainMenuState extends MusicBeatState
{
public static var psychEngineVersion:String = '0.6.3';
public static var psikeEngineVersion:String = '0.2.3';
public static var psikeEngineVersion:String = '0.2.4';
public static var curSelected:Int = 0;

var menuItems:FlxTypedGroup<FlxSprite>;
Expand Down
4 changes: 3 additions & 1 deletion source/editors/ChartingState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1720,8 +1720,10 @@ class ChartingState extends MusicBeatState


if (FlxG.keys.justPressed.BACKSPACE) {
// Protect against lost data when quickly leaving the chart editor.
autosaveSong();

Main.fpsVar.inEditor = false;

PlayState.chartingMode = false;
MusicBeatState.switchState(new editors.MasterEditorMenu());
FlxG.sound.playMusic(Paths.music('freakyMenu'));
Expand Down
11 changes: 0 additions & 11 deletions source/lime/_internal/backend/flash/FlashAudioSource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,6 @@ class FlashAudioSource
return loops = value;
}

public function getPitch():Float
{
lime.utils.Log.verbose("Pitch is not supported in Flash.");
return 1;
}

public function setPitch(value:Float):Float
{
return getPitch();
}

public function getPosition():Vector4
{
position.x = channel.soundTransform.pan;
Expand Down
55 changes: 28 additions & 27 deletions source/lime/_internal/backend/native/NativeAudioSource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ class NativeAudioSource {

var vorbisFile = parent.buffer.__srcVorbisFile;
if (stream = vorbisFile != null) {
var pcmTotal = vorbisFile.pcmTotal(), info = vorbisFile.info();
var value = pcmTotal * Int64.ofInt(parent.buffer.channels) * (Int64.ofInt(parent.buffer.bitsPerSample) / Int64.ofInt(8));
dataLength = Int64.toInt(value);
var pcmTotal = vorbisFile.pcmTotal();

dataLength = Int64.toInt(pcmTotal * parent.buffer.channels * (Int64.ofInt(parent.buffer.bitsPerSample) / 8));
samples = Int64.toInt(pcmTotal);

buffers = new Array();
bufferDatas = new Array();
Expand All @@ -93,14 +94,12 @@ class NativeAudioSource {
bufferDatas.push(new UInt8Array(STREAM_BUFFER_SIZE));
bufferTimeBlocks.push(0);
}

samples = Int64.toInt(pcmTotal);
}
else {
dataLength = parent.buffer.data.length;
if (!disposed) AL.sourcei(handle, AL.BUFFER, parent.buffer.__srcBuffer);

samples = Int64.toInt((Int64.make(0, dataLength) * Int64.ofInt(8)) / (parent.buffer.channels * parent.buffer.bitsPerSample));
dataLength = parent.buffer.data.length;
samples = Int64.toInt((Int64.make(0, dataLength) * 8) / (parent.buffer.channels * parent.buffer.bitsPerSample));
}
}

Expand All @@ -112,15 +111,15 @@ class NativeAudioSource {
}

public function pause():Void {
if (!(disposed = (handle == null))) AL.sourcePause(handle);
if (!(disposed = handle == null)) AL.sourcePause(handle);

playing = false;
stopStreamTimer();
stopTimer();
}

public function stop():Void {
if (playing && !(disposed = (handle == null)) && AL.getSourcei(handle, AL.SOURCE_STATE) == AL.PLAYING)
if (playing && !(disposed = handle == null) && AL.getSourcei(handle, AL.SOURCE_STATE) == AL.PLAYING)
AL.sourceStop(handle);

bufferLoops = 0;
Expand Down Expand Up @@ -172,15 +171,15 @@ class NativeAudioSource {
var vorbisFile = parent.buffer.__srcVorbisFile;
if (vorbisFile == null) return dispose();

var position = Int64.toInt(vorbisFile.pcmTell()), samples = samples, sampleRate = parent.buffer.sampleRate;
if (length != null) samples = Int64.toInt((Int64.fromFloat(length) + Int64.make(0, parent.offset)) / 1000 * sampleRate);
if (position >= samples && loops <= 0) return;
var position = vorbisFile.pcmTell(), samples = samples;
if (length != null) samples = Int64.toInt(Int64.fromFloat((length + parent.offset) / 1000 * parent.buffer.sampleRate));
if (position >= samples && loops < 1) return;

var numBuffers = 0, size = 0, data;
for (buffer in buffers) {
if (loops < 1 && position >= samples) break;
position += (size = (data = readVorbisFileBuffer(vorbisFile, STREAM_BUFFER_SIZE)).length);
AL.bufferData(buffer, format, data, size, sampleRate);
AL.bufferData(buffer, format, data, size, parent.buffer.sampleRate);
numBuffers++;
}

Expand Down Expand Up @@ -238,11 +237,12 @@ class NativeAudioSource {
if (!safeEnd && bufferLoops <= 0) {
var ranOut = false;
#if lime_vorbis
var vorbisFile;
if (stream && (vorbisFile = parent.buffer.__srcVorbisFile) != null) {
var position = Int64.toInt(vorbisFile.pcmTell()), samples = samples, sampleRate = parent.buffer.sampleRate;
if (length != null) samples = Int64.toInt((Int64.fromFloat(length) + Int64.make(0, parent.offset)) / 1000 * sampleRate);
ranOut = position >= samples - 2048 || queuedBuffers < 3;
var vorbisFile = parent.buffer.__srcVorbisFile;
if (stream) {
if (vorbisFile == null) return dispose();
var samples = samples;
if (length != null) samples = Int64.toInt(Int64.fromFloat((length + parent.offset) / 1000 * parent.buffer.sampleRate));
ranOut = vorbisFile.pcmTell() >= samples || queuedBuffers < 3;
}
#end

Expand Down Expand Up @@ -278,11 +278,11 @@ class NativeAudioSource {
if (completed) return getLength();
else if (!disposed) {
var time;
if (stream) time = (bufferTimeBlocks[STREAM_NUM_BUFFERS - queuedBuffers] + AL.getSourcef(handle, AL.SEC_OFFSET)) * 1000;
else time = samples / parent.buffer.sampleRate * (AL.getSourcei(handle, AL.BYTE_OFFSET) / dataLength) * 1000;
if (stream) time = (bufferTimeBlocks[STREAM_NUM_BUFFERS - queuedBuffers] + AL.getSourcef(handle, AL.SEC_OFFSET));
else time = samples / parent.buffer.sampleRate * (AL.getSourcei(handle, AL.BYTE_OFFSET) / dataLength);
time -= parent.offset;

if (time > 0) return time;
if (time > 0) return time * 1000;
}
return 0;
}
Expand All @@ -296,14 +296,14 @@ class NativeAudioSource {
if (stream) {
AL.sourceStop(handle);

// uses the al queuedbuffers instead if there is any unexpected repeated buffers
// uses the al queuedbuffers instead just incase if there is any unexpected repeated buffers
AL.sourceUnqueueBuffers(handle, AL.getSourcei(handle, AL.BUFFERS_QUEUED));

#if lime_vorbis
var vorbisFile = parent.buffer.__srcVorbisFile;
if (canFill = (vorbisFile != null)) {
//var chunk = Std.int(Math.floor(samples * ratio / STREAM_BUFFER_SIZE) * STREAM_BUFFER_SIZE);
vorbisFile.pcmSeek(Std.int(samples * ratio));
vorbisFile.pcmSeek(Int64.fromFloat(samples * ratio));

fillBuffers(buffers.slice(0, queuedBuffers = 3));
//AL.sourcei(handle, AL.SAMPLE_OFFSET, Std.int((samples * ratio) - chunk));
Expand All @@ -317,7 +317,7 @@ class NativeAudioSource {
}

if (playing) {
var timeRemaining = (getLength() - value) / getPitch();
var timeRemaining = (getLength() - time) / getPitch();
if (completed = timeRemaining < 1) complete();
else {
AL.sourcePlay(handle);
Expand All @@ -332,6 +332,7 @@ class NativeAudioSource {
if (length != null) return length - parent.offset;
return (samples / parent.buffer.sampleRate * 1000) - parent.offset;
}

public function setLength(value:Float):Float {
if (value == length) return value;
if (playing) {
Expand All @@ -342,12 +343,12 @@ class NativeAudioSource {
}

public function getPitch():Float {
if (!disposed) return AL.getSourcef(handle, AL.PITCH);
return 1;
if (disposed) return 1;
return AL.getSourcef(handle, AL.PITCH);
}

public function setPitch(value:Float):Float {
if (disposed || value == getPitch()) return value;
if (disposed || value == AL.getSourcef(handle, AL.PITCH)) return value;
AL.sourcef(handle, AL.PITCH, value);

if (playing) {
Expand Down
8 changes: 4 additions & 4 deletions source/lime/media/AudioSource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class AudioSource {
public var loops(get, set):Int;
public var loopTime(get, set):Float;
public var pitch(get, set):Float;
public var offset:Int;
public var offset:Float;
public var position(get, set):Vector4;

@:noCompletion private var __backend:AudioSourceBackend;

public function new(buffer:AudioBuffer = null, offset:Int = 0, length:Null<Int> = null, loops:Int = 0) {
public function new(buffer:AudioBuffer = null, offset:Float = 0, length:Null<Float> = null, loops:Int = 0) {
this.buffer = buffer;
this.offset = offset;

Expand Down Expand Up @@ -85,10 +85,10 @@ class AudioSource {
return #if flash 0 #else __backend.setLoopTime(value) #end;

@:noCompletion inline private function get_pitch():Float
return #if flash 0 #else __backend.getPitch() #end;
return #if flash 1 #else __backend.getPitch() #end;

@:noCompletion inline private function set_pitch(value:Float):Float
return #if flash 0 #else __backend.setPitch(Math.max(0, value)) #end;
return #if flash value #else __backend.setPitch(Math.max(0, value)) #end;

@:noCompletion inline private function get_position():Vector4
return __backend.getPosition();
Expand Down
Loading

0 comments on commit bb17c5c

Please sign in to comment.