I'm using SDL2 on macOS but it seems like the SDL_MixAudioFormat isn't working properly. It doesn't crash or provide any errors, but the output is silent.
Here is the function:
static void audio_sdl_play(const uint8_t *buf, size_t len) {
uint8_t *mix_buf[len];
SDL_memset(mix_buf, 0, len);
SDL_MixAudioFormat(mix_buf, buf, AUDIO_S16, len, SDL_MIXER_MAXVOLUME);
SDL_QueueAudio(dev, mix_buf, len);
}
However, if I do not use the mixer it works perfectly fine:
static void audio_sdl_play(const uint8_t *buf, size_t len) {
SDL_QueueAudio(dev, buf, len);
}
Am I doing something wrong?
I'm seeing compiler warnings but I'm not sure how to fix them and I'm also using similar code to every example I've seen online.
Here are the warnings:
src/pc/audio/audio_sdl2.c: In function 'audio_sdl_play':
src/pc/audio/audio_sdl2.c:53:28: warning: passing argument 1 of 'SDL_MixAudioFormat' from incompatible pointer type [-Wincompatible-pointer-types]
53 | SDL_MixAudioFormat(mix_buf, buf, AUDIO_S16, len, 128);
| ^~~~~~~
| |
| uint8_t ** {aka unsigned char **}
In file included from /opt/homebrew/include/SDL2/SDL.h:36,
from src/pc/audio/audio_sdl2.c:4:
/opt/homebrew/include/SDL2/SDL_audio.h:1178:57: note: expected 'Uint8 *' {aka 'unsigned char *'} but argument is of type 'uint8_t **' {aka 'unsigned char **'}
1178 | extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst,
| ~~~~~~~~^~~