]>
git.zerfleddert.de Git - micropolis/blob - src/sim/w_sound.c
260218341d12ccc1a58ca8c5ba1ea1f0a62e0515
2 * Portions Copyright (c) 2008 Deanna Phillips <deanna@sdf.lonestar.org>
7 * Micropolis, Unix Version. This game was released for the Unix platform
8 * in or about 1990 and has been modified for inclusion in the One Laptop
9 * Per Child program. Copyright (C) 1989 - 2007 Electronic Arts Inc. If
10 * you need assistance with this program, you may contact:
11 * http://wiki.laptop.org/go/Micropolis or email micropolis@laptop.org.
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or (at
16 * your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details. You should have received a
22 * copy of the GNU General Public License along with this program. If
23 * not, see <http://www.gnu.org/licenses/>.
25 * ADDITIONAL TERMS per GNU GPL Section 7
27 * No trademark or publicity rights are granted. This license does NOT
28 * give you any right, title or interest in the trademark SimCity or any
29 * other Electronic Arts trademark. You may not distribute any
30 * modification of this program using the trademark SimCity or claim any
31 * affliation or association with Electronic Arts Inc. or its employees.
33 * Any propagation or conveyance of this program must include this
34 * copyright notice and these terms.
36 * If you convey this program (or any modifications of it) and assume
37 * contractual liability for the program to recipients of it, you agree
38 * to indemnify Electronic Arts for any liability that those contractual
39 * assumptions impose on Electronic Arts.
41 * You may not misrepresent the origins of this program; modified
42 * versions of the program must be marked as such and not identified as
43 * the original program.
45 * This disclaimer supplements the one included in the General Public
46 * License. TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, THIS
47 * PROGRAM IS PROVIDED TO YOU "AS IS," WITH ALL FAULTS, WITHOUT WARRANTY
48 * OF ANY KIND, AND YOUR USE IS AT YOUR SOLE RISK. THE ENTIRE RISK OF
49 * SATISFACTORY QUALITY AND PERFORMANCE RESIDES WITH YOU. ELECTRONIC ARTS
50 * DISCLAIMS ANY AND ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES,
51 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY,
52 * FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT OF THIRD PARTY
53 * RIGHTS, AND WARRANTIES (IF ANY) ARISING FROM A COURSE OF DEALING,
54 * USAGE, OR TRADE PRACTICE. ELECTRONIC ARTS DOES NOT WARRANT AGAINST
55 * INTERFERENCE WITH YOUR ENJOYMENT OF THE PROGRAM; THAT THE PROGRAM WILL
56 * MEET YOUR REQUIREMENTS; THAT OPERATION OF THE PROGRAM WILL BE
57 * UNINTERRUPTED OR ERROR-FREE, OR THAT THE PROGRAM WILL BE COMPATIBLE
58 * WITH THIRD PARTY SOFTWARE OR THAT ANY ERRORS IN THE PROGRAM WILL BE
59 * CORRECTED. NO ORAL OR WRITTEN ADVICE PROVIDED BY ELECTRONIC ARTS OR
60 * ANY AUTHORIZED REPRESENTATIVE SHALL CREATE A WARRANTY. SOME
61 * JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF OR LIMITATIONS ON IMPLIED
62 * WARRANTIES OR THE LIMITATIONS ON THE APPLICABLE STATUTORY RIGHTS OF A
63 * CONSUMER, SO SOME OR ALL OF THE ABOVE EXCLUSIONS AND LIMITATIONS MAY
67 #include <SDL/SDL_mixer.h>
71 #define SIM_NSOUNDS 47
72 #define SIM_NCHANNELS 32
73 #define DOZER_CHANNEL 0
74 #define DOZER_SOUND "rumble.wav"
82 struct sound sounds
[SIM_NSOUNDS
] = {
83 { "A", "a.wav", NULL
},
84 { "Aaah", "aaah.wav", NULL
},
85 { "Airport", "airport.wav", NULL
},
86 { "Beep", "beep.wav", NULL
},
87 { "Boing", "boing.wav", NULL
},
88 { "Bop", "bop.wav", NULL
},
89 { "Build", "build.wav", NULL
},
90 { "Bulldozer", "bulldozer.wav", NULL
},
91 { "Chalk", "chalk.wav", NULL
},
92 { "Coal", "coal.wav", NULL
},
93 { "Com", "com.wav", NULL
},
94 { "Computer", "computer.wav", NULL
},
95 { "Cuckoo", "cuckoo.wav", NULL
},
96 { "E", "e.wav", NULL
},
97 { "Eraser", "eraser.wav", NULL
},
98 { "Explosion-High", "explosion-high.wav", NULL
},
99 { "Explosion-Low", "explosion-low.wav", NULL
},
100 { "Fire", "fire.wav", NULL
},
101 { "HeavyTraffic", "heavytraffic.wav", NULL
},
102 { "HonkHonk-High", "honkhonk-high.wav", NULL
},
103 { "HonkHonk-Low", "honkhonk-low.wav", NULL
},
104 { "HonkHonk-Med", "honkhonk-med.wav", NULL
},
105 { "Ignition", "ignition.wav", NULL
},
106 { "Ind", "ind.wav", NULL
},
107 { "Monster", "monster.wav", NULL
},
108 { "Nuclear", "nuclear.wav", NULL
},
109 { "O", "o.wav", NULL
},
110 { "Oop", "oop.wav", NULL
},
111 { "Park", "park.wav", NULL
},
112 { "Player", "player.wav", NULL
},
113 { "Police", "police.wav", NULL
},
114 { "QuackQuack", "quackquack.wav", NULL
},
115 { "Query", "query.wav", NULL
},
116 { "Rail", "rail.wav", NULL
},
117 { "Res", "res.wav", NULL
},
118 { "Road", "road.wav", NULL
},
119 { "Rumble", "rumble.wav", NULL
},
120 { "Seaport", "seaport.wav", NULL
},
121 { "Siren", "siren.wav", NULL
},
122 { "Skid", "skid.wav", NULL
},
123 { "Sorry", "sorry.wav", NULL
},
124 { "Stadium", "stadium.wav", NULL
},
125 { "UhUh", "uhuh.wav", NULL
},
126 { "Whip", "whip.wav", NULL
},
127 { "Wire", "wire.wav", NULL
},
128 { "Woosh", "woosh.wav", NULL
},
129 { "Zone", "zone.wav", NULL
}
135 int SoundInitialized
= 0;
144 if (SDL_Init(SDL_INIT_AUDIO
) == -1) {
145 fprintf(stderr
, "SDL_Init: %s\n", SDL_GetError());
149 if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT
, 1, 1024) == -1) {
150 fprintf(stderr
, "Mix_OpenAudio: %s\n", Mix_GetError());
154 reserved_chans
= Mix_ReserveChannels(1);
156 if (reserved_chans
!= 1) {
157 fprintf(stderr
, "Mix_ReserveChannels: %s\n", Mix_GetError());
161 if (Mix_AllocateChannels(SIM_NCHANNELS
) == -1) {
162 fprintf(stderr
, "Mix_AllocateChannels: %s\n", Mix_GetError());
166 snprintf(buf
, sizeof(buf
), "%s/sounds/%s", ResourceDir
, DOZER_SOUND
);
167 rumble
= Mix_LoadWAV(buf
);
169 if (rumble
== NULL
) {
170 printf("Mix_LoadWAV: %s\n", Mix_GetError());
174 SoundInitialized
= 1;
181 SoundInitialized
= 0;
183 for (i
= 0; i
< SIM_NSOUNDS
; i
++) {
184 if (sounds
[i
].wave
) {
185 Mix_FreeChunk(sounds
[i
].wave
);
186 sounds
[i
].wave
= NULL
;
190 Mix_FreeChunk(rumble
);
198 MakeSound(char *channel
, char *id
)
203 if (!UserSoundOn
) return;
204 if (!SoundInitialized
) return;
206 for (i
= 0; i
< SIM_NSOUNDS
; i
++) {
207 if (!strcmp(sounds
[i
].id
, id
))
211 if (sounds
[i
].wave
) {
212 if (Mix_PlayChannel(-1, sounds
[i
].wave
, 0) == -1)
213 fprintf(stderr
, "Mix_PlayChannel: %s\n", Mix_GetError());
217 snprintf(buf
, sizeof(buf
), "%s/sounds/%s", ResourceDir
,
220 sounds
[i
].wave
= Mix_LoadWAV(buf
);
222 if (sounds
[i
].wave
== NULL
) {
223 fprintf(stderr
, "Mix_LoadWAV: %s\n", Mix_GetError());
227 if (Mix_PlayChannel(-1, sounds
[i
].wave
, 0) == -1)
228 fprintf(stderr
, "Mix_PlayChannel: %s\n", Mix_GetError());
231 MakeSoundOn(SimView
*view
, char *channel
, char *id
)
233 if (!UserSoundOn
) return;
234 if (!SoundInitialized
) return;
236 MakeSound(channel
, id
);
245 if (!UserSoundOn
) return;
246 if (!SoundInitialized
) return;
248 if (Mix_PlayChannel(DOZER_CHANNEL
, rumble
, 4) == -1) {
249 printf("Mix_PlayChannel: %s\n", Mix_GetError());
257 if (!UserSoundOn
) return;
258 if (!SoundInitialized
) return;
260 Mix_HaltChannel(DOZER_CHANNEL
);
264 /* XXX comefrom: doKeyEvent */
271 DoStartSound(char *channel
, char *id
)
273 MakeSound(channel
, id
);
276 DoStopSound(char *id
)
281 SoundCmd(CLIENT_ARGS
)
283 if (!strcmp(argv
[2], "Rumble"))
286 MakeSound(NULL
, argv
[2]);
290 DozerCmd(CLIENT_ARGS
)
298 Tcl_CreateCommand(tk_mainInterp
, "playsound", SoundCmd
,
299 (ClientData
)NULL
, (void (*)()) NULL
);
300 Tcl_CreateCommand(tk_mainInterp
, "stopdozer", DozerCmd
,
301 (ClientData
)NULL
, (void (*)()) NULL
);