SDL_mixer 音频问题

SDL_mixer 音频问题

当我尝试初始化 SDL_mixer 声音时

if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
{
    printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
    success = false;
}

出现以下错误:

SDL_mixer Error: 
    No such audio device

编译器是GCC,操作系统是Ubuntu 20.04

该错误该如何解决?

答案1

首先安装libasound2-devlibpulse-dev

sudo apt-get install libasound2-dev libpulse-dev

然后再次构建 SDL。因此配置脚本找到新的标头,以便它包含 PulseAudio 和 ALSA 支持。

https://discourse.libsdl.org/t/couldnt-open-audio-device-no-available-audio-device/18499

答案2

首先需要安装相应的依赖项,如文档所示: https://github.com/libsdl-org/SDL/blob/main/docs/README-linux.md

Ubuntu 18.04,所有可用功能均已启用:

sudo apt-get install build-essential git make \
pkg-config cmake ninja-build gnome-desktop-testing libasound2-dev libpulse-dev \
libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev \
libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev \
libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev \
libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev

然后构建源代码,构建方法请参考以下链接: https://wiki.libsdl.org/SDL2/Installation

git clone [email protected]:libsdl-org/SDL.git -b SDL2 --recurse-submodules
cd SDL
mkdir build
cd build
../configure
make
sudo make install

相关内容