The Battle for Wesnoth  1.17.10+dev
sdl2_audio.cpp
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 
4 #include <SDL2/SDL.h>
5 #include <SDL2/SDL_mixer.h>
6 
7 int main(int, char** argv)
8 {
9  if (SDL_Init(SDL_INIT_AUDIO) < 0) {
10  fprintf(stdout, "Cannot initialize SDL Audio: %s\\n", SDL_GetError());
11  return (EXIT_FAILURE);
12  }
13 
14  if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
15  fprintf(stdout, "Cannot initialize SDL Mixer: %s\\n", Mix_GetError());
16  return (EXIT_FAILURE);
17  }
18 
19  if (Mix_Init(MIX_INIT_OGG) != MIX_INIT_OGG) {
20  fprintf(stdout, "Cannot initialize OGG codec: %s\\n", Mix_GetError());
21  Mix_CloseAudio();
22  return (EXIT_FAILURE);
23  }
24 
25  Mix_Music* music = Mix_LoadMUS(argv[1]);
26  if (music == NULL) {
27  fprintf(stdout, "Cannot load music file: %s\\n", Mix_GetError());
28  Mix_CloseAudio();
29  return (EXIT_FAILURE);
30  }
31 
32  fprintf(stdout, "Success\\n");
33  Mix_FreeMusic(music);
34  Mix_CloseAudio();
35  return (EXIT_SUCCESS);
36 }
int main(int, char **argv)
Definition: sdl2_audio.cpp:7