1
似乎我發現了爲mingw和visual studio編譯的SDL庫之間的錯誤。Windows上的SDL 2與音頻設備的配合不正確
我試圖打開與下面的代碼的音頻設備:
#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;
}
當通過MSVS編譯這個我得到「錯誤格式錯誤」
相同的代碼通過的mingw32編譯命令:
g++ main.c -I/mingw32/include/SDL2 -L/mingw32/lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2
工作正常。有人能指出我的原因嗎?這是在同一臺機器上完成的。這可能是由不同版本的SDL庫引起的嗎?
嘗試添加環境變量「SDL_AUDIODRIVER」 =「的DirectSound」,並告訴我,如果它的工作原理 –