some fixes

This commit is contained in:
Ralty
2025-11-22 12:57:24 +07:00
parent deef60b231
commit 846f2deedb
3 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -471,7 +471,7 @@ final class AudioAnalyzer {
// TODO: Wrap it with try until i figured it out an effective way to do this...
// So... sometimes it just uses the decoder even if it looks good?? please help
var n = Math.floor((endPos - startPos) * __toBits);
var i = backend.bufferLengths.length - backend.queuedBuffers - 1, time:Float;
var i = backend.bufferLengths.length - backend.requestBuffers - 1, time:Float;
while (++i < backend.bufferLengths.length) if (startPos >= (time = backend.bufferTimes[i] * 1000)) {
var pos = Math.floor((startPos - time) * __toBits), buf = backend.bufferDatas[i].buffer, size = backend.bufferLengths[i], c = 0;
while (pos >= size) {
@@ -387,9 +387,9 @@ class NativeAudioSource {
wasEOF = false;
}
}
catch (e:Dynamic) {
trace(e);
result = -1;
catch (e:haxe.Exception) {
trace('NativeAudioSource readToBufferData Bug! error: ${e.message} | ${e.stack}, streamEnded: $streamEnded, total: $total, n: $n');
return result;
}
if (result < 0) {
@@ -444,21 +444,25 @@ class NativeAudioSource {
for (i in (STREAM_MAX_BUFFERS - queuedBuffers)...STREAM_MAX_BUFFERS)
if (sec >= (bufferTime = bufferTimes[i]) && sec < bufferTime + (bufferLengths[i] / wordSize / channels / sampleRate))
{
#if audio_stream_async streamMutex.acquire(); #end
skipBuffers(i - STREAM_MAX_BUFFERS + queuedBuffers);
fillBuffers(STREAM_MIN_BUFFERS - STREAM_MAX_BUFFERS + i);
AL.sourcei(source, AL.SAMPLE_OFFSET, Math.floor((sec - bufferTime) * sampleRate));
fillBuffers(STREAM_MIN_BUFFERS - STREAM_MAX_BUFFERS + i);
#if audio_stream_async streamMutex.release(); #end
return flushBuffers();
}
}
AL.sourceUnqueueBuffers(source, AL.getSourcei(source, AL.BUFFERS_QUEUED));
#if audio_stream_async streamMutex.acquire(); #end
streamEnded = false;
streamSeek(Int64.fromFloat(sec * sampleRate));
requestBuffers = queuedBuffers = streamLoops = nextBuffer = 0;
fillBuffers(STREAM_MIN_BUFFERS);
flushBuffers();
#if audio_stream_async streamMutex.release(); #end
}
#if audio_stream_async
@@ -466,18 +470,16 @@ class NativeAudioSource {
var i:Int, source:NativeAudioSource, process:Int;
while ((i = Thread.readMessage(true)) != 0) {
streamMutex.acquire();
while (i-- > 0) {
if ((source = streamSources[i]).parent.buffer == null || source.parent.buffer.__srcVorbisFile == null) {
if ((source = streamSources[i]).parent.buffer == null) {
source.stopStream();
continue;
}
streamMutex.acquire();
process = source.requestBuffers < STREAM_MIN_BUFFERS ? STREAM_MIN_BUFFERS - source.requestBuffers : 0;
source.fillBuffers(STREAM_PROCESS_BUFFERS > process ? STREAM_PROCESS_BUFFERS : process);
streamMutex.release();
}
streamMutex.release();
}
threadRunning = false;
+1 -1
View File
@@ -164,7 +164,7 @@ import lime.media.openal.AL;
#if lime_cffi
var backend = __source.__backend, i = 0;
if (backend.streamed) {
size = backend.bufferLengths[i = backend.bufferLengths.length - backend.queuedBuffers];
size = backend.bufferLengths[i = backend.bufferLengths.length - backend.requestBuffers];
buf = backend.bufferDatas[i].buffer;
pos -= Math.floor(backend.bufferTimes[i] * buffer.sampleRate * buffer.channels * wordSize);
while (pos > size) {