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

[audio] Unable to hear any sound #3448

Closed
4 tasks done
wilsonsilva opened this issue Oct 21, 2023 · 13 comments
Closed
4 tasks done

[audio] Unable to hear any sound #3448

wilsonsilva opened this issue Oct 21, 2023 · 13 comments

Comments

@wilsonsilva
Copy link
Contributor

Please, before submitting a new issue verify and check:

  • I tested it on latest raylib version from master branch (c66eb49), 4.5.0 branch and Homebrew formula
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

I can't hear any sound on any of the audio examples. No errors either.

Environment

Model Name: MacBook Pro
Model Identifier: MacBookPro18,2
Chip: Apple M1 Max
Total Number of Cores: 10 (8 performance and 2 efficiency)
Memory: 64 GB
System Firmware Version: 10151.1.1
OS Loader Version: 10151.1.1
macOS Sonoma 14.0 (23A344) (didn't work with macOS Ventura either)

Issue Screenshot

Screenshot 2023-10-21 at 16 06 27

Code Example

examples/audio/audio_mixed_processor.c
examples/audio/audio_module_playing.c
examples/audio/audio_music_stream.c
examples/audio/audio_raw_stream.c
examples/audio/audio_sound_loading.c
examples/audio/audio_sound_multi.c
examples/audio/audio_stream_effects.c

Logs

/Users/wilson/projects/github/raysan5/raylib/cmake-build-debug/examples/audio_music_stream
INFO: Initializing raylib 5.0-dev
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 1728 x 1117
INFO:     > Screen size:  800 x 450
INFO:     > Render size:  800 x 450
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 43
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Apple
INFO:     > Renderer: Apple M1 Max
INFO:     > Version:  4.1 Metal - 86
INFO:     > GLSL:     4.10
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: PLATFORM: DESKTOP: Application initialized successfully
INFO: AUDIO: Device initialized successfully
INFO:     > Backend:       miniaudio / Null
INFO:     > Format:        32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
INFO:     > Channels:      2 -> 2
INFO:     > Sample rate:   48000 -> 48000
INFO:     > Periods size:  1440
INFO: STREAM: Initialized successfully (44100 Hz, 32 bit, Stereo)
INFO: FILEIO: [resources/country.mp3] Music file loaded successfully
INFO:     > Sample rate:   44100 Hz
INFO:     > Sample size:   32 bits
INFO:     > Channels:      2 (Stereo)
INFO:     > Total frames:  4128768
INFO: TIMER: Target time per frame: 33.333 milliseconds

Troubleshooting

As suggested in Discord, I tried to set AUDIO_DEVICE_SAMPLE_RATE in config.h to different values, including matching the same rate of the loaded file, but nothing worked.

Please note that I'm not a C developer. I am developing ruby bindings for raylib and I noticed that none of my audio examples worked.

@wilsonsilva wilsonsilva changed the title [module] Short description of the issue/bug/feature [audio] Unable to hear any sound Oct 21, 2023
@wilsonsilva
Copy link
Contributor Author

This user has also reported the same problem https://discord.com/channels/426912293134270465/1164761771073089546/1164761771073089546

@wilsonsilva
Copy link
Contributor Author

I can hear the web audio tho, just not the desktop version.

@raysan5
Copy link
Owner

raysan5 commented Oct 21, 2023

@wilsonsilva did you test the C examples?

@gen2brain
Copy link
Contributor

@wilsonsilva
Copy link
Contributor Author

wilsonsilva commented Oct 22, 2023

@raysan5 Yes, I executed all the C examples in the audio folder. All run without errors, but I couldn't hear any sound.

@wilsonsilva
Copy link
Contributor Author

@gen2brain Thanks. I confirm that adding:

# Adding suggested flags
add_definitions(-DMA_NO_RUNTIME_LINKING)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework CoreFoundation -framework CoreAudio -framework AudioToolbox")

To the top of my root CMakeLists.txt fixed the issue.

The logs changed from:

INFO: AUDIO: Device initialized successfully
INFO:     > Backend:       miniaudio / Null

to

INFO: AUDIO: Device initialized successfully
INFO:     > Backend:       miniaudio / Core Audio

@raysan5 I'll leave it up to you to decide if this is an issue that warrants a global fix or I just happen to be an unlucky rare exception 😂

@raysan5
Copy link
Owner

raysan5 commented Oct 22, 2023

@wilsonsilva This is strange because miniaudio should be able to dynamically request required libraries at runtime. As far as I know it works as expected for other macOS users.

Are you linking raylib statically or dynamically?

Maybe @mackron could know more about the cause of this issue...

@wilsonsilva
Copy link
Contributor Author

wilsonsilva commented Oct 22, 2023

@raysan5 I suppose that I'm doing both.

Statically

When I add these lines to CMakeLists.txt:

add_definitions(-DMA_NO_RUNTIME_LINKING)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework CoreAudio -framework AudioToolbox")

And I reload the CLion configuration, I see this log:

/Users/wilson/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Users/wilson/Applications/CLion.app/Contents/bin/ninja/mac/ninja -G Ninja -S /Users/wilson/projects/github/raysan5/raylib -B /Users/wilson/projects/github/raysan5/raylib/cmake-build-debug
-- The C compiler identification is AppleClang 15.0.0.15000040
-- The CXX compiler identification is AppleClang 15.0.0.15000040
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test COMPILER_HAS_THOSE_TOGGLES
-- Performing Test COMPILER_HAS_THOSE_TOGGLES - Success
-- Testing if -Werror=pointer-arith can be used -- compiles
-- Testing if -Werror=implicit-function-declaration can be used -- compiles
-- Testing if -fno-strict-aliasing can be used -- compiles
-- Using raylib's GLFW
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Including Cocoa support
CMake Warning (dev) at cmake/LibraryConfigurations.cmake:22 (MESSAGE):
  OpenGL is deprecated starting with macOS 10.14 (Mojave)!
Call Stack (most recent call first):
  src/CMakeLists.txt:48 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Audio Backend: miniaudio
-- Building raylib static library
-- Generated build type: Debug
-- Compiling with the flags:
--   PLATFORM=PLATFORM_DESKTOP
--   GRAPHICS=GRAPHICS_API_OPENGL_33
-- Building examples is enabled
-- Looking for CLOCK_MONOTONIC
-- Looking for CLOCK_MONOTONIC - found
-- Looking for QueryPerformanceCounter
-- Looking for QueryPerformanceCounter - not found
-- Looking for stdatomic.h
-- Looking for stdatomic.h - found
-- Testing if -std=c11 can be used -- compiles
CMake Warning (dev) at examples/CMakeLists.txt:44 (MESSAGE):
  OpenGL is deprecated starting with macOS 10.14 (Mojave)!
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done (1.0s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/wilson/projects/github/raysan5/raylib/cmake-build-debug

[Finished]

Then, I can run and hear all audio examples with no issues. I do it via CLion GUI.

Dynamically

This is my current goal. I am developing raylib-ruby. I'm converting all audio examples from C to Ruby. I don't get errors, but there's no sound.

The instructions on how to compile the library dynamically are not very clear on the wiki. I tried to modify the homebrew formula, and I also tried a bash script. The examples run, but there's no audio:

INFO: AUDIO: Device initialized successfully
INFO:     > Backend:       miniaudio / Null
# Used a different name to avoid conflicts
class Laylib < Formula
  desc "Simple and easy-to-use library to learn videogames programming"
  homepage "https://www.raylib.com/"
  url "https://github.com/raysan5/raylib/archive/4.5.0.tar.gz"
  sha256 "0df98bfc553db31356cab46a2f9ed6d932065f186a0fff24bafa05f8a60e16d1"
  license "Zlib"
  head "https://github.com/raysan5/raylib.git", branch: "master"

  bottle do
    sha256 cellar: :any,                 arm64_sonoma:   "662558c42eb94dd57d74769c8be1fa56dc511b2c532016725ea2f795ddc981d4"
    sha256 cellar: :any,                 arm64_ventura:  "a3f03b9f6fc41dd1884d4c1694aa44a1ad0a035ddb1dc4dda690898d000cd407"
    sha256 cellar: :any,                 arm64_monterey: "10a1d493f6abdfd66b2d0639d848c5972e65df7a475b1e77210da59e60ff57b3"
    sha256 cellar: :any,                 arm64_big_sur:  "b50c3a4cea028ce463bce5f8cd857d61c9c0ac10fcab6f491cb62c98b08c3d08"
    sha256 cellar: :any,                 sonoma:         "f6d9ec0179498117c61f08faacf4c3b5bb95d99a4804f961005c8541755f4c1e"
    sha256 cellar: :any,                 ventura:        "a5fa31296b157523b968e2ba6a913e11140a06b46600d14fff7dfca08dec16d3"
    sha256 cellar: :any,                 monterey:       "af0630c193767d75d93bead04d6b5ace6fa0db4f789f35a8980ec771b37face1"
    sha256 cellar: :any,                 big_sur:        "f62b1dde82d0f33e6fbda710e75b0a2f4a7559dc6588201419bce5f2f9ca4b92"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "2d9f930f5a0e98eece43c16318eaaf42e94629d7f45e07c0b6765ee36fe70ece"
  end

  depends_on "cmake" => :build

  on_linux do
    depends_on "libx11"
    depends_on "libxcursor"
    depends_on "libxi"
    depends_on "libxinerama"
    depends_on "libxrandr"
    depends_on "mesa"
    depends_on "mesa-glu"
  end

  def install
    args = std_cmake_args + [
      "-S", ".",
      "-DMA_NO_RUNTIME_LINKING=ON",
      "-DCMAKE_EXE_LINKER_FLAGS=#{Shellwords.shellescape("-framework CoreAudio -framework AudioToolbox")}",
      "-DBUILD_SHARED_LIBS=ON",
      "-DMACOS_FATLIB=OFF",
      "-DBUILD_EXAMPLES=OFF",
      "-DBUILD_GAMES=OFF"
    ]

    system "cmake", *args, "-B", "build"
    system "cmake", "--build", "build"
    system "cmake", "--install", "build"

    args_static = args.dup
    args_static[args_static.index("-DBUILD_SHARED_LIBS=ON")] = "-DBUILD_SHARED_LIBS=OFF"

    system "cmake", *args_static, "-B", "build-static"
    system "cmake", "--build", "build-static"
    lib.install "build-static/raylib/libraylib.a"
  end

  # def install
  #   system "cmake", "-S", ".", "-B", "build",
  #          "-DBUILD_SHARED_LIBS=ON",
  #          "-DMACOS_FATLIB=OFF",
  #          "-DBUILD_EXAMPLES=OFF",
  #          "-DBUILD_GAMES=OFF",
  #          "-DMA_NO_RUNTIME_LINKING:BOOL=ON",
  #          "-DCMAKE_EXE_LINKER_FLAGS=-framework CoreFoundation -framework CoreAudio -framework AudioToolbox",
  #          *std_cmake_args
  #   system "cmake", "--build", "build"
  #   system "cmake", "--install", "build"
  #   system "cmake", "-S", ".", "-B", "build-static",
  #          "-DBUILD_SHARED_LIBS=OFF",
  #          "-DMACOS_FATLIB=OFF",
  #          "-DBUILD_EXAMPLES=OFF",
  #          "-DBUILD_GAMES=OFF",
  #          "-DMA_NO_RUNTIME_LINKING:BOOL=ON",
  #          "-DCMAKE_EXE_LINKER_FLAGS=-framework CoreFoundation -framework CoreAudio -framework AudioToolbox",
  #          *std_cmake_args
  #   system "cmake", "--build", "build-static"
  #   lib.install "build-static/raylib/libraylib.a"
  # end

  test do
    (testpath/"test.c").write <<~EOS
      #include <stdlib.h>
      #include <raylib.h>
      int main(void)
      {
          int num = GetRandomValue(42, 1337);
          return 42 <= num && num <= 1337 ? EXIT_SUCCESS : EXIT_FAILURE;
      }
    EOS
    flags = if OS.mac?
      %w[
        -framework Cocoa
        -framework IOKit
        -framework OpenGL
        -framework CoreFoundation
        -framework CoreAudio
        -framework AudioToolbox
      ]
    else
      %w[
        -lm
        -ldl
        -lGL
        -lpthread
      ]
    end
    system ENV.cc, "test.c", "-o", "test", "-L#{lib}", "-lraylib", *flags
    system "./test"
  end
end
mkdir -p build
cd build
export MACOSX_DEPLOYMENT_TARGET=14.0
cmake \
-D CMAKE_C_FLAGS="" \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_EXAMPLES=OFF \
-D CMAKE_C_COMPILER=clang \
-D CMAKE_CXX_FLAGS="-DMA_NO_RUNTIME_LINKING" \
-D CMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS} -framework CoreAudio -framework AudioToolbox" \
../
make
sudo cp raylib/libraylib.dylib /usr/local/lib

@gen2brain
Copy link
Contributor

@raysan5 This is already fixed in the dev branch mackron/miniaudio@b792ccd, it affects the latest macOS versions.

@mackron
Copy link
Contributor

mackron commented Oct 22, 2023

I haven't read through all of the details here, but if you're running on an Apple platform and you're not hearing anything, the most likely reason is because it's failing to link at runtime and is falling back to the null backend. The changed noted by @gen2brain has a workaround that apparently works, but another option is to link at compile time instead of at runtime. More info here in section 2.2: https://miniaud.io/docs/manual/#Building

@raysan5
Copy link
Owner

raysan5 commented Oct 22, 2023

@gen2brain @mackron thanks for your answers! yeah, that seems to be the issue!

@wilsonsilva
Copy link
Contributor Author

After fighting with the build flags, I finally managed to compile the macOS dylib by copying miniaudio.h from the dev branch onto src/external.h and then running:

mkdir -p build
cd build
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_EXAMPLES=OFF \
../
make
sudo cp raylib/libraylib.dylib /usr/local/lib

Thanks everyone for your help.

raysan5 added a commit that referenced this issue Oct 26, 2023
@raysan5
Copy link
Owner

raysan5 commented Oct 26, 2023

Updated to latest miniaudio dev as proposed by @gen2brain. It should work now...

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

No branches or pull requests

4 participants