Skip to content

Commit 5d8a9c7

Browse files
committed
Update Audio Backend from Vs Camellia v2.75.1 (info at desc)
Before anyone asks why vs cam, the code is public, plus i helped most of the audio backend rewrite in the mod too. :P - Static sounds can now also seamlessly loop with AL_SOFT_loop_points extension - Panning stereo sounds is now possible with AL_EXT_STEREO_ANGLES extension (although this was already implemented before) - Improved streaming sounds, should fix most of the lagspike issues - Streaming sounds should no longer regenrate if it's in the nearest timestamp (not for reversing though) ! You still can't access FlxSound.latency because of the new procedures that's not available in lime If there's any crashes with this pls report an issue asap.
1 parent bbe3464 commit 5d8a9c7

File tree

8 files changed

+575
-398
lines changed

8 files changed

+575
-398
lines changed

building/alsoft.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
[general]
1+
[General]
22
sample-type=float32
33
stereo-mode=speakers
4-
stereo-encoding=panpot
54
hrtf=false
65
cf_level=0
7-
resampler=fast_bsinc24
8-
front-stablizer=false
96
output-limiter=false
7+
front-stabilizer=false
108
volume-adjust=0
9+
period_size=441
10+
sources=512
11+
sends=64
12+
dither=false
13+
1114
[decoder]
12-
hq-mode=false
13-
distance-comp=false
15+
hq-mode=true
16+
distance-comp=true
1417
nfc=false

source/flixel/sound/FlxSound.hx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ class FlxSound extends FlxBasic {
718718
_paused = false;
719719
_time = startTime;
720720
_lastTime = FlxG.game.getTicks();
721-
if (_channel == null || !_channel.__isValid || _source == null #if lime_cffi || _source.__backend.disposed || _source.__backend.handle == null #end)
721+
if (_channel == null || !_channel.__isValid || _source == null #if lime_cffi || _source.__backend.disposed #end)
722722
makeChannel();
723723

724724
if (_channel != null) {
@@ -939,19 +939,19 @@ class FlxSound extends FlxBasic {
939939
return _time = time;
940940
}
941941

942-
inline function get_offset():Float return _offset;
943-
inline function set_offset(offset:Float):Float {
942+
function get_offset():Float return _offset;
943+
function set_offset(offset:Float):Float {
944944
if (_offset == (_offset = offset)) return offset;
945945
//time = time + _offset;
946946
return offset;
947947
}
948948

949-
inline function get_length():Float return _length - _offset;
949+
function get_length():Float return _length - _offset;
950950

951-
/*function get_latency():Float {
952-
if (_channel != null) return _source.latency;
953-
return 0;
954-
}*/
951+
//function get_latency():Float {
952+
// if (_channel != null) return _source.latency;
953+
// return 0;
954+
//}
955955

956956
override function toString():String {
957957
return FlxStringUtil.getDebugString([

source/funkin/backend/utils/AudioAnalyzer.hx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ typedef AudioAnalyzerCallback = Int->Int->Void;
2020
* An utility that analyze FlxSounds,
2121
* can be used to make waveform or real-time audio visualizer.
2222
*
23-
* FlxSound.amplitude does work in CNE so if any case if your only checking for peak of current
24-
* time, use that instead.
23+
* FlxSound.amplitude works so if any case if your only checking for peak of current time, use that instead.
2524
*/
2625
final class AudioAnalyzer {
2726
/**
@@ -296,7 +295,7 @@ final class AudioAnalyzer {
296295
__check();
297296
}
298297

299-
function __check() if (sound.buffer != buffer) {
298+
function __check() if (sound != null && sound.buffer != buffer) {
300299
byteSize = 1 << ((buffer = sound.buffer).bitsPerSample - 1);
301300

302301
#if (lime_cffi && lime_vorbis)
@@ -324,7 +323,7 @@ final class AudioAnalyzer {
324323
* @param maxFreq The maximum frequency to cap (Optional, default 22000.0, Above 23000.0 is not recommended).
325324
* @return Output of levels/bars that ranges from 0 to 1.
326325
*/
327-
public function getLevels(startPos:Float, ?volume:Float, barCount:Int, ?levels:Array<Float>, ?ratio:Float, ?minDb:Float, ?maxDb:Float, ?minFreq:Float, ?maxFreq:Float):Array<Float>
326+
public function getLevels(?startPos:Float, ?volume:Float, barCount:Int, ?levels:Array<Float>, ?ratio:Float, ?minDb:Float, ?maxDb:Float, ?minFreq:Float, ?maxFreq:Float):Array<Float>
328327
return inline getLevelsFromFrequencies(__frequencies = getFrequencies(startPos, volume, __frequencies), buffer.sampleRate, barCount, levels, ratio, minDb, maxDb, minFreq, maxFreq);
329328

330329
/**
@@ -334,8 +333,8 @@ final class AudioAnalyzer {
334333
* @param frequencies The output for getting the frequencies, to avoid memory leaks (Optional).
335334
* @return Output of frequencies.
336335
*/
337-
public function getFrequencies(startPos:Float, ?volume:Float, ?frequencies:Array<Float>):Array<Float>
338-
return inline getFrequenciesFromSamples(__freqSamples = getSamples(startPos, fftN, true, -1, volume, __freqSamples), fftN, useWindowingFFT, frequencies);
336+
public function getFrequencies(?startPos:Float, ?volume:Float, ?frequencies:Array<Float>):Array<Float>
337+
return inline getFrequenciesFromSamples(__freqSamples = getSamples(startPos != null ? startPos : sound.time, fftN, true, -1, volume, __freqSamples), fftN, useWindowingFFT, frequencies);
339338

340339
/**
341340
* Analyzes an attached FlxSound from startPos to endPos in milliseconds to get the amplitudes.
@@ -467,36 +466,37 @@ final class AudioAnalyzer {
467466
@:privateAccess return sound._source != null && sound._source.__backend != null && sound._source.__backend.playing;
468467

469468
inline function __readStream(startPos:Float, endPos:Float, callback:AudioAnalyzerCallback):Float @:privateAccess {
470-
var backend = sound._source.__backend;
471-
var i = backend.bufferSizes.length - backend.queuedBuffers;
472-
var time = backend.bufferTimes[i] * 1000;
469+
final backend = sound._source.__backend;
473470

471+
// TODO: Wrap it with try until i figured it out an effective way to do this...
472+
// So... sometimes it just uses the decoder even if it looks good?? please help
474473
var n = Math.floor((endPos - startPos) * __toBits);
475-
if (startPos >= time && startPos < backend.bufferTimes[backend.bufferSizes.length - 1] * 1000) {
476-
var pos = Math.floor((startPos - time) * __toBits), buf = backend.bufferDatas[i].buffer, size = backend.bufferSizes[i], c = 0;
474+
var i = backend.bufferLengths.length - backend.queuedBuffers - 1, time:Float;
475+
while (++i < backend.bufferLengths.length) if (startPos >= (time = backend.bufferTimes[i] * 1000)) {
476+
var pos = Math.floor((startPos - time) * __toBits), buf = backend.bufferDatas[i].buffer, size = backend.bufferLengths[i], c = 0;
477477
while (pos >= size) {
478-
if (++i >= backend.bufferSizes.length) {
479-
n = 0;
480-
break;
481-
}
478+
if (++i >= backend.bufferLengths.length) break;
482479
pos -= size;
483480
buf = backend.bufferDatas[i].buffer;
484-
size = backend.bufferSizes[i];
481+
size = backend.bufferLengths[i];
485482
}
486-
pos -= pos % __sampleSize;
483+
if (i >= backend.bufferLengths.length) break;
484+
if ((pos -= pos % __sampleSize) < 0) pos = 0;
487485
n -= pos % __sampleSize;
488486

489487
while (n > 0) {
490488
callback(getByte(buf, pos, __wordSize), c);
491489
if (++c > buffer.channels) c = 0;
492490
if ((pos += __wordSize) >= size) {
493-
if (++i >= backend.bufferSizes.length) break;
491+
if (++i >= backend.bufferLengths.length) break;
494492
pos = 0;
495493
buf = backend.bufferDatas[i].buffer;
496-
size = backend.bufferSizes[i];
494+
size = backend.bufferLengths[i];
497495
}
498496
n -= __wordSize;
499497
}
498+
499+
break;
500500
}
501501

502502
return endPos - (n / __toBits);

source/funkin/game/PlayState.hx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,13 +1587,11 @@ class PlayState extends MusicBeatState
15871587
var camera:FlxCamera = event.params[1] == "camHUD" ? camHUD : camGame;
15881588
camera.zoom += event.params[0];
15891589
case "Camera Bop":
1590-
if (Options.camZoomOnBeat) {
1591-
if (useCamZoomMult) {
1592-
camZoomingMult += event.params[0];
1593-
} else {
1594-
FlxG.camera.zoom += event.params[0] * camZoomingStrength;
1595-
camHUD.zoom += event.params[0] * camZoomingStrength;
1596-
}
1590+
if (useCamZoomMult) {
1591+
camZoomingMult += event.params[0];
1592+
} else {
1593+
FlxG.camera.zoom += event.params[0] * camZoomingStrength;
1594+
camHUD.zoom += event.params[0] * camZoomingStrength;
15971595
}
15981596
case "Camera Zoom":
15991597
var cam = event.params[2] == "camHUD" ? camHUD : camGame;

0 commit comments

Comments
 (0)