Debian Codegraph @

sound.cpp

raw symbols SCIP
1 /* ************************************************************************* *
2 SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
3 Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * ************************************************************************* */
18
19 #include <vector>
20
21 struct sampleQueuedItemcxx . . $ sampleQueuedItem# {
22 int scxx . . $ sampleQueuedItem#s.,pcxx . . $ sampleQueuedItem#p.,numcxx . . $ sampleQueuedItem#num.;
23 };
24
25 class soundClasscxx . . $ soundClass# {
26 private:
27 #ifndef NOSOUND
28 //The actual sound samples
29 Mix_Chunk *samplecxx . . $ soundClass#sample.[SNDSAMPLEScxx . . $ `main.cpp:138:9`!];
30 //List of queued samples
31 vectorcxx . . $ std/vector#<struct sampleQueuedItemcxx . . $ sampleQueuedItem#> qcxx . . $ soundClass#q.;
32 void loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).(const char *SampleName, int sampleNum);
33
34 int mcxx . . $ soundClass#m.; //Secret undocumented variable
35
36 #endif
37
38 public:
39 bool initcxx . . $ soundClass#init(c9857a73d68e59ba).();
40 void playcxx . . $ soundClass#play(49f6e7a06ebc5aa8).();
41 void addcxx . . $ soundClass#add(43c79ee2f1b9aefe).(int i, GLfloat x);
42 void loadsoundscxx . . $ soundClass#loadsounds(49f6e7a06ebc5aa8).();
43 ~cxx . . $ soundClass#`~soundClass`(ced63f7c635d850d).soundClasscxx . . $ soundClass#();
44 };
45
46 bool soundClasscxx . . $ soundClass#::initcxx . . $ soundClass#init(c9857a73d68e59ba).() {
47 #ifndef NOSOUND
48 mcxx . . $ soundClass#m.=0;
49 int audio_rate = 44100;
50 Uint16cxx . . $ Uint16# audio_format = AUDIO_S16cxx . . $ `<external>/17835154366534373553/SDL_audio.h:57:9`!; /* 16-bit stereo */
51 int audio_channels = 2;
52 int audio_buffers = 1024;
53 if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
54 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error: Could not open audio device."<<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a).endlcxx . . $ std/endl(345bf97a19cc83a9).<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."Sound have been disabled."<<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a).endlcxx . . $ std/endl(345bf97a19cc83a9).;
55 settingcxx . . $ setting..soundcxx . . $ settings#sound.=0;
56 return(0);
57 }
58 Mix_AllocateChannels(MIX_CHANNELScxx . . $ `main.cpp:61:11`!);
59
60 if(settingcxx . . $ setting..soundcxx . . $ settings#sound.)
61 loadsoundscxx . . $ soundClass#loadsounds(49f6e7a06ebc5aa8).();
62 #endif
63 return(1);
64 }
65
66 #ifndef NOSOUND
67 void soundClasscxx . . $ soundClass#::loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).(const char *SampleName, int sampleNum)
68 {
69 stringcxx . . $ std/string# F="snd/"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
70 F +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). SampleName;
71
72 samplecxx . . $ soundClass#sample.[sampleNum] = Mix_LoadWAVcxx . . $ `<external>/13318562018335047551/SDL_mixer.h:150:9`!(useTheme(F,setting.sndTheme).data());
73 if(!samplecxx . . $ soundClass#sample.[sampleNum])
74 {
75 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "SoundManager '"<<cxx . . $ std/`operator<<`(88df5bef833f7f83). F <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."' : " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). Mix_GetErrorcxx . . $ `<external>/13318562018335047551/SDL_mixer.h:626:9`!() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
76 }
77 }
78 #endif
79
80
81 /* This function puts a sample in queue for playing */
82 void soundClasscxx . . $ soundClass#::addcxx . . $ soundClass#add(43c79ee2f1b9aefe).(int i, GLfloat x)
83 {
84 #ifndef NOSOUND
85 if(settingcxx . . $ setting..soundcxx . . $ settings#sound.==0)
86 return;
87
88 int p = 0;
89 if(settingcxx . . $ setting..stereocxx . . $ settings#stereo.)
90 {
91 p=(255.0/3.2)*(x+1.6);
92 }
93
94 struct sampleQueuedItemcxx . . $ sampleQueuedItem# qt;
95 qt.scxx . . $ sampleQueuedItem#s.=i;
96 qt.pcxx . . $ sampleQueuedItem#p.=p;
97 qcxx . . $ soundClass#q..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).( qt );
98
99 #endif
100 }
101
102 void soundClasscxx . . $ soundClass#::loadsoundscxx . . $ soundClass#loadsounds(49f6e7a06ebc5aa8).()
103 {
104
105 #ifndef NOSOUND
106 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("start.ogg", SND_STARTcxx . . $ `main.cpp:112:9`!);
107 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("ball-hit-border.ogg", SND_BALL_HIT_BORDERcxx . . $ `main.cpp:113:9`!);
108 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("ball-hit-paddle.ogg", SND_BALL_HIT_PADDLEcxx . . $ `main.cpp:114:9`!);
109 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("norm-brick-breaka.ogg", SND_NORM_BRICK_BREAKcxx . . $ `main.cpp:115:9`!); //breaka
110
111 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("norm-brick-breakb.ogg", SND_NORM_BRICK_BREAKBcxx . . $ `main.cpp:133:9`!);
112 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("norm-brick-breakc.ogg", SND_NORM_BRICK_BREAKCcxx . . $ `main.cpp:134:9`!);
113 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("norm-brick-breakd.ogg", SND_NORM_BRICK_BREAKDcxx . . $ `main.cpp:135:9`!);
114 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("norm-brick-breake.ogg", SND_NORM_BRICK_BREAKEcxx . . $ `main.cpp:136:9`!);
115
116
117 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("expl-brick-break.ogg", SND_EXPL_BRICK_BREAKcxx . . $ `main.cpp:116:9`!);
118 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("glass-brick-hit.ogg", SND_GLASS_BRICK_HITcxx . . $ `main.cpp:117:9`!);
119 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("glass-brick-break.ogg", SND_GLASS_BRICK_BREAKcxx . . $ `main.cpp:118:9`!);
120 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("invisible-brick-appear.ogg", SND_INVISIBLE_BRICK_APPEARcxx . . $ `main.cpp:130:9`!);
121 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("cement-brick-hit.ogg", SND_CEMENT_BRICK_HITcxx . . $ `main.cpp:119:9`!);
122 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("doom-brick-break.ogg", SND_DOOM_BRICK_BREAKcxx . . $ `main.cpp:128:9`!);
123 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("po-hit-border.ogg", SND_PO_HIT_BORDERcxx . . $ `main.cpp:120:9`!);
124 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("good-po-hit-paddle.ogg", SND_GOOD_PO_HIT_PADDLEcxx . . $ `main.cpp:121:9`!);
125 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("evil-po-hit-paddle.ogg", SND_EVIL_PO_HIT_PADDLEcxx . . $ `main.cpp:122:9`!);
126 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("shot.ogg", SND_SHOTcxx . . $ `main.cpp:123:9`!);
127 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("die.ogg", SND_DIEcxx . . $ `main.cpp:124:9`!);
128 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("nextlevel.ogg", SND_NEXTLEVELcxx . . $ `main.cpp:125:9`!);
129 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("gameover.ogg", SND_GAMEOVERcxx . . $ `main.cpp:126:9`!);
130 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("highscore.ogg", SND_HIGHSCOREcxx . . $ `main.cpp:131:9`!);
131 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("menuclick.ogg", SND_MENUCLICKcxx . . $ `main.cpp:127:9`!);
132 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("glue-ball-hit-paddle.ogg", SND_GLUE_BALL_HIT_PADDLEcxx . . $ `main.cpp:129:9`!);
133 loadSamplecxx . . $ soundClass#loadSample(34d26762b42c433a).("buy-powerup.ogg", SND_BUY_POWERUPcxx . . $ `main.cpp:132:9`!);
134 #endif
135 }
136
137 /* This function is called only when drawing a frame, and plays the queue of samples,
138 It will average the x/stereo position of a sample if it is queued more than once */
139 void soundClasscxx . . $ soundClass#::playcxx . . $ soundClass#play(49f6e7a06ebc5aa8).()
140 {
141 #ifndef NOSOUND
142 if(settingcxx . . $ setting..soundcxx . . $ settings#sound.==0)
143 return;
144
145 //Playlist (lol, imagination for the win..)
146 vectorcxx . . $ std/vector#<struct sampleQueuedItemcxx . . $ sampleQueuedItem#> plcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
147 vectorcxx . . $ std/vector#<struct sampleQueuedItem>::iteratorcxx . . $ std/vector#iterator# plItcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ced63f7c635d850d).;
148 bool same=0;
149 int freeChannel = -1; //The channel we will use for this sample
150
151 //Loop through queue and find samples thare are the same, average their position and put in a new vector
152 for(vectorcxx . . $ std/vector#<struct sampleQueuedItem>::iteratorcxx . . $ std/vector#iterator# it = qcxx . . $ soundClass#q..begincxx . . $ std/vector#begin(55a6de06420d4903).(); it !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). qcxx . . $ soundClass#q..endcxx . . $ std/vector#end(55a6de06420d4903).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).it)
153 {
154 //Loop thrugh the playlist to see find out if this allready exist
155 same=0;
156 for(plIt=cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(dd73d2dfb925c58d).pl.begincxx . . $ std/vector#begin(55a6de06420d4903).(); plIt !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). pl.endcxx . . $ std/vector#end(55a6de06420d4903).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).plIt)
157 {
158 if(plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).scxx . . $ sampleQueuedItem#s. == it->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).scxx . . $ sampleQueuedItem#s.)
159 {
160 same=1;
161 plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).numcxx . . $ sampleQueuedItem#num.++;
162 plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).pcxx . . $ sampleQueuedItem#p. += it->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).pcxx . . $ sampleQueuedItem#p.;
163 }
164 }
165
166 //this sample is not yet in the playlist
167 if(!same)
168 {
169 pl.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).it );
170 plIt =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(dd73d2dfb925c58d). pl.endcxx . . $ std/vector#end(55a6de06420d4903).();
171 --cxx . . $ __gnu_cxx/__normal_iterator#operator--(1613faa01bc3d014).plIt;
172 plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).numcxx . . $ sampleQueuedItem#num.=1;
173 }
174 }
175 qcxx . . $ soundClass#q..clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
176
177 //Play the actual samples :)
178 for(plIt =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(dd73d2dfb925c58d). pl.begincxx . . $ std/vector#begin(55a6de06420d4903).(); plIt !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). pl.endcxx . . $ std/vector#end(55a6de06420d4903).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).plIt)
179 {
180 //Find a free channel:
181 for(int i=0; i < MIX_CHANNELScxx . . $ `main.cpp:61:11`!; i++)
182 {
183 if(!Mix_Playing(i))
184 {
185 freeChannel=i;
186 break;
187 }
188 }
189 if(settingcxx . . $ setting..stereocxx . . $ settings#stereo.)
190 {
191 plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).pcxx . . $ sampleQueuedItem#p. /=plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).numcxx . . $ sampleQueuedItem#num.;
192 Mix_SetPanning(freeChannel, 255-plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).pcxx . . $ sampleQueuedItem#p., plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).pcxx . . $ sampleQueuedItem#p.);
193 }
194
195 if(plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).scxx . . $ sampleQueuedItem#s. == SND_NORM_BRICK_BREAKcxx . . $ `main.cpp:115:9`!)
196 {
197 switch(mcxx . . $ soundClass#m.)
198 {
199 //Case 0 = SND_NORM_BREAK(a)
200 case 1:
201 plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).scxx . . $ sampleQueuedItem#s. = SND_NORM_BRICK_BREAKBcxx . . $ `main.cpp:133:9`!;
202 break;
203 case 2:
204 plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).scxx . . $ sampleQueuedItem#s. = SND_NORM_BRICK_BREAKCcxx . . $ `main.cpp:134:9`!;
205 break;
206 case 3:
207 plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).scxx . . $ sampleQueuedItem#s. = SND_NORM_BRICK_BREAKDcxx . . $ `main.cpp:135:9`!;
208 break;
209 case 4:
210 plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).scxx . . $ sampleQueuedItem#s. = SND_NORM_BRICK_BREAKEcxx . . $ `main.cpp:136:9`!;
211 break;
212 }
213
214 mcxx . . $ soundClass#m.++;
215 if(mcxx . . $ soundClass#m.==5)
216 mcxx . . $ soundClass#m.=0;
217
218 }
219
220 if(Mix_PlayChannelcxx . . $ `<external>/13318562018335047551/SDL_mixer.h:536:9`!(freeChannel, sample[plIt->s], 0) == -1)
221 {
222 printf("Sample %i: %s\n",plIt->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).scxx . . $ sampleQueuedItem#s., Mix_GetErrorcxx . . $ `<external>/13318562018335047551/SDL_mixer.h:626:9`!());
223 }
224 }
225 #endif
226 }
227
228 soundClasscxx . . $ soundClass#::~cxx . . $ soundClass#`~soundClass`(ced63f7c635d850d).soundClasscxx . . $ soundClass#()
229 {
230 #ifndef NOSOUND
231 for(int i=0; i < SNDSAMPLEScxx . . $ `main.cpp:138:9`!; i++)
232 {
233 Mix_FreeChunk(samplecxx . . $ soundClass#sample.[i]);
234 }
235 Mix_CloseAudio();
236 #endif
237 }