From c404240751392a05c6db3445f97558e314865e08 Mon Sep 17 00:00:00 2001 From: Shirasawa <764798966@qq.com> Date: Sun, 10 Dec 2023 17:50:14 +0800 Subject: [PATCH] update to java 21 --- CMakeLists.txt | 18 +++----- build.gradle | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- jitpack.yml | 4 +- .../dsp/timestretchers/NativeFFT.java | 46 +++++++++---------- .../dsp/timestretchers/NativeLibrary.java | 6 +-- .../dsp/timestretchers/NativeResampler.java | 26 +++++------ .../timestretchers/NativeTimeStretcher.java | 42 ++++++++--------- 8 files changed, 70 insertions(+), 78 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9d76b4..896f68a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,22 +6,17 @@ set(CMAKE_CXX_STANDARD 23) add_definitions(-DNO_TIMING) set(BUILD_TESTING OFF CACHE BOOL "" FORCE) + if (WIN32) add_definitions(-D_WIN32 -DNOMINMAX -D_USE_MATH_DEFINES -DHAVE_SLEEF -DHAVE_LIBSAMPLERATE -DGETOPT_API=0) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MD") - - set(sleef_SOURCE_DIR ${CMAKE_SOURCE_DIR}/sleef) - set(sleef_BINARY_DIR ${CMAKE_BINARY_DIR}/sleef) - set(BUILD_DFT ON CACHE BOOL "" FORCE) - set(BUILD_TESTS OFF CACHE BOOL "" FORCE) - add_subdirectory("sleef") - include_directories(${sleef_BINARY_DIR}/include) - include_directories(${sleef_SOURCE_DIR}/include) - link_directories(${sleef_BINARY_DIR}/lib) - set(CMAKE_PROJECT_VERSION 2.3.2) +elseif (LINUX) + add_definitions(-DUSE_PTHREADS -DHAVE_LIBSAMPLERATE -DHAVE_SLEEF -DHAVE_POSIX_MEMALIGN) elseif (APPLE) add_definitions(-DHAVE_LIBSAMPLERATE -DHAVE_VDSP -DNO_THREAD_CHECKS -DUSE_PTHREADS -DMALLOC_IS_ALIGNED) -elseif (LINUX) +endif () + +if (WIN32 OR LINUX) set(sleef_SOURCE_DIR ${CMAKE_SOURCE_DIR}/sleef) set(sleef_BINARY_DIR ${CMAKE_BINARY_DIR}/sleef) set(BUILD_DFT ON CACHE BOOL "" FORCE) @@ -31,7 +26,6 @@ elseif (LINUX) include_directories(${sleef_SOURCE_DIR}/include) link_directories(${sleef_BINARY_DIR}/lib) set(CMAKE_PROJECT_VERSION 2.3.2) - add_definitions(-DUSE_PTHREADS -DHAVE_LIBSAMPLERATE -DHAVE_SLEEF) endif () # check is Release build or MinSizeRel build diff --git a/build.gradle b/build.gradle index 5750f3b..e0721b2 100644 --- a/build.gradle +++ b/build.gradle @@ -8,8 +8,8 @@ plugins { group = 'com.eimsound.dsp.timestretchers' version = System.getenv('VERSION') ?: '0.0.0' -sourceCompatibility = JavaVersion.VERSION_19 -targetCompatibility = JavaVersion.VERSION_19 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 repositories { mavenCentral() diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0ce0425..8ac63de 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sat Dec 09 21:28:39 CST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jitpack.yml b/jitpack.yml index 96c0307..80f91a5 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,3 +1,3 @@ before_install: - - sdk install java 19.0.2-librca - - sdk use java 19.0.2-librca + - sdk install java 21.0.1-librca + - sdk use java 21.0.1-librca diff --git a/src/main/java/com/eimsound/dsp/timestretchers/NativeFFT.java b/src/main/java/com/eimsound/dsp/timestretchers/NativeFFT.java index ea30886..fd7f2e5 100644 --- a/src/main/java/com/eimsound/dsp/timestretchers/NativeFFT.java +++ b/src/main/java/com/eimsound/dsp/timestretchers/NativeFFT.java @@ -8,7 +8,7 @@ @SuppressWarnings("unused") public final class NativeFFT implements AutoCloseable { private boolean isClosed = false; - private final Addressable pointer; + private final MemorySegment pointer; private static MethodHandle fft_init; // void* *fft_init(int fftSize) private static MethodHandle fft_destroy; // void fft_destroy(void* *fft) @@ -28,20 +28,20 @@ private static void init() { var lib = NativeLibrary.getLookup(); var linker = Linker.nativeLinker(); fft_init = linker.downcallHandle( - lib.lookup("fft_init").orElseThrow(), + lib.find("fft_init").orElseThrow(), FunctionDescriptor.of( ValueLayout.ADDRESS, ValueLayout.JAVA_INT ) ); fft_destroy = linker.downcallHandle( - lib.lookup("fft_destroy").orElseThrow(), + lib.find("fft_destroy").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS ) ); fft_forward = linker.downcallHandle( - lib.lookup("fft_forward").orElseThrow(), + lib.find("fft_forward").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.ADDRESS, @@ -50,7 +50,7 @@ private static void init() { ) ); fft_forward_interleaved = linker.downcallHandle( - lib.lookup("fft_forward_interleaved").orElseThrow(), + lib.find("fft_forward_interleaved").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.ADDRESS, @@ -58,7 +58,7 @@ private static void init() { ) ); fft_forward_polar = linker.downcallHandle( - lib.lookup("fft_forward_polar").orElseThrow(), + lib.find("fft_forward_polar").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.ADDRESS, @@ -67,7 +67,7 @@ private static void init() { ) ); fft_forward_magnitude = linker.downcallHandle( - lib.lookup("fft_forward_magnitude").orElseThrow(), + lib.find("fft_forward_magnitude").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.ADDRESS, @@ -75,7 +75,7 @@ private static void init() { ) ); fft_inverse = linker.downcallHandle( - lib.lookup("fft_inverse").orElseThrow(), + lib.find("fft_inverse").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.ADDRESS, @@ -84,7 +84,7 @@ private static void init() { ) ); fft_inverse_interleaved = linker.downcallHandle( - lib.lookup("fft_inverse_interleaved").orElseThrow(), + lib.find("fft_inverse_interleaved").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.ADDRESS, @@ -92,7 +92,7 @@ private static void init() { ) ); fft_inverse_polar = linker.downcallHandle( - lib.lookup("fft_inverse_polar").orElseThrow(), + lib.find("fft_inverse_polar").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.ADDRESS, @@ -101,7 +101,7 @@ private static void init() { ) ); fft_inverse_cepstral = linker.downcallHandle( - lib.lookup("fft_inverse_cepstral").orElseThrow(), + lib.find("fft_inverse_cepstral").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.ADDRESS, @@ -109,14 +109,14 @@ private static void init() { ) ); fft_get_size = linker.downcallHandle( - lib.lookup("fft_get_size").orElseThrow(), + lib.find("fft_get_size").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_INT, ValueLayout.ADDRESS ) ); fft_get_default_implementation = linker.downcallHandle( - lib.lookup("fft_get_default_implementation").orElseThrow(), + lib.find("fft_get_default_implementation").orElseThrow(), FunctionDescriptor.of( ValueLayout.ADDRESS ) @@ -126,13 +126,13 @@ private static void init() { public NativeFFT(int fftSize) { init(); try { - pointer = (MemoryAddress) fft_init.invokeExact(fftSize); + pointer = (MemorySegment) fft_init.invokeExact(fftSize); } catch (Throwable e) { throw new RuntimeException(e); } } - public void forward(@NotNull Addressable realIn, @NotNull Addressable realOut, @NotNull Addressable imagOut) { + public void forward(@NotNull MemorySegment realIn, @NotNull MemorySegment realOut, @NotNull MemorySegment imagOut) { try { fft_forward.invokeExact(pointer, realIn, realOut, imagOut); } catch (Throwable e) { @@ -140,7 +140,7 @@ public void forward(@NotNull Addressable realIn, @NotNull Addressable realOut, @ } } - public void forwardInterleaved(@NotNull Addressable realIn, @NotNull Addressable complexOut) { + public void forwardInterleaved(@NotNull MemorySegment realIn, @NotNull MemorySegment complexOut) { try { fft_forward_interleaved.invokeExact(pointer, realIn, complexOut); } catch (Throwable e) { @@ -148,7 +148,7 @@ public void forwardInterleaved(@NotNull Addressable realIn, @NotNull Addressable } } - public void forwardPolar(@NotNull Addressable realIn, @NotNull Addressable magOut, @NotNull Addressable phaseOut) { + public void forwardPolar(@NotNull MemorySegment realIn, @NotNull MemorySegment magOut, @NotNull MemorySegment phaseOut) { try { fft_forward_polar.invokeExact(pointer, realIn, magOut, phaseOut); } catch (Throwable e) { @@ -156,7 +156,7 @@ public void forwardPolar(@NotNull Addressable realIn, @NotNull Addressable magOu } } - public void forwardMagnitude(@NotNull Addressable realIn, @NotNull Addressable magOut) { + public void forwardMagnitude(@NotNull MemorySegment realIn, @NotNull MemorySegment magOut) { try { fft_forward_magnitude.invokeExact(pointer, realIn, magOut); } catch (Throwable e) { @@ -164,7 +164,7 @@ public void forwardMagnitude(@NotNull Addressable realIn, @NotNull Addressable m } } - public void inverse(@NotNull Addressable realIn, @NotNull Addressable imagIn, @NotNull Addressable realOut) { + public void inverse(@NotNull MemorySegment realIn, @NotNull MemorySegment imagIn, @NotNull MemorySegment realOut) { try { fft_inverse.invokeExact(pointer, realIn, imagIn, realOut); } catch (Throwable e) { @@ -172,7 +172,7 @@ public void inverse(@NotNull Addressable realIn, @NotNull Addressable imagIn, @N } } - public void inverseInterleaved(@NotNull Addressable complexIn, @NotNull Addressable realOut) { + public void inverseInterleaved(@NotNull MemorySegment complexIn, @NotNull MemorySegment realOut) { try { fft_inverse_interleaved.invokeExact(pointer, complexIn, realOut); } catch (Throwable e) { @@ -180,7 +180,7 @@ public void inverseInterleaved(@NotNull Addressable complexIn, @NotNull Addressa } } - public void inversePolar(@NotNull Addressable magIn, @NotNull Addressable phaseIn, @NotNull Addressable realOut) { + public void inversePolar(@NotNull MemorySegment magIn, @NotNull MemorySegment phaseIn, @NotNull MemorySegment realOut) { try { fft_inverse_polar.invokeExact(pointer, magIn, phaseIn, realOut); } catch (Throwable e) { @@ -188,7 +188,7 @@ public void inversePolar(@NotNull Addressable magIn, @NotNull Addressable phaseI } } - public void inverseCepstral(@NotNull Addressable magIn, @NotNull Addressable cepOut) { + public void inverseCepstral(@NotNull MemorySegment magIn, @NotNull MemorySegment cepOut) { try { fft_inverse_cepstral.invokeExact(pointer, magIn, cepOut); } catch (Throwable e) { @@ -208,7 +208,7 @@ public int getSize() { public static String getDefaultImplementation() { init(); try { - return ((MemoryAddress) fft_get_default_implementation.invokeExact()).getUtf8String(0L); + return ((MemorySegment) fft_get_default_implementation.invokeExact()).getUtf8String(0L); } catch (Throwable e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/eimsound/dsp/timestretchers/NativeLibrary.java b/src/main/java/com/eimsound/dsp/timestretchers/NativeLibrary.java index 4e12cbd..c280312 100644 --- a/src/main/java/com/eimsound/dsp/timestretchers/NativeLibrary.java +++ b/src/main/java/com/eimsound/dsp/timestretchers/NativeLibrary.java @@ -1,6 +1,6 @@ package com.eimsound.dsp.timestretchers; -import java.lang.foreign.MemorySession; +import java.lang.foreign.Arena; import java.lang.foreign.SymbolLookup; import java.nio.file.Files; import java.nio.file.Path; @@ -9,7 +9,6 @@ import java.util.Objects; final class NativeLibrary { - private static MemorySession session; private static final String fileName; private static SymbolLookup lookup; @@ -23,8 +22,7 @@ final class NativeLibrary { } static SymbolLookup getLookup() { - if (session == null) session = MemorySession.openImplicit(); - if (lookup == null) lookup = SymbolLookup.libraryLookup(getLibraryPath(), session); + if (lookup == null) lookup = SymbolLookup.libraryLookup(getLibraryPath(), Arena.global()); return lookup; } diff --git a/src/main/java/com/eimsound/dsp/timestretchers/NativeResampler.java b/src/main/java/com/eimsound/dsp/timestretchers/NativeResampler.java index 2aed57a..ba658e0 100644 --- a/src/main/java/com/eimsound/dsp/timestretchers/NativeResampler.java +++ b/src/main/java/com/eimsound/dsp/timestretchers/NativeResampler.java @@ -8,7 +8,7 @@ @SuppressWarnings("unused") public final class NativeResampler implements AutoCloseable { private boolean isClosed = false; - private final Addressable pointer; + private final MemorySegment pointer; private static MethodHandle resampler_init; // void* *resampler_init(int channels, double initialSampleRate, int quality, bool isRatioOftenChanging, bool isSuddenRatioChange) private static MethodHandle resampler_destroy; // void resampler_destroy(void* *resampler) @@ -24,7 +24,7 @@ private static void init() { var lib = NativeLibrary.getLookup(); var linker = Linker.nativeLinker(); resampler_init = linker.downcallHandle( - lib.lookup("resampler_init").orElseThrow(), + lib.find("resampler_init").orElseThrow(), FunctionDescriptor.of( ValueLayout.ADDRESS, ValueLayout.JAVA_INT, @@ -35,13 +35,13 @@ private static void init() { ) ); resampler_destroy = linker.downcallHandle( - lib.lookup("resampler_destroy").orElseThrow(), + lib.find("resampler_destroy").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS ) ); resampler_resample = linker.downcallHandle( - lib.lookup("resampler_resample").orElseThrow(), + lib.find("resampler_resample").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_INT, ValueLayout.ADDRESS, @@ -53,7 +53,7 @@ private static void init() { ) ); resampler_resample_interleaved = linker.downcallHandle( - lib.lookup("resampler_resample_interleaved").orElseThrow(), + lib.find("resampler_resample_interleaved").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_INT, ValueLayout.ADDRESS, @@ -65,14 +65,14 @@ private static void init() { ) ); resampler_get_channel_count = linker.downcallHandle( - lib.lookup("resampler_get_channel_count").orElseThrow(), + lib.find("resampler_get_channel_count").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_INT, ValueLayout.ADDRESS ) ); resampler_get_effective_ratio = linker.downcallHandle( - lib.lookup("resampler_get_effective_ratio").orElseThrow(), + lib.find("resampler_get_effective_ratio").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_DOUBLE, ValueLayout.ADDRESS, @@ -80,13 +80,13 @@ private static void init() { ) ); resampler_reset = linker.downcallHandle( - lib.lookup("resampler_reset").orElseThrow(), + lib.find("resampler_reset").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS ) ); resampler_get_implementation = linker.downcallHandle( - lib.lookup("resampler_get_implementation").orElseThrow(), + lib.find("resampler_get_implementation").orElseThrow(), FunctionDescriptor.of( ValueLayout.ADDRESS, ValueLayout.ADDRESS @@ -97,7 +97,7 @@ private static void init() { public NativeResampler(int channels, double initialSampleRate, int quality, boolean isRatioOftenChanging, boolean isSuddenRatioChange) { init(); try { - pointer = (Addressable) resampler_init.invokeExact(channels, initialSampleRate, quality, isRatioOftenChanging, isSuddenRatioChange); + pointer = (MemorySegment) resampler_init.invokeExact(channels, initialSampleRate, quality, isRatioOftenChanging, isSuddenRatioChange); } catch (Throwable e) { throw new RuntimeException(e); } @@ -114,7 +114,7 @@ public void close() { } } - public int resample(@NotNull Addressable out, int outspace, @NotNull Addressable in, int incount, double ratio, boolean final_) { + public int resample(@NotNull MemorySegment out, int outspace, @NotNull MemorySegment in, int incount, double ratio, boolean final_) { try { return (int) resampler_resample.invokeExact(pointer, out, outspace, in, incount, ratio, final_); } catch (Throwable e) { @@ -122,7 +122,7 @@ public int resample(@NotNull Addressable out, int outspace, @NotNull Addressable } } - public int interleaved(@NotNull Addressable out, int outspace, @NotNull Addressable in, int incount, double ratio, boolean final_) { + public int interleaved(@NotNull MemorySegment out, int outspace, @NotNull MemorySegment in, int incount, double ratio, boolean final_) { try { return (int) resampler_resample_interleaved.invokeExact(pointer, out, outspace, in, incount, ratio, final_); } catch (Throwable e) { @@ -158,7 +158,7 @@ public void reset() { public static String getImplementation() { init(); try { - return ((MemoryAddress) resampler_get_implementation.invokeExact()).getUtf8String(0L); + return ((MemorySegment) resampler_get_implementation.invokeExact()).getUtf8String(0L); } catch (Throwable e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/eimsound/dsp/timestretchers/NativeTimeStretcher.java b/src/main/java/com/eimsound/dsp/timestretchers/NativeTimeStretcher.java index 421ae35..bd64c2c 100644 --- a/src/main/java/com/eimsound/dsp/timestretchers/NativeTimeStretcher.java +++ b/src/main/java/com/eimsound/dsp/timestretchers/NativeTimeStretcher.java @@ -9,9 +9,9 @@ @SuppressWarnings("unused") public final class NativeTimeStretcher implements AutoCloseable { - private final MemorySession session = MemorySession.openShared(); - private final Addressable pointer; - private Addressable inputBuffersPtr, outputBuffersPtr; + private final Arena arena = Arena.ofShared(); + private final MemorySegment pointer; + private MemorySegment inputBuffersPtr, outputBuffersPtr; private FloatBuffer inputBuffers, outputBuffers; private int inputBufferSize, numChannels, samplesPerBlock, maxFramesNeeded; private final boolean isPlanar; @@ -39,26 +39,26 @@ private static void init() { var lib = NativeLibrary.getLookup(); var linker = Linker.nativeLinker(); get_all_time_stretchers = linker.downcallHandle( - lib.lookup("get_all_time_stretchers").orElseThrow(), + lib.find("get_all_time_stretchers").orElseThrow(), FunctionDescriptor.of( ValueLayout.ADDRESS ) ); create_time_stretcher = linker.downcallHandle( - lib.lookup("create_time_stretcher").orElseThrow(), + lib.find("create_time_stretcher").orElseThrow(), FunctionDescriptor.of( ValueLayout.ADDRESS, ValueLayout.ADDRESS ) ); destroy_time_stretcher = linker.downcallHandle( - lib.lookup("destroy_time_stretcher").orElseThrow(), + lib.find("destroy_time_stretcher").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS ) ); time_stretcher_process = linker.downcallHandle( - lib.lookup("time_stretcher_process").orElseThrow(), + lib.find("time_stretcher_process").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_INT, ValueLayout.ADDRESS, @@ -68,13 +68,13 @@ private static void init() { ) ); time_stretcher_reset = linker.downcallHandle( - lib.lookup("time_stretcher_reset").orElseThrow(), + lib.find("time_stretcher_reset").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS ) ); time_stretcher_flush = linker.downcallHandle( - lib.lookup("time_stretcher_flush").orElseThrow(), + lib.find("time_stretcher_flush").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_INT, ValueLayout.ADDRESS, @@ -82,42 +82,42 @@ private static void init() { ) ); time_stretcher_set_speed_ratio = linker.downcallHandle( - lib.lookup("time_stretcher_set_speed_ratio").orElseThrow(), + lib.find("time_stretcher_set_speed_ratio").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.JAVA_FLOAT ) ); time_stretcher_set_semitones = linker.downcallHandle( - lib.lookup("time_stretcher_set_semitones").orElseThrow(), + lib.find("time_stretcher_set_semitones").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.JAVA_FLOAT ) ); time_stretcher_get_max_frames_needed = linker.downcallHandle( - lib.lookup("time_stretcher_get_max_frames_needed").orElseThrow(), + lib.find("time_stretcher_get_max_frames_needed").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_INT, ValueLayout.ADDRESS ) ); time_stretcher_get_frames_needed = linker.downcallHandle( - lib.lookup("time_stretcher_get_frames_needed").orElseThrow(), + lib.find("time_stretcher_get_frames_needed").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_INT, ValueLayout.ADDRESS ) ); // time_stretcher_is_initialized = linker.downcallHandle( -// lib.lookup("time_stretcher_is_initialized").orElseThrow(), +// lib.find("time_stretcher_is_initialized").orElseThrow(), // FunctionDescriptor.of( // ValueLayout.JAVA_BOOLEAN, // ValueLayout.ADDRESS // ) // ); time_stretcher_initialise = linker.downcallHandle( - lib.lookup("time_stretcher_initialise").orElseThrow(), + lib.find("time_stretcher_initialise").orElseThrow(), FunctionDescriptor.ofVoid( ValueLayout.ADDRESS, ValueLayout.JAVA_FLOAT, @@ -127,7 +127,7 @@ private static void init() { ) ); time_stretcher_is_planar = linker.downcallHandle( - lib.lookup("time_stretcher_is_planar").orElseThrow(), + lib.find("time_stretcher_is_planar").orElseThrow(), FunctionDescriptor.of( ValueLayout.JAVA_BOOLEAN, ValueLayout.ADDRESS @@ -139,7 +139,7 @@ private static void init() { public static String @NotNull [] getAllTimeStretcherNames() { init(); try { - return ((MemoryAddress) get_all_time_stretchers.invokeExact()).getUtf8String(0L).split(","); + return ((MemorySegment) get_all_time_stretchers.invokeExact()).getUtf8String(0L).split(","); } catch (Throwable e) { throw new RuntimeException(e); } @@ -149,7 +149,7 @@ private static void init() { public NativeTimeStretcher(@NotNull String name, float speedRatio, float semitones) { init(); try { - pointer = (MemoryAddress) create_time_stretcher.invokeExact((Addressable) session.allocateUtf8String(name)); + pointer = (MemorySegment) create_time_stretcher.invokeExact(arena.allocateUtf8String(name)); isPlanar = (boolean) time_stretcher_is_planar.invokeExact(pointer); } catch (Throwable e) { throw new RuntimeException(e); @@ -247,7 +247,7 @@ public void initialise(float sourceSampleRate, int samplesPerBlock, int numChann try { time_stretcher_initialise.invokeExact(pointer, sourceSampleRate, samplesPerBlock, numChannels, isRealtime); maxFramesNeeded = (int) time_stretcher_get_max_frames_needed.invokeExact(pointer); - var ptr = session.allocateArray(ValueLayout.JAVA_FLOAT, (long) samplesPerBlock * numChannels); + var ptr = arena.allocateArray(ValueLayout.JAVA_FLOAT, (long) samplesPerBlock * numChannels); outputBuffers = ptr.asByteBuffer().order(ByteOrder.nativeOrder()).asFloatBuffer(); outputBuffersPtr = ptr; if (speedRatio != 1F) time_stretcher_set_speed_ratio.invokeExact(pointer, speedRatio); @@ -262,7 +262,7 @@ public int process(float[] @NotNull [] input, float[] @NotNull [] output, int nu int max = numSamples * numChannels; if (inputBufferSize < max) { inputBufferSize = max; - var ptr = session.allocateArray(ValueLayout.JAVA_FLOAT, inputBufferSize); + var ptr = arena.allocateArray(ValueLayout.JAVA_FLOAT, inputBufferSize); inputBuffers = ptr.asByteBuffer().order(ByteOrder.nativeOrder()).asFloatBuffer(); inputBuffersPtr = ptr; } @@ -285,7 +285,7 @@ public void close() { } catch (Throwable e) { throw new RuntimeException(e); } finally { - session.close(); + arena.close(); } }