Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ex_hrtf_spatialization example have no sound bug #216

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Q-Qian
Copy link
Contributor

@Q-Qian Q-Qian commented Jan 26, 2024

I don't known if this is a better way to fix this bug, if so, I hope the author can adopt it. If not, just reject it.

@meshula
Copy link
Member

meshula commented Jan 26, 2024

Thanks for thinking about this some more.

I think it would be good to add an option

cmake/LabSound.cmake:

option(LABSOUND_INTERNAL_LIBSAMPLERATE, "Use internal libsamplerate", ON)

and then we could elide the existing libsamplerate internal c file if that option is OFF, and all the currently commented sections could be guarded by the option as well. Then you wouldn't have to modify the cmake file at all, just pass in -DLABSOUND_INTERNAL_LIBSAMPLERATE=OFF in your build.

As a further question beyond the suggestion of adding an option, does it make sense for your use to use add_subdirectory for libsamplerate as a submodule, or would it be better to use find_package? If LABSOUND_INTERNAL_LIBSAMPLERATE is OFF, and the submodule is not available, and find_package does not find it, we could use FetchContent to get libsamplerate.

@Q-Qian Q-Qian closed this Jan 29, 2024
@Q-Qian
Copy link
Contributor Author

Q-Qian commented Jan 29, 2024

Thanks for thinking about this some more.

I think it would be good to add an option

cmake/LabSound.cmake:

option(LABSOUND_INTERNAL_LIBSAMPLERATE, "Use internal libsamplerate", ON)

and then we could elide the existing libsamplerate internal c file if that option is OFF, and all the currently commented sections could be guarded by the option as well. Then you wouldn't have to modify the cmake file at all, just pass in -DLABSOUND_INTERNAL_LIBSAMPLERATE=OFF in your build.

As a further question beyond the suggestion of adding an option, does it make sense for your use to use add_subdirectory for libsamplerate as a submodule, or would it be better to use find_package? If LABSOUND_INTERNAL_LIBSAMPLERATE is OFF, and the submodule is not available, and find_package does not find it, we could use FetchContent to get libsamplerate.

your ideas are more thoughtful, look forward to your repair update.

@meshula meshula reopened this Jan 29, 2024
@meshula
Copy link
Member

meshula commented Jan 29, 2024

I'm going to leave this open as we think about it.

Would this work in your case?

diff --git a/cmake/LabSound.cmake b/cmake/LabSound.cmake
index 1b8757ad..8abd7691 100644
--- a/cmake/LabSound.cmake
+++ b/cmake/LabSound.cmake
@@ -44,17 +44,28 @@ elseif (LABSOUND_USE_RTAUDIO)
     )
 endif()
 
-#option(LIBSAMPLERATE_EXAMPLES "" OFF)
-#option(LIBSAMPLERATE_INSTALL "" ON)
-#option(BUILD_TESTING "" OFF) # suppress testing of libsamplerate
-#add_subdirectory("${LABSOUND_ROOT}/third_party/libsamplerate")
+option(LABSOUND_INTERNAL_LIBSAMPLERATE, "Use internal libsamplerate", ON)
+if (LABSOUND_INTERNAL_LIBSAMPLERATE)
+    set(LABSOUND_LSR "${LABSOUND_ROOT}/src/internal/src/samplerate.c")
+else()
+    find_package(libsamplerate)
+    if (NOT libsamplerate_FOUND)
+        message(INFO "libsamplerate not found, using submodule")
+        option(LIBSAMPLERATE_EXAMPLES "" OFF)
+        option(LIBSAMPLERATE_INSTALL "" ON)
+        option(BUILD_TESTING "" OFF) # suppress testing of libsamplerate
+        add_subdirectory("${LABSOUND_ROOT}/third_party/libsamplerate")
+    endif()
+    set(LABSOUND_LSR SampleRate::samplerate)
+endif()
 
 file(GLOB labsnd_core_h     "${LABSOUND_ROOT}/include/LabSound/core/*")
 file(GLOB labsnd_extended_h "${LABSOUND_ROOT}/include/LabSound/extended/*")
 file(GLOB labsnd_core       "${LABSOUND_ROOT}/src/core/*")
 file(GLOB labsnd_extended   "${LABSOUND_ROOT}/src/extended/*")
 file(GLOB labsnd_int_h      "${LABSOUND_ROOT}/src/internal/*")
-file(GLOB labsnd_int_src    "${LABSOUND_ROOT}/src/internal/src/*")
+# only pick up the cpp, don't pick up libsamplerate.c
+file(GLOB labsnd_int_src    "${LABSOUND_ROOT}/src/internal/src/*.cpp")
 
 # FFT
 if (IOS)
@@ -79,6 +90,7 @@ add_library(LabSound STATIC
     ${labsnd_int_h}      ${labsnd_int_src}
     ${labsnd_fft_src}
     ${ooura_src}
+    ${LABSOUND_LSR}
  )
 
  #--- CONFIGURE RTAUDIO

@Q-Qian
Copy link
Contributor Author

Q-Qian commented Jan 29, 2024

I'm going to leave this open as we think about it.

Would this work in your case?

diff --git a/cmake/LabSound.cmake b/cmake/LabSound.cmake
index 1b8757ad..8abd7691 100644
--- a/cmake/LabSound.cmake
+++ b/cmake/LabSound.cmake
@@ -44,17 +44,28 @@ elseif (LABSOUND_USE_RTAUDIO)
     )
 endif()
 
-#option(LIBSAMPLERATE_EXAMPLES "" OFF)
-#option(LIBSAMPLERATE_INSTALL "" ON)
-#option(BUILD_TESTING "" OFF) # suppress testing of libsamplerate
-#add_subdirectory("${LABSOUND_ROOT}/third_party/libsamplerate")
+option(LABSOUND_INTERNAL_LIBSAMPLERATE, "Use internal libsamplerate", ON)
+if (LABSOUND_INTERNAL_LIBSAMPLERATE)
+    set(LABSOUND_LSR "${LABSOUND_ROOT}/src/internal/src/samplerate.c")
+else()
+    find_package(libsamplerate)
+    if (NOT libsamplerate_FOUND)
+        message(INFO "libsamplerate not found, using submodule")
+        option(LIBSAMPLERATE_EXAMPLES "" OFF)
+        option(LIBSAMPLERATE_INSTALL "" ON)
+        option(BUILD_TESTING "" OFF) # suppress testing of libsamplerate
+        add_subdirectory("${LABSOUND_ROOT}/third_party/libsamplerate")
+    endif()
+    set(LABSOUND_LSR SampleRate::samplerate)
+endif()
 
 file(GLOB labsnd_core_h     "${LABSOUND_ROOT}/include/LabSound/core/*")
 file(GLOB labsnd_extended_h "${LABSOUND_ROOT}/include/LabSound/extended/*")
 file(GLOB labsnd_core       "${LABSOUND_ROOT}/src/core/*")
 file(GLOB labsnd_extended   "${LABSOUND_ROOT}/src/extended/*")
 file(GLOB labsnd_int_h      "${LABSOUND_ROOT}/src/internal/*")
-file(GLOB labsnd_int_src    "${LABSOUND_ROOT}/src/internal/src/*")
+# only pick up the cpp, don't pick up libsamplerate.c
+file(GLOB labsnd_int_src    "${LABSOUND_ROOT}/src/internal/src/*.cpp")
 
 # FFT
 if (IOS)
@@ -79,6 +90,7 @@ add_library(LabSound STATIC
     ${labsnd_int_h}      ${labsnd_int_src}
     ${labsnd_fft_src}
     ${ooura_src}
+    ${LABSOUND_LSR}
  )
 
  #--- CONFIGURE RTAUDIO

report error while cmake:
CMake Error at cmake/LabSound.cmake:53 (option):
option called with incorrect number of arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants