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);
78 void addEnvSound(XYZ coords, float vol, float life)
80 envsound[numenvsounds] = coords;
81 envsoundvol[numenvsounds] = vol;
82 envsoundlife[numenvsounds] = life;
86 void emit_sound_at(int soundid, const XYZ& pos, float vol)
88 PlaySoundEx(soundid, samp[soundid], NULL, true);
89 OPENAL_3D_SetAttributes_(channels[soundid], pos);
90 OPENAL_SetVolume(channels[soundid], vol);
91 OPENAL_SetPaused(channels[soundid], false);
94 void emit_sound_np(int soundid, float vol)
96 PlaySoundEx(soundid, samp[soundid], NULL, true);
97 OPENAL_SetVolume(channels[soundid], vol);
98 OPENAL_SetPaused(channels[soundid], false);
101 void emit_stream_at(int soundid, const XYZ& pos, float vol)
103 PlayStreamEx(soundid, samp[soundid], NULL, true);
104 OPENAL_3D_SetAttributes_(channels[soundid], pos);
105 OPENAL_SetVolume(channels[soundid], vol);
106 OPENAL_SetPaused(channels[soundid], false);
109 void emit_stream_np(int soundid, float vol)
111 PlayStreamEx(soundid, samp[soundid], NULL, true);
112 OPENAL_SetVolume(channels[soundid], vol);
113 OPENAL_SetPaused(channels[soundid], false);
116 void resume_stream(int soundid)
118 OPENAL_SetPaused(channels[soundid], false);
121 void pause_sound(int soundid)
123 OPENAL_SetPaused(channels[soundid], true);