2 Copyright (C) 2003 Parallel Realities
3 Copyright (C) 2011, 2012 Guus Sliepen
4 Copyright (C) 2015 Julian Marchant
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 3
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "Starfighter.h"
22 static Mix_Chunk *sound[SFX_MAX];
23 static Mix_Music *music = NULL;
25 void audio_loadSounds()
27 sound[SFX_EXPLOSION] = Mix_LoadWAV("sound/explode.ogg");
28 sound[SFX_HIT] = Mix_LoadWAV("sound/explode2.ogg");
29 sound[SFX_DEATH] = Mix_LoadWAV("sound/maledeath.ogg");
30 sound[SFX_MISSILE] = Mix_LoadWAV("sound/missile.ogg");
31 sound[SFX_PLASMA] = Mix_LoadWAV("sound/plasma.ogg");
32 sound[SFX_CLOCK] = Mix_LoadWAV("sound/clock.ogg");
33 sound[SFX_FLY] = Mix_LoadWAV("sound/flyby.ogg");
34 sound[SFX_ENERGYRAY] = Mix_LoadWAV("sound/beamLaser.ogg");
35 sound[SFX_PICKUP] = Mix_LoadWAV("sound/item.ogg");
36 sound[SFX_SHIELDUP] = Mix_LoadWAV("sound/shield.ogg");
37 sound[SFX_CLOAK] = Mix_LoadWAV("sound/cloak.ogg");
38 sound[SFX_DEBRIS] = Mix_LoadWAV("sound/explode3.ogg");
39 sound[SFX_DEBRIS2] = Mix_LoadWAV("sound/explode4.ogg");
40 sound[SFX_LASER] = Mix_LoadWAV("sound/laser.ogg");
41 sound[SFX_PLASMA2] = Mix_LoadWAV("sound/plasma2.ogg");
42 sound[SFX_PLASMA3] = Mix_LoadWAV("sound/plasma3.ogg");
45 void audio_playSound(int sid, float x)
47 if ((!engine.useSound) || (!engine.useAudio))
51 static int freechannel = 4;
84 channel = freechannel++;
89 int angle = atanf((x - (screen->w / 2)) / (screen->w / 2)) * 180 / M_PI;
90 int attenuation = fabsf(x - (screen->w / 2)) / 40;
95 if (attenuation > 255)
98 Mix_SetPosition(channel, angle, attenuation);
99 Mix_PlayChannel(channel, sound[sid], 0);
102 void audio_haltMusic()
104 if (Mix_PlayingMusic())
112 Mix_FreeMusic(music);
117 void audio_pauseMusic()
119 if (Mix_PlayingMusic() && !Mix_PausedMusic())
123 void audio_resumeMusic()
128 void audio_setMusicVolume(int volume)
130 if (engine.useMusic && engine.useAudio)
131 Mix_VolumeMusic(volume);
134 void audio_playMusic(const char *filename, int loops)
136 if (engine.useMusic && engine.useAudio)
139 music = Mix_LoadMUS(filename);
140 audio_setMusicVolume(100);
141 Mix_PlayMusic(music, loops);
145 void audio_playRandomTrack()
147 if ((!engine.useMusic) || (!engine.useAudio))
152 "music/railjet_short.ogg", "music/space_dimensions.ogg",
153 "music/frozen_jam.ogg", "music/sound_and_silence.ogg"
159 audio_playMusic("music/railjet_short.ogg", -1);
165 audio_playMusic("music/orbital_colossus.ogg", -1);
168 audio_playMusic("music/RE.ogg", -1);
171 audio_playMusic(track[rand() % tracks], -1);
177 for (int i = 0 ; i < SFX_MAX ; i++)
179 if (sound[i] != NULL)
181 Mix_FreeChunk(sound[i]);
188 Mix_FreeMusic(music);