SDL 2 on windows works incorrectly with audio device

Viewed 936

It seems that I've found a bug between the libraries of SDL compiled for mingw and visual studio.

I'm trying to open the audio device with the following code:

#include <SDL.h>
#include <stdio.h>
int main(int argc, char **argv)
{
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
        exit(1);
    }

    SDL_AudioSpec wanted_spec, spec;

    wanted_spec.channels = 2;
    wanted_spec.freq = 44100;
    wanted_spec.format = AUDIO_S16SYS;
    wanted_spec.silence = 0;
    wanted_spec.samples = 2048;
    wanted_spec.callback = 0;
    //wanted_spec.userdata = opaque;
    while (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
        printf("error cant open audio");
    }
    if (spec.format != AUDIO_S16SYS) {
        printf("error wrong format");
        return -1;
    }

    return 0;
}

When compiling this via MSVS I get "error wrong format"

The same code compiled via mingw32 with the command:

g++ main.c -I/mingw32/include/SDL2 -L/mingw32/lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2

works correctly. Can someone point me to the reason for this? This is done on the same machine. Could this be caused by different versions of SDL libraries?

1 Answers
Related