libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
423 stars 144 forks source link

Specific sound won't play as OGG/Vorbis with device set to 48000hz #589

Open rapha-s opened 9 months ago

rapha-s commented 9 months ago

I have this file adv_zenhan.zip Its an ogg/vorbis with sample rate of 96000hz.

The current facts (on Windows):

I have a minimum reproducible example: For wav simply reencoding with ffmpeg without any parameter suffice. For the other ogg, anything that is known to work is enough.

#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#include <stdbool.h>

int main(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
    Mix_Init(MIX_INIT_OGG);

    SDL_Window* window = SDL_CreateWindow("Audio Test",
        SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED,
        256,
        256,
        SDL_WINDOW_RESIZABLE);

    Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 4096);

    Mix_Music* ogg = Mix_LoadMUS("adv_zenhan.ogg");
    Mix_Music* wav = Mix_LoadMUS("adv_zenhan.wav");
    Mix_Music* works = Mix_LoadMUS("works for sure.ogg");
    Mix_PlayMusic(ogg,65535);

    SDL_Event Event;

    bool done = false;
    while (!done)
    {
        bool gotEvent = SDL_PollEvent(&Event);

        while (!done && gotEvent)
        {
            switch (Event.type)
            {
            case SDL_KEYDOWN:
                switch (Event.key.keysym.sym)
                {
                case 'o':
                    Mix_PlayMusic(ogg, 65535);
                    break;
                case 'w':
                    Mix_PlayMusic(wav, 65535);
                    break;
                case 'r':
                    Mix_PlayMusic(works, 65535);
                    break;
                default:
                    break;
                }
                break;

            case SDL_QUIT:
                done = true;
                break;

            default:
                break;
            }
            if (!done) gotEvent = SDL_PollEvent(&Event);
        }
        SDL_Delay(10);
    }
    Mix_FreeMusic(ogg);
    Mix_FreeMusic(wav);
    Mix_FreeMusic(works);

    Mix_CloseAudio();
    SDL_Quit();
    return 0;
}

I've no idea what's going on, it doesn't make sense and I couldn't figure out the cause, so I'm reporting.

rapha-s commented 9 months ago

Confirmed the same behaviour happens on openSUSE Tumbleweed.

sezero commented 9 months ago

With stb_vorbis backend, it plays.

With libvorbis backend: reproduced the issue: the playmus program with an -r option anything smaller than 96000 just quits:

$ ./playmus -r 48000 ~/3/1/adv_zenhan.ogg
INFO: Opened audio at 48000 Hz 16 bit stereo 4096 bytes audio buffer
INFO: Detected music type: OGG Vorbis
INFO: Playing /home/ozzie/3/1/adv_zenhan.ogg, duration 73.846156

However -r 96000 or -r 192000 works.

Something in music_vorbis.c? @slouken?