From be0f865bda5d5c953f2a8dcd9b8b61861cca573b Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sat, 27 Jan 2024 06:16:13 -0500 Subject: [PATCH] crackhead activity in progress --- .../backend/native/NativeAudioSource.hx | 29 ++++++++++++------- src/lime/media/OpenALAudioContext.hx | 5 ++++ src/lime/media/openal/AL.hx | 7 ++++- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/lime/_internal/backend/native/NativeAudioSource.hx b/src/lime/_internal/backend/native/NativeAudioSource.hx index 4554e7200..7434e2876 100644 --- a/src/lime/_internal/backend/native/NativeAudioSource.hx +++ b/src/lime/_internal/backend/native/NativeAudioSource.hx @@ -378,21 +378,30 @@ class NativeAudioSource } else { - var offset = AL.getSourcei(handle, AL.BYTE_OFFSET); - var ratio = (offset / dataLength); - var totalSeconds = samples / parent.buffer.sampleRate; + // var offset = AL.getSourcei(handle, AL.BYTE_OFFSET); + // var ratio = (offset / dataLength); + // var totalSeconds = samples / parent.buffer.sampleRate; - var sampleTime = AL.getSourcef(handle, AL.SAMPLE_OFFSET); + // var sampleTime = AL.getSourcef(handle, AL.SAMPLE_OFFSET); // var time = (sampleTime / parent.buffer.sampleRate * 1000) - parent.offset; // var time = Std.int(totalSeconds * ratio * 1000) - parent.offset; // var time = Std.int (AL.getSourcef (handle, AL.SEC_OFFSET) * 1000) - parent.offset; - var value = AL.getSourcedvSOFT(handle, AL.SEC_OFFSET_CLOCK_SOFT); - var deviceOffset:Float = value[1]; - var realOffset:Float = value[0]; - var time = Std.int((deviceOffset - realOffset) * 1000) - parent.offset; + try + { + var value = AL.getSourcedvSOFT(handle, AL.SEC_OFFSET_LATENCY_SOFT); + var deviceOffset:Float = value[1]; + var realOffset:Float = value[0]; + var time:Float = ((realOffset - deviceOffset) * 1000) - parent.offset; + + if (time < 0) return 0; + return Math.round(time); + } + catch (e:Dynamic) + { + trace(e.messsage); + trace(e.stack); + } - if (time < 0) return 0; - return Std.int(time); } } diff --git a/src/lime/media/OpenALAudioContext.hx b/src/lime/media/OpenALAudioContext.hx index bc9b54349..66dc30c8a 100644 --- a/src/lime/media/OpenALAudioContext.hx +++ b/src/lime/media/OpenALAudioContext.hx @@ -91,6 +91,11 @@ class OpenALAudioContext public var DEFAULT_ALL_DEVICES_SPECIFIER:Int = 0x1012; public var ALL_DEVICES_SPECIFIER:Int = 0x1013; + public var DEVICE_CLOCK_SOFT:Int = 0x1600; + public var DEVICE_LATENCY_SOFT:Int = 0x1601; + public var DEVICE_CLOCK_LATENCY_SOFT:Int = 0x1602; + + public var SEC_OFFSET_LATENCY_SOFT:Int = 0x1201; public var SEC_OFFSET_CLOCK_SOFT:Int = 0x1203; @:noCompletion private function new() {} diff --git a/src/lime/media/openal/AL.hx b/src/lime/media/openal/AL.hx index c3a2fee65..9f7db835d 100644 --- a/src/lime/media/openal/AL.hx +++ b/src/lime/media/openal/AL.hx @@ -232,6 +232,11 @@ class AL public static inline var FILTER_HIGHPASS:Int = 0x0002; public static inline var FILTER_BANDPASS:Int = 0x0003; + public static inline var DEVICE_CLOCK_SOFT:Int = 0x1600; + public static inline var DEVICE_LATENCY_SOFT:Int = 0x1601; + public static inline var DEVICE_CLOCK_LATENCY_SOFT:Int = 0x1602; + + public static inline var SEC_OFFSET_LATENCY_SOFT:Int = 0x1201; public static inline var SEC_OFFSET_CLOCK_SOFT:Int = 0x1203; public static function removeDirectFilter(source:ALSource) @@ -969,7 +974,7 @@ class AL #end } - public static function getSourcedvSOFT(source:ALSource, param:Int, count:Int = 1):Array + public static function getSourcedvSOFT(source:ALSource, param:Int, count:Int = 2):Array { #if (lime_cffi && lime_openal && !macro) var result = NativeCFFI.lime_al_get_sourcedv_SOFT(source, param, count);