Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,22 @@ find_package(Threads REQUIRED)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(MafiaNetHelpers)

# RakVoice is built into the core library, so its dependencies (Opus, RNNoise)
# are always fetched, before the Source subdirectory that consumes them.
include(FetchVoiceDependencies)

# Platform-specific settings
if(WIN32)
add_compile_definitions(
_CRT_SECURE_NO_DEPRECATE
_CRT_NONSTDC_NO_DEPRECATE
# Suppress the legacy Winsock 1.1 header. Several samples include
# <windows.h> before the MafiaNet headers that pull in <winsock2.h>;
# without this, windows.h drags in winsock.h first and winsock2.h then
# redefines sockaddr/fd_set/etc. (C2011/C2375). winsock2.h itself
# defines _WINSOCKAPI_ for the same reason, so predefining it globally
# is consistent and harmless for the core library.
_WINSOCKAPI_
)
endif()

Expand All @@ -58,7 +69,7 @@ add_subdirectory(Source)

# Samples and extensions
if(MAFIANET_BUILD_SAMPLES)
# Fetch dependencies (bzip2, miniupnpc, opus, rnnoise)
# Fetch sample/extension dependencies (bzip2, miniupnpc, jansson)
include(FetchDependencies)
add_subdirectory(Samples)
add_subdirectory(DependentExtensions)
Expand Down
8 changes: 3 additions & 5 deletions DependentExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MafiaNet Dependent Extensions
#
# Dependencies (bzip2, miniupnpc, opus, rnnoise) are fetched via FetchContent
# Dependencies (bzip2, miniupnpc, jansson) are fetched via FetchContent
# in cmake/FetchDependencies.cmake
#
# Copyright (c) 2024, MafiaHub
Expand All @@ -12,10 +12,8 @@ add_subdirectory(Autopatcher)
# Lobby2 extension (matchmaking and lobby system)
add_subdirectory(Lobby2)

# RakVoice - voice compression and transmission (uses opus, rnnoise from FetchContent)
add_library(RakVoice STATIC RakVoice.cpp RakVoice.h)
target_link_libraries(RakVoice PUBLIC MafiaNet PRIVATE opus rnnoise)
target_include_directories(RakVoice PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# RakVoice (voice compression using Opus + RNNoise) is built into the core
# MafiaNet library; see Source/CMakeLists.txt.

# Optional extensions based on available dependencies

Expand Down
1 change: 0 additions & 1 deletion Samples/RakVoice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ if(PORTAUDIO_FOUND)
add_executable(RakVoiceSample main.cpp)
target_link_libraries(RakVoiceSample PRIVATE
MafiaNet
RakVoice
${PORTAUDIO_LIBRARIES}
)
target_include_directories(RakVoiceSample PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion Samples/RakVoice/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "mafianet/peerinterface.h"
#include "mafianet/MessageIdentifiers.h"

#include "RakVoice.h"
#include "mafianet/RakVoice.h"
#include "mafianet/statistics.h"
#include "mafianet/NatPunchthroughClient.h"
#include "mafianet/BitStream.h"
Expand Down
1 change: 0 additions & 1 deletion Samples/RakVoiceDSound/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ if(DSOUND_INCLUDE_DIR AND DSOUND_LIBRARY)

target_link_libraries(RakVoiceDSoundSample PRIVATE
MafiaNet
RakVoice
${DSOUND_LIBRARY}
${DXERR_LIBRARY}
winmm
Expand Down
2 changes: 1 addition & 1 deletion Samples/RakVoiceDSound/DSoundVoiceAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ of each frame.
#ifndef __DSOUNDVOICEADAPTER_H
#define __DSOUNDVOICEADAPTER_H

#include "RakVoice.h"
#include "mafianet/RakVoice.h"

// If you get:
// Error 1 fatal error C1083: Cannot open include file: 'dsound.h': No such file or directory
Expand Down
2 changes: 1 addition & 1 deletion Samples/RakVoiceDSound/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "mafianet/MessageIdentifiers.h"

#include "mafianet/sleep.h"
#include "RakVoice.h"
#include "mafianet/RakVoice.h"
#include "mafianet/statistics.h"
#include "mafianet/GetTime.h"
#include "mafianet/assert.h"
Expand Down
1 change: 0 additions & 1 deletion Samples/RakVoiceFMOD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ if(FMOD_INCLUDE_DIR AND FMOD_LIBRARY)

target_link_libraries(RakVoiceFMODSample PRIVATE
MafiaNet
RakVoice
${FMOD_LIBRARY}
)

Expand Down
2 changes: 1 addition & 1 deletion Samples/RakVoiceFMOD/FMODVoiceAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef __FMODVOICEBRIDGE_H
#define __FMODVOICEBRIDGE_H

#include "RakVoice.h"
#include "mafianet/RakVoice.h"

// If you get:
// Error 1 fatal error C1083: Cannot open include file: 'fmod.hpp': No such file or directory c:\raknet\samples\rakvoicefmod\fmodvoiceadapter.h 9
Expand Down
2 changes: 1 addition & 1 deletion Samples/RakVoiceFMOD/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "mafianet/Gets.h"

#include "mafianet/sleep.h"
#include "RakVoice.h"
#include "mafianet/RakVoice.h"
#include "mafianet/statistics.h"
#include "mafianet/GetTime.h"
#include "mafianet/assert.h"
Expand Down
20 changes: 20 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ set(MAFIANET_SOURCES
src/RakSleep.cpp
src/RakString.cpp
src/RakThread.cpp
src/RakVoice.cpp
src/RakWString.cpp
src/Rand.cpp
src/RandSync.cpp
Expand Down Expand Up @@ -222,6 +223,7 @@ set(MAFIANET_HEADERS
include/mafianet/PS3Includes.h
include/mafianet/PS4Includes.h
include/mafianet/Rackspace.h
include/mafianet/RakVoice.h
include/mafianet/Rand.h
include/mafianet/RandSync.h
include/mafianet/ReadyEvent.h
Expand Down Expand Up @@ -319,6 +321,12 @@ function(mafianet_configure_target target_name)
PRIVATE
Threads::Threads
$<$<PLATFORM_ID:Windows>:ws2_32>
# RakVoice (built into the core library) requires the Opus codec and
# RNNoise noise suppression, fetched in FetchVoiceDependencies. These
# are bundled into the MafiaNet export set (see Installation below) so
# installed static-library consumers can resolve the symbols.
opus
rnnoise
)

target_compile_definitions(${target_name}
Expand Down Expand Up @@ -402,6 +410,18 @@ install(TARGETS ${MAFIANET_INSTALL_TARGETS}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# RakVoice links the Opus and RNNoise static libraries into the core library.
# Bundle them into the MafiaNet export so installed static-library consumers can
# resolve opus_*/rnnoise_* symbols (neither dependency ships its own CMake config
# package here). Opus also self-exports to its own OpusTargets set, which is
# harmless: a target may belong to multiple export sets.
install(TARGETS opus rnnoise
EXPORT MafiaNetTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

# Install headers
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* license found in the license.txt file in the root directory of this source tree.
*/

#include "RakVoice.h"
#include "mafianet/RakVoice.h"
#include <opus.h>
#include <rnnoise.h>
#include "mafianet/BitStream.h"
Expand Down
84 changes: 4 additions & 80 deletions cmake/FetchDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,87 +62,14 @@ set(UPNPC_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(UPNPC_BUILD_SAMPLE OFF CACHE BOOL "" FORCE)
set(UPNPC_NO_INSTALL ON CACHE BOOL "" FORCE)

# -----------------------------------------------------------------------------
# Opus - audio codec for RakVoice
# -----------------------------------------------------------------------------
FetchContent_Declare(
Opus
GIT_REPOSITORY https://github.com/xiph/opus.git
GIT_TAG v1.6.1
GIT_SHALLOW TRUE
)

# Opus configuration
set(OPUS_BUILD_SHARED_LIBRARY OFF CACHE BOOL "" FORCE)
set(OPUS_BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(OPUS_BUILD_PROGRAMS OFF CACHE BOOL "" FORCE)
set(OPUS_INSTALL_PKG_CONFIG_MODULE OFF CACHE BOOL "" FORCE)
set(OPUS_INSTALL_CMAKE_CONFIG_MODULE OFF CACHE BOOL "" FORCE)

# -----------------------------------------------------------------------------
# RNNoise - neural network noise suppression for RakVoice
# -----------------------------------------------------------------------------
# RNNoise doesn't have a proper CMake build, so we fetch and build manually
FetchContent_Declare(
rnnoise
GIT_REPOSITORY https://github.com/xiph/rnnoise.git
GIT_TAG v0.2
GIT_SHALLOW TRUE
)

# RNNoise model data (neural network weights)
set(RNNOISE_MODEL_VERSION "0b50c45")
FetchContent_Declare(
rnnoise_model
URL https://media.xiph.org/rnnoise/models/rnnoise_data-${RNNOISE_MODEL_VERSION}.tar.gz
URL_HASH SHA256=4ac81c5c0884ec4bd5907026aaae16209b7b76cd9d7f71af582094a2f98f4b43
)
# Note: Opus and RNNoise (used by RakVoice, which is built into the core
# library) are fetched separately in FetchVoiceDependencies.cmake so they are
# always available, independent of MAFIANET_BUILD_SAMPLES.

# -----------------------------------------------------------------------------
# Fetch all dependencies
# -----------------------------------------------------------------------------
FetchContent_MakeAvailable(bzip2 miniupnpc Opus jansson)

# Fetch rnnoise separately (needs manual target creation)
FetchContent_GetProperties(rnnoise)
if(NOT rnnoise_POPULATED)
FetchContent_Populate(rnnoise)
endif()

# Fetch rnnoise model data
FetchContent_GetProperties(rnnoise_model)
if(NOT rnnoise_model_POPULATED)
FetchContent_Populate(rnnoise_model)
endif()

# -----------------------------------------------------------------------------
# RNNoise - manual target creation (no upstream CMakeLists.txt)
# -----------------------------------------------------------------------------
if(NOT TARGET rnnoise)
add_library(rnnoise STATIC
${rnnoise_SOURCE_DIR}/src/denoise.c
${rnnoise_SOURCE_DIR}/src/rnn.c
${rnnoise_SOURCE_DIR}/src/rnnoise_tables.c
${rnnoise_SOURCE_DIR}/src/nnet.c
${rnnoise_SOURCE_DIR}/src/nnet_default.c
${rnnoise_SOURCE_DIR}/src/pitch.c
${rnnoise_SOURCE_DIR}/src/kiss_fft.c
${rnnoise_SOURCE_DIR}/src/celt_lpc.c
)
# Get Opus source directory for celt headers (needed by vec_neon.h)
FetchContent_GetProperties(Opus)
target_include_directories(rnnoise
PUBLIC
${rnnoise_SOURCE_DIR}/include
PRIVATE
${rnnoise_SOURCE_DIR}/src
${rnnoise_model_SOURCE_DIR}/src # Contains rnnoise_data.h
${opus_SOURCE_DIR}/celt # Contains os_support.h
${opus_SOURCE_DIR}/include # Contains opus_defines.h
)
target_compile_definitions(rnnoise PRIVATE COMPILE_OPUS=1)
set_target_properties(rnnoise PROPERTIES FOLDER "Dependencies")
endif()
FetchContent_MakeAvailable(bzip2 miniupnpc jansson)

# -----------------------------------------------------------------------------
# Create aliases for compatibility with existing target names
Expand All @@ -164,9 +91,6 @@ endif()
if(TARGET libminiupnpc-static)
set_target_properties(libminiupnpc-static PROPERTIES FOLDER "Dependencies")
endif()
if(TARGET opus)
set_target_properties(opus PROPERTIES FOLDER "Dependencies")
endif()
if(TARGET jansson)
set_target_properties(jansson PROPERTIES FOLDER "Dependencies")
endif()
Expand Down
Loading
Loading