Skip to content

Commit

Permalink
update to java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirasawaSama committed Dec 10, 2023
1 parent 6813f23 commit c404240
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 78 deletions.
18 changes: 6 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -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
46 changes: 23 additions & 23 deletions src/main/java/com/eimsound/dsp/timestretchers/NativeFFT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -50,15 +50,15 @@ 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,
ValueLayout.ADDRESS
)
);
fft_forward_polar = linker.downcallHandle(
lib.lookup("fft_forward_polar").orElseThrow(),
lib.find("fft_forward_polar").orElseThrow(),
FunctionDescriptor.ofVoid(
ValueLayout.ADDRESS,
ValueLayout.ADDRESS,
Expand All @@ -67,15 +67,15 @@ 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,
ValueLayout.ADDRESS
)
);
fft_inverse = linker.downcallHandle(
lib.lookup("fft_inverse").orElseThrow(),
lib.find("fft_inverse").orElseThrow(),
FunctionDescriptor.ofVoid(
ValueLayout.ADDRESS,
ValueLayout.ADDRESS,
Expand All @@ -84,15 +84,15 @@ 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,
ValueLayout.ADDRESS
)
);
fft_inverse_polar = linker.downcallHandle(
lib.lookup("fft_inverse_polar").orElseThrow(),
lib.find("fft_inverse_polar").orElseThrow(),
FunctionDescriptor.ofVoid(
ValueLayout.ADDRESS,
ValueLayout.ADDRESS,
Expand All @@ -101,22 +101,22 @@ 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,
ValueLayout.ADDRESS
)
);
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
)
Expand All @@ -126,69 +126,69 @@ 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) {
throw new RuntimeException(e);
}
}

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) {
throw new RuntimeException(e);
}
}

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) {
throw new RuntimeException(e);
}
}

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) {
throw new RuntimeException(e);
}
}

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) {
throw new RuntimeException(e);
}
}

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) {
throw new RuntimeException(e);
}
}

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) {
throw new RuntimeException(e);
}
}

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) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,7 +9,6 @@
import java.util.Objects;

final class NativeLibrary {
private static MemorySession session;
private static final String fileName;
private static SymbolLookup lookup;

Expand All @@ -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;
}

Expand Down
Loading

0 comments on commit c404240

Please sign in to comment.