2 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4 This file is part of Lugaru.
6 Lugaru 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 of the License, or
9 (at your option) any later version.
11 Lugaru 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 Lugaru. If not, see <http://www.gnu.org/licenses/>.
20 #include "Audio/Sounds.hpp"
22 #include "Audio/openal_wrapper.hpp"
23 #include "Utils/Folders.hpp"
25 struct OPENAL_SAMPLE *samp[sounds_count];
27 extern XYZ envsound[30];
28 extern float envsoundvol[30];
29 extern int numenvsounds;
30 extern float envsoundlife[30];
32 int footstepsound, footstepsound2, footstepsound3, footstepsound4;
36 static const char *sound_data[sounds_count] = {
37 #define DECLARE_SOUND(id, filename) filename,
42 // FIXME: dimensionality is not a property of the sound sample.
43 // This should be decided at the time of playback
44 static int snd_mode(int snd)
48 case consolefailsound:
49 case consolesuccesssound:
60 for (int i = 0; i < sounds_count; i++) {
61 std::string buf = std::string("Sounds/") + sound_data[i];
62 samp[i] = OPENAL_Sample_Load(OPENAL_FREE,
63 Folders::getResourcePath(buf).c_str(),
67 footstepsound = footstepsn1;
68 footstepsound2 = footstepsn2;
69 footstepsound3 = footstepst1;
70 footstepsound4 = footstepst2;
72 // OPENAL_Sample_SetMode(samp[whooshsound], OPENAL_LOOP_NORMAL);
73 for (int i = stream_firesound; i <= stream_menutheme; i++)
74 OPENAL_Stream_SetMode(samp[i], OPENAL_LOOP_NORMAL);
77 void addEnvSound(XYZ coords, float vol, float life)
79 envsound[numenvsounds] = coords;
80 envsoundvol[numenvsounds] = vol;
81 envsoundlife[numenvsounds] = life;
85 void emit_sound_at(int soundid, const XYZ &pos, float vol)
87 PlaySoundEx (soundid, samp[soundid], NULL, true);
88 OPENAL_3D_SetAttributes_ (channels[soundid], pos);
89 OPENAL_SetVolume (channels[soundid], vol);
90 OPENAL_SetPaused (channels[soundid], false);
93 void emit_sound_np(int soundid, float vol)
95 PlaySoundEx (soundid, samp[soundid], NULL, true);
96 OPENAL_SetVolume (channels[soundid], vol);
97 OPENAL_SetPaused (channels[soundid], false);
100 void emit_stream_at(int soundid, const XYZ &pos, float vol)
102 PlayStreamEx (soundid, samp[soundid], NULL, true);
103 OPENAL_3D_SetAttributes_ (channels[soundid], pos);
104 OPENAL_SetVolume (channels[soundid], vol);
105 OPENAL_SetPaused (channels[soundid], false);
108 void emit_stream_np(int soundid, float vol)
110 PlayStreamEx (soundid, samp[soundid], NULL, true);
111 OPENAL_SetVolume (channels[soundid], vol);
112 OPENAL_SetPaused (channels[soundid], false);
115 void resume_stream(int soundid)
117 OPENAL_SetPaused (channels[soundid], false);
120 void pause_sound(int soundid)
122 OPENAL_SetPaused (channels[soundid], true);