The Battle for Wesnoth  1.19.5+dev
sdl2_audio.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2022 - 2024
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 
18 #include <SDL2/SDL.h>
19 #include <SDL2/SDL_mixer.h>
20 
21 int main(int, char** argv)
22 {
23  if (SDL_Init(SDL_INIT_AUDIO) < 0) {
24  fprintf(stdout, "Cannot initialize SDL Audio: %s\\n", SDL_GetError());
25  return (EXIT_FAILURE);
26  }
27 
28  if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
29  fprintf(stdout, "Cannot initialize SDL Mixer: %s\\n", Mix_GetError());
30  return (EXIT_FAILURE);
31  }
32 
33  if (Mix_Init(MIX_INIT_OGG) != MIX_INIT_OGG) {
34  fprintf(stdout, "Cannot initialize OGG codec: %s\\n", Mix_GetError());
35  Mix_CloseAudio();
36  return (EXIT_FAILURE);
37  }
38 
39  Mix_Music* music = Mix_LoadMUS(argv[1]);
40  if (music == NULL) {
41  fprintf(stdout, "Cannot load music file: %s\\n", Mix_GetError());
42  Mix_CloseAudio();
43  return (EXIT_FAILURE);
44  }
45 
46  fprintf(stdout, "Success\\n");
47  Mix_FreeMusic(music);
48  Mix_CloseAudio();
49  return (EXIT_SUCCESS);
50 }
int main(int, char **argv)
Definition: sdl2_audio.cpp:21