1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | |
---|
15 | Some code was taken from Simon's first implementation of the SoundEngine. |
---|
16 | */ |
---|
17 | |
---|
18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND |
---|
19 | |
---|
20 | #include "sound_engine.h" |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | /** |
---|
25 | \brief standard constructor |
---|
26 | */ |
---|
27 | SoundEngine::SoundEngine () |
---|
28 | { |
---|
29 | this->setClassName ("SoundEngine"); |
---|
30 | this->isInit = false; |
---|
31 | this->enableSound(); |
---|
32 | } |
---|
33 | |
---|
34 | //! brief the singleton reference to this class |
---|
35 | SoundEngine* SoundEngine::singletonRef = NULL; |
---|
36 | |
---|
37 | /** |
---|
38 | \returns a Pointer to this Class |
---|
39 | */ |
---|
40 | SoundEngine* SoundEngine::getInstance(void) |
---|
41 | { |
---|
42 | if (!SoundEngine::singletonRef) |
---|
43 | SoundEngine::singletonRef = new SoundEngine(); |
---|
44 | return SoundEngine::singletonRef; |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | \brief standard deconstructor |
---|
49 | |
---|
50 | */ |
---|
51 | SoundEngine::~SoundEngine () |
---|
52 | { |
---|
53 | SoundEngine::singletonRef = NULL; |
---|
54 | |
---|
55 | this->disableSound(); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | /** |
---|
60 | \brief enables the SDL_mixer library |
---|
61 | */ |
---|
62 | void SoundEngine::enableSound(void) |
---|
63 | { |
---|
64 | if (!this->isInit) |
---|
65 | if (SDL_Init(SDL_INIT_AUDIO)) |
---|
66 | { |
---|
67 | PRINTF(1)("SDL-sound could not be initialized\n"); |
---|
68 | return; |
---|
69 | } |
---|
70 | this->isInit = true; |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | \brief disabled SDL_mixer |
---|
75 | */ |
---|
76 | void SoundEngine::disableSound(void) |
---|
77 | { |
---|
78 | if (this->isInit) |
---|
79 | { |
---|
80 | SDL_QuitSubSystem(SDL_INIT_AUDIO); |
---|
81 | } |
---|
82 | else |
---|
83 | PRINTF(4)("SDL_mixer was not initialized.\n"); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | \brief checks if the compiled version and the local version of SDL_mixer match. |
---|
88 | \returns true if match, false otherwise |
---|
89 | */ |
---|
90 | bool SoundEngine::checkVersion(void) |
---|
91 | { |
---|
92 | SDL_version compile_version; |
---|
93 | SDL_version link_version; |
---|
94 | MIX_VERSION(&compile_version); |
---|
95 | link_version = *Mix_Linked_Version(); |
---|
96 | |
---|
97 | if (compile_version.major == link_version.major && |
---|
98 | compile_version.minor == link_version.minor && |
---|
99 | compile_version.patch == link_version.patch) |
---|
100 | { |
---|
101 | return true; |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | PRINTF(2)("compiled with SDL_mixer version: %d.%d.%d\n", |
---|
106 | compile_version.major, |
---|
107 | compile_version.minor, |
---|
108 | compile_version.patch); |
---|
109 | |
---|
110 | PRINTF(2)("running with SDL_mixer version: %d.%d.%d\n", |
---|
111 | link_version.major, |
---|
112 | link_version.minor, |
---|
113 | link_version.patch); |
---|
114 | return false; |
---|
115 | } |
---|
116 | } |
---|