This first problem has been solved. A follow-up problem is in my reply below this one.
I started tinkering with SDL’s audio capabilities and ran into an issue with opening audio. Here’s a few code snippets of how I am initializing the libraries:
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
success = false;
}
...
int mixFlags = MIX_INIT_MP3;
if(!(Mix_Init(mixFlags) & mixFlags)) {
printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
success = false;
}
The initialization runs with no errors and executing the following code shows I am using the alsa driver:
printf("Current audio driver: %s\n", SDL_GetCurrentAudioDriver());
Current audio driver: alsa
Running code to open audio is where issues start. If I call the Mix_OpenAudio function, I get an alsa error.
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048) < 0) {
printf("Mix_OpenAudio: %s\n", Mix_GetError());
success = false;
}
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
Mix_OpenAudio: ALSA: Couldn't open audio device: No such file or directory
Now, the real confusion comes from when I replace the Mix_OpenAudio call with
Mix_OpenAudioDevice (sidenote, is this function even in the docs?).
if(Mix_OpenAudioDevice(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048, SDL_GetAudioDeviceName(7, 0), SDL_AUDIO_ALLOW_ANY_CHANGE) < 0) {
printf("Mix_OpenAudioDevice: %s\n", Mix_GetError());
success = false;
}
This code actually runs fine given the specific index of the device I want to use. Unfortunately, this isn’t exactly the greatest option since a default device isn’t being automatically used.
I should note that all the libraries I’m using are coming from the current ubuntu packages, libraries are being applied in the make file of my project, and g++ is current as well.
Ubuntu 20.04
libsdl2-2.0-0 – Version: 2.0.10+dfsg1-3
libsdl2-mixer-2.0-0 – Version: 2.0.4+dfsg1-2build1
libasound2 – Version: 1.2.2-2.1
alsa driver version: k5.4.0-33-generic
The dev libraries are the same version.
Anyone know what’s going on here? I feel like it’s a silly mistake on my part but I don’t know. Any help is appreciated!