From feae6af85a437bd00efbd277cf5bc5dec4bd9daf Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Sun, 28 Mar 2021 19:48:10 +0200 Subject: [PATCH] Making NativeAudio buffers configurable & playback behaving like other sources. --- .../_internal/backend/native/NativeAudioSource.hx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lime/_internal/backend/native/NativeAudioSource.hx b/src/lime/_internal/backend/native/NativeAudioSource.hx index 077205889..0f278ad68 100644 --- a/src/lime/_internal/backend/native/NativeAudioSource.hx +++ b/src/lime/_internal/backend/native/NativeAudioSource.hx @@ -19,7 +19,11 @@ import lime.utils.UInt8Array; class NativeAudioSource { private static var STREAM_BUFFER_SIZE = 48000; + #if !(!native_audio_buffers || macro) private static var STREAM_NUM_BUFFERS = 3; + #else + private static var STREAM_NUM_BUFFERS = Std.parseInt(haxe.macro.Compiler.getDefine("native_audio_buffers")); + #end private static var STREAM_TIMER_FREQUENCY = 100; private var buffers:Array; @@ -289,6 +293,13 @@ class NativeAudioSource } AL.sourceQueueBuffers(handle, numBuffers, buffers); + + // If openAL runs out of buffer it will stop playback. + // This check is here to recover from this and resume playback + // this situation typically happens when resizing window or other operations that freezes the main thread + if (playing && handle != null && AL.getSourcei(handle, AL.SOURCE_STATE) == AL.STOPPED){ + AL.sourcePlay(handle); + } } #end } @@ -298,6 +309,7 @@ class NativeAudioSource if (playing && handle != null && AL.getSourcei(handle, AL.SOURCE_STATE) == AL.PLAYING) { AL.sourceStop(handle); + setCurrentTime(0); } playing = false;