Enabling Portaudio in beatoraja on OSX

未分类
2.4k 词

Preface

This is a small guide of how to compile and enable portaudio in beatoraja on osx, the guide includes some manual modifications, so it assumes that readers have the basic knowledge of computer and git.

This guide’s target is building the jportaudio.dylib on macos and make beatoraja reads it.

Process

  • Download portaudio library by brew install portaudio
  • Copy portaudio.h file to an library path like /usr/local/inlcude, you can find the file under /opt/homebrew/Cellar/portaudio[version]/include
  • git clone https://github.com/philburk/portaudio-java
  • Edit CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
cmake_minimum_required(VERSION 3.2)

project(jportaudio_project)

# somehow, $ENV{JAVA_HOME} isn't work on my machine, so I replaced them with absolute path
# $which java to find where java is

#include_directories($ENV{JAVA_HOME}/include)
#include_directories($ENV{JAVA_HOME}/include/darwin)
#include_directories($ENV{JAVA_HOME}/include/linux)

# DON'T COPY THIS DIRECTLY
include_directories(/Library/Java/JavaVirtualMachines/liberica-jdk-17-full.jdk/Contents/Home/inlcude)
include_directories(/Library/Java/JavaVirtualMachines/liberica-jdk-17-full.jdk/Contents/Home/inlcude/darwin)

# for installed portaudio.h
# If you didn't put portaudio.h here, modify this line
include_directories(/usr/local/include)

link_directories(/usr/local/lib)
# No need because we downloaded portaudio through brew, brew will link the files for you under /usr/local/lib
#link_directories(../portaudio/pagit)
#link_directories(../portaudio/pagit/lib)

set (jportaudio_sources
src/main/jni/com_portaudio_BlockingStream.c
src/main/jni/com_portaudio_PortAudio.c
src/main/jni/jpa_tools.c
)

set (jportaudio_libname jportaudio_0_1_0)

add_library(${jportaudio_libname} SHARED ${jportaudio_sources})
target_link_libraries(${jportaudio_libname} portaudio)

install(TARGETS ${jportaudio_libname} DESTINATION lib)
  • mkdir build
    cmake -B build
    cd build
    

After

You should be able to see a dylib file under build folder, and there should also be a dylib file under ~/Library/Java/Extensions/. The latter one is a ‘global’ installation. You should be able to use portaudio in beatoraja without any further changes. And if it still fails to find dylib file. Try:

  • See files under ~/Library/Java/Extensions/, if the file is not named as libjportaudio.dylib, try renaming it
  • If there’s no file under ~/Library/Java/Extensions/, try copying the dylib file from build directory. You can also place the file along with the raja’s jar file, it should be working too.