Skip to content

Commit

Permalink
Merge pull request #97 from jhasse/psemek-audio
Browse files Browse the repository at this point in the history
Use psemek-audio instead of OpenAL
  • Loading branch information
jhasse authored Dec 29, 2023
2 parents 252a764 + 9ba2bdf commit fd1bd19
Show file tree
Hide file tree
Showing 52 changed files with 3,940 additions and 463 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libgl1-mesa-dev libfreetype6-dev libfontconfig1-dev libxxf86vm-dev libpng-dev libvorbis-dev libopenal-dev g++ libwebp-dev git libsdl2-dev ninja-build
sudo apt install libgl1-mesa-dev libfreetype6-dev libfontconfig1-dev libxxf86vm-dev libpng-dev libvorbis-dev g++ libwebp-dev git libsdl2-dev ninja-build
- name: Configure with CMake and GCC
run: cmake -Bbuild -G"Ninja Multi-Config"
- name: Build Debug
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
image: registry.fedoraproject.org/fedora-minimal:37
steps:
- name: Install dependencies
run: microdnf install -y cmake ninja-build mingw64-pkg-config mingw64-libvorbis mingw64-SDL2 mingw64-fontconfig mingw64-libwebp mingw64-dlfcn mingw64-openal-soft mingw32-nsis mingw64-gcc-c++ tar gzip
run: microdnf install -y cmake ninja-build mingw64-pkg-config mingw64-libvorbis mingw64-SDL2 mingw64-fontconfig mingw64-libwebp mingw64-dlfcn mingw32-nsis mingw64-gcc-c++ tar gzip
- uses: actions/checkout@v3
- name: Build with CMake and GCC
run: |
Expand Down
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ image: registry.fedoraproject.org/fedora-minimal:38
linux:
stage: build
script:
- microdnf install -y cmake ninja-build gcc-c++ fontconfig-devel freetype-devel libvorbis-devel libwebp-devel SDL2-devel openal-soft-devel libtheora-devel clang util-linux >/dev/null
- microdnf install -y cmake ninja-build gcc-c++ fontconfig-devel freetype-devel libvorbis-devel libwebp-devel SDL2-devel libtheora-devel clang util-linux >/dev/null
- CXXFLAGS=-fdiagnostics-color cmake -Bbuild -GNinja
- cd build
- ninja
Expand All @@ -29,7 +29,7 @@ linux:
mingw:
stage: build
script:
- microdnf install -y gcc-c++ cmake ninja-build mingw64-pkg-config mingw64-libvorbis mingw64-SDL2 mingw64-fontconfig mingw64-libwebp mingw64-dlfcn mingw64-openal-soft mingw64-gcc-c++ > /dev/null
- microdnf install -y cmake ninja-build mingw64-pkg-config mingw64-libvorbis mingw64-SDL2 mingw64-fontconfig mingw64-libwebp mingw64-dlfcn mingw64-gcc-c++ > /dev/null
- mingw64-cmake -GNinja -Bbuild-debug -DCMAKE_BUILD_TYPE=Debug
- ninja -C build-debug
- mingw64-cmake -GNinja -Bbuild-release -DCMAKE_BUILD_TYPE=Release
Expand Down
91 changes: 42 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

file(GLOB SRC src/*.cpp src/jngl/*.cpp)
file(GLOB SRC src/*.cpp src/jngl/*.cpp
src/audio/*.cpp
src/audio/effect/*.cpp
)
add_library(jngl ${SRC})
file(GLOB HEADERS src/*.hpp src/jngl/*.hpp)
target_sources(jngl PRIVATE ${HEADERS})
Expand Down Expand Up @@ -67,15 +70,13 @@ if(MSVC OR IOS OR ANDROID OR EMSCRIPTEN)
endif()
option(JNGL_BUILD_WEBP_FROM_SOURCE "Build libwebp from source instead of using the system version" ${JNGL_BUILD_WEBP_FROM_SOURCE_DEFAULT})

set(ALSOFT_TESTS OFF CACHE BOOL "Build and install test programs" FORCE)
set(ALSOFT_EXAMPLES OFF CACHE BOOL "Build and install example programs" FORCE)
set(ALSOFT_UTILS OFF CACHE BOOL "Build and install utility programs" FORCE)

if (ANDROID)
find_package(oboe REQUIRED CONFIG)
target_link_libraries(jngl PRIVATE oboe::oboe)
file(GLOB ANDROID_SOURCES src/android/*.cpp)
target_sources(jngl PRIVATE ${ANDROID_SOURCES})
target_sources(jngl PRIVATE ${ANDROID_SOURCES} src/audio/android/engine.cpp)
elseif(IOS)
file(GLOB SRC src/ios/*.cpp src/ios/*.mm src/ios/*.h)
file(GLOB SRC src/ios/*.cpp src/ios/*.mm src/audio/ios/Engine.mm src/ios/*.h)
target_sources(jngl PRIVATE ${SRC} src/mac/message.cpp)
elseif (UNIX)
file(GLOB SRC src/sdl/*.cpp src/sdl/controller/SdlController.cpp)
Expand All @@ -93,6 +94,7 @@ elseif (UNIX)
else()
file(GLOB SRC src/linux/*.cpp src/linux/*.c)
target_sources(jngl PRIVATE ${SRC})
target_link_libraries(jngl PRIVATE atomic)
endif()

target_link_libraries(jngl PRIVATE $<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:stdc++fs>)
Expand Down Expand Up @@ -189,22 +191,12 @@ endif()
if(ANDROID)
target_compile_definitions(jngl PRIVATE NOPNG)

CPMAddPackage(NAME openal
URL https://github.com/kcat/openal-soft/archive/refs/tags/1.21.1.zip
URL_HASH SHA1=1442363faf47a5a7cd6287513068ecd6c70e747e
OPTIONS
"LIBTYPE STATIC"
"ALSOFT_INSTALL_CONFIG OFF"
"ALSOFT_INSTALL_HRTF_DATA OFF"
"ALSOFT_INSTALL_AMBDEC_PRESETS OFF"
"ALSOFT_BACKEND_WAVE OFF"
"ALSOFT_CPUEXT_NEON OFF"
)
set(OPENAL_LIBRARY OpenAL)

target_include_directories(jngl PUBLIC ${ANDROID_NDK}/sources/android/native_app_glue)
target_include_directories(jngl PRIVATE ${OGG_INCLUDE_DIRS} ${VORBIS_SRC_DIR}/include)
else()
if(NOT IOS)
target_sources(jngl PRIVATE src/audio/sdl/engine.cpp)
endif()
if(UNIX AND NOT IOS AND NOT EMSCRIPTEN)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
Expand Down Expand Up @@ -232,46 +224,51 @@ else()
if(MSVC)
target_compile_definitions(jngl PUBLIC _USE_MATH_DEFINES)
if(JNGL_SDL2)
set(SDL_SENSOR OFF CACHE BOOL "" FORCE) # doesn't work with UWP
FetchContent_Declare(sdl2
CPMAddPackage(NAME sdl2
URL https://www.libsdl.org/release/SDL2-2.28.4.zip
URL_HASH SHA1=0d9e0da0e935c4f0524cfd16d47d38b6045b9573
OPTIONS
"SDL_SENSOR OFF" # doesn't work with UWP
)
else()
CPMAddPackage(NAME sdl2
URL https://www.libsdl.org/release/SDL2-2.28.4.zip
URL_HASH SHA1=0d9e0da0e935c4f0524cfd16d47d38b6045b9573
OPTIONS
"SDL_ATOMIC OFF"
"SDL_CPUINFO OFF"
"SDL_DLOPEN OFF"
"SDL_FILE OFF"
"SDL_FILESYSTEM OFF"
"SDL_HAPTIC OFF"
"SDL_LOADSO ON"
"SDL_LOCALE OFF"
"SDL_POWER OFF"
"SDL_RENDER OFF"
"SDL_SENSOR OFF"
"SDL_SHARED OFF"
"SDL_TIMERS OFF"
)
FetchContent_MakeAvailable(sdl2)
target_link_libraries(jngl PRIVATE SDL2-static)
endif()
target_link_libraries(jngl PRIVATE SDL2-static)
if(WINDOWS_STORE)
target_compile_definitions(jngl PUBLIC JNGL_UWP)
target_include_directories(jngl PUBLIC ${sdl2_SOURCE_DIR}/include ${sdl2_BINARY_DIR}/include) # TODO: This should be PRIVATE
FetchContent_Declare(openal
GIT_REPOSITORY https://github.com/jhasse/openal-soft-winphone
GIT_TAG e4f3681316b1e8d8d68dfc31b1fc952d9bba085d)
target_link_options(jngl PUBLIC $<IF:$<CONFIG:Debug>,/defaultlib:vccorlibd.lib /defaultlib:msvcrtd.lib,/defaultlib:vccorlib.lib /defaultlib:msvcrt.lib>)
else()
FetchContent_Declare(openal
URL https://github.com/kcat/openal-soft/archive/refs/tags/1.21.1.zip
URL_HASH SHA1=1442363faf47a5a7cd6287513068ecd6c70e747e)
set(ALSOFT_NO_CONFIG_UTIL ON CACHE BOOL "Disable building the alsoft-config utility" FORCE)
set(LIBTYPE "STATIC" CACHE STRING "" FORCE)
target_compile_definitions(jngl PRIVATE AL_LIBTYPE_STATIC)
endif()
FetchContent_MakeAvailable(openal)
set(OPENAL_LIBRARY OpenAL)

elseif(IOS)
target_compile_options(jngl PRIVATE -Wno-deprecated-declarations) # OpenAL
target_compile_definitions(jngl PRIVATE IOS)
target_compile_definitions(jngl PUBLIC GLES_SILENCE_DEPRECATION)
target_include_directories(jngl PUBLIC include/ios)
find_library(IOS_OPENGLES OpenGLES)
find_library(IOS_OPENAL OpenAL)
find_library(IOS_QUARTZCORE QuartzCore)
find_library(IOS_UIKIT UIKit)
find_library(IOS_AVFOUNDATION AVFoundation)
find_library(IOS_GAMECONTROLLER GameController)
find_library(IOS_AudioToolbox AudioToolbox)
target_link_libraries(jngl PRIVATE
${IOS_OPENGLES} ${IOS_OPENAL} ${IOS_QUARTZCORE} ${IOS_UIKIT} ${IOS_AVFOUNDATION}
${IOS_GAMECONTROLLER}
${IOS_OPENGLES} ${IOS_QUARTZCORE} ${IOS_UIKIT} ${IOS_AVFOUNDATION}
${IOS_GAMECONTROLLER} ${IOS_AudioToolbox}
)

if(NOT hasParent)
Expand All @@ -287,8 +284,6 @@ else()
set_target_properties(jngl-test PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/data/ios/jngl-test.in.plist")
endif()
else()
find_package(OpenAL REQUIRED)

if(NOT JNGL_BUILD_WEBP_FROM_SOURCE)
find_package(WebP)
if(WebP_FOUND)
Expand All @@ -300,11 +295,9 @@ else()

find_package(PkgConfig)
if(PkgConfig_FOUND)
if(JNGL_SDL2)
pkg_check_modules(SDL2 REQUIRED sdl2)
target_include_directories(jngl PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(jngl PRIVATE ${SDL2_LINK_LIBRARIES})
endif()
pkg_check_modules(SDL2 REQUIRED sdl2)
target_include_directories(jngl PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(jngl PRIVATE ${SDL2_LINK_LIBRARIES})
if(JNGL_VIDEO)
if(APPLE)
# On macOS we'll build theora from source, since Homebrew's version crashes due
Expand Down Expand Up @@ -435,7 +428,7 @@ endif()

target_include_directories(jngl PRIVATE ${FREETYPE_INCLUDE_DIRS})
target_link_directories(jngl PUBLIC ${FREETYPE_LIBRARY_DIRS})
target_link_libraries(jngl PUBLIC ${FREETYPE_LIBRARIES} ${OPENAL_LIBRARY})
target_link_libraries(jngl PUBLIC ${FREETYPE_LIBRARIES})

if(NOT hasParent AND NOT WINDOWS_STORE)
include(CTest)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ cmake --build build

```
sudo apt-get install libgl1-mesa-dev libfreetype6-dev libfontconfig1-dev libxxf86vm-dev \
libpng-dev libvorbis-dev libopenal-dev cmake g++ \
libpng-dev libvorbis-dev cmake g++ \
libwebp-dev git libsdl2-dev
```

### Fedora

```
sudo dnf install fontconfig-devel freetype-devel libvorbis-devel libwebp-devel \
cmake SDL2-devel openal-soft-devel gcc-c++
cmake SDL2-devel gcc-c++
```

### Arch Linux

```
pacman -Syu --needed cmake gcc sdl2 pkg-config fontconfig libwebp openal libvorbis
pacman -Syu --needed cmake gcc sdl2 pkg-config fontconfig libwebp libvorbis
```

## Windows
Expand All @@ -50,7 +50,7 @@ pacman -Syu --needed cmake gcc sdl2 pkg-config fontconfig libwebp openal libvorb
Set up [MSYS2](https://www.msys2.org/) and install the following in a MinGW-w64 Win64 Shell:

```
pacman -Syu --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-openal \
pacman -Syu --needed mingw-w64-x86_64-gcc \
mingw-w64-x86_64-freetype mingw-w64-x86_64-libvorbis mingw-w64-x86_64-libwebp \
mingw-w64-x86_64-dlfcn mingw-w64-x86_64-cmake make mingw-w64-x86_64-gdb \
mingw-w64-x86_64-libtheora
Expand Down
9 changes: 9 additions & 0 deletions android/test/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ android {
applicationId = 'com.bixense.jngl_test'
minSdkVersion 21
targetSdkVersion 31
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
}
}
}
buildFeatures {
prefab true
}
buildTypes {
release {
Expand All @@ -31,4 +39,5 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.oboe:oboe:1.7.0'
}
1 change: 1 addition & 0 deletions android/test/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/../../../../../.. ${CMAKE_CURRENT_BINARY_
# add lib dependencies
target_link_libraries(jngl-test
android
log
native_app_glue
EGL
GLESv3
Expand Down
2 changes: 1 addition & 1 deletion doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Switch<sup><a href="#fn1">1</a></sup> and the Web.
static linking
* OpenGL (ES) 3.0 accelerated
* PNG, BMP and [WebP](https://developers.google.com/speed/webp/) image support
* Ogg Vorbis audio support using OpenAL
* Ogg Vorbis audio support with support for effects like pitch shifting
* Theora video playback support
* UTF-8 text output using [FreeType](http://www.freetype.org/)

Expand Down
3 changes: 3 additions & 0 deletions examples/videoplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ JNGL_MAIN_BEGIN {
while (jngl::running()) {
jngl::updateInput();
video.draw();
if (video.finished()) {
jngl::setTitle(filename + " [FINISHED]");
}
jngl::swapBuffers();
}
} JNGL_MAIN_END
Loading

0 comments on commit fd1bd19

Please sign in to comment.