RandyGaul / cute_headers

Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
4.3k stars 270 forks source link

[cute_sound.h] Fails with certain OGG files with latest stb_vorbis #242

Closed ghost closed 3 years ago

ghost commented 3 years ago

With the newest stb_vorbis, cute_sound either fails to load or fails to mix certain files. The number of samples and/or channels is 0. Minimal test case:

#include <SDL2/SDL.h>

#define STB_VORBIS_IMPLEMENTATION
#include "stb_vorbis.c"

#define CUTE_SOUND_IMPLEMENTATION
#define CUTE_SOUND_FORCE_SDL
#include "cute_sound.h"

cs_context_t *context;

int main(void)
{
    context = cs_make_context(NULL, 44100, 4096, 0, NULL);
    cs_spawn_mix_thread(context);
    cs_loaded_sound_t loaded = cs_load_ogg("cave-loop-mono.ogg");
    cs_playing_sound_t hum = cs_make_playing_sound(&loaded);
    cs_insert_sound(context, &hum);
    cs_sleep(5000);

    return 0;
}

cave-loop-mono.ogg.zip

ghost commented 3 years ago

After some testing, I have determined that the cause of the problem is the latest revision of stb_vorbis throwing an error if an OGG is missing a comment field. Such files can be exported from Audacity, though usually they contain comments so this isn't caught.

Why throw an error if a file doesn't have metadata but is still playable? I'll report this issue in stb as it's not your bug.

EDIT: A PR is already open for it at stb. I reviewed it. It works. Fix inbound I'm sure.

dcousens commented 3 years ago

@fluffrabbit for those of us spectating, could you post a link? 🙇🏿‍♂️

ghost commented 3 years ago

This thing fixes the vorbis bug: https://github.com/nothings/stb/pull/1113

RandyGaul commented 3 years ago

Going to close this out for now, thanks so much @fluffrabbit for writing down the problem and documenting the solution. This will likely help other people running into the same problem.