2
Copyright (C) 2004 Parallel Realities
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32
for (int i = 0 ; i < MAX_SOUNDS ; i++)
38
void Audio::setSoundVolume(int soundVolume)
40
this->soundVolume = soundVolume;
42
Mix_Volume(-1, soundVolume);
45
void Audio::setMusicVolume(int musicVolume)
47
this->musicVolume = musicVolume;
49
Mix_VolumeMusic(musicVolume);
52
void Audio::registerEngine(Engine *engine)
54
this->engine = engine;
57
bool Audio::loadSound(int i, char *filename)
59
if (!engine->useAudio)
64
printf("ERROR: SOUND INDEX IS HIGHER THAN MAXIMUM ALLOWED %d >= %d\n", i, MAX_SOUNDS);
70
Mix_FreeChunk(sound[i]);
75
engine->unpack(filename, PAK_SOUND);
76
sound[i] = Mix_LoadWAV_RW(engine->sdlrw, 1);
78
sound[i] = Mix_LoadWAV(filename);
83
printf("Sound '%s' not loaded\n", filename);
90
bool Audio::loadMusic(char *filename)
92
char tempPath[PATH_MAX];
94
sprintf(tempPath, "%smusic.mod", engine->userHomeDirectory);
96
if (!engine->useAudio)
103
SDL_Delay(250); // wait a bit, just to be sure!
109
Mix_FreeMusic(music);
114
engine->unpack(filename, PAK_MUSIC);
115
music = Mix_LoadMUS(tempPath);
117
music = Mix_LoadMUS(filename);
122
debug(("WARNING - Failed to load %s\n", filename));
129
void Audio::playSound(int snd, int channel)
131
if ((!engine->useAudio) || (soundVolume == 0))
134
Mix_Volume(channel, soundVolume);
136
Mix_PlayChannel(channel, sound[snd], 0);
139
void Audio::playSound(int snd, int channel, int loops)
141
if ((!engine->useAudio) || (soundVolume == 0))
144
Mix_Volume(channel, soundVolume);
146
Mix_PlayChannel(channel, sound[snd], loops);
149
void Audio::playMusic()
151
if (!engine->useAudio)
154
Mix_PlayMusic(music, -1);
156
Mix_VolumeMusic(musicVolume);
159
int Audio::playMenuSound(int sound)
161
if ((!engine->useAudio) || (soundVolume == 0))
164
if ((sound == 0) || (sound == 3))
168
//playSound(SND_HIGHLIGHT, CH_ANY);
171
//playSound(SND_SELECT, CH_ANY);
178
if (!engine->useAudio)
181
for (int i = 0 ; i < 8 ; i++)
189
if (!engine->useAudio)
192
for (int i = 0 ; i < 8 ; i++)
198
void Audio::stopMusic()
200
if (!engine->useAudio)
206
void Audio::fadeMusic()
208
if (!engine->useAudio)
211
Mix_FadeOutMusic(3500);
216
debug(("Audio::free()\n"));
218
for (int i = 0 ; i < MAX_SOUNDS - 3 ; i++)
220
if (sound[i] != NULL)
222
Mix_FreeChunk(sound[i]);
231
Mix_FreeMusic(music);
237
void Audio::destroy()
239
debug(("Audio::destroy()\n"));
243
for (int i = MAX_SOUNDS - 3 ; i < MAX_SOUNDS ; i++)
245
if (sound[i] != NULL)
247
Mix_FreeChunk(sound[i]);