]> git.jsancho.org Git - lugaru.git/blob - Source/Sounds.cpp
Add copyright notice and AUTHORS file for open source contributors
[lugaru.git] / Source / Sounds.cpp
1 /*
2 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
3
4 This file is part of Lugaru.
5
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.
10
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.
15
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/>.
18 */
19
20 #include "Quaternions.h"
21 #include "Sounds.h"
22 #include "openal_wrapper.h"
23
24 struct OPENAL_SAMPLE *samp[sounds_count];
25
26 int footstepsound, footstepsound2, footstepsound3, footstepsound4;
27
28 int channels[100];
29
30 static const char *sound_data[sounds_count] = {
31 #define DECLARE_SOUND(id, filename) filename,
32 #include "Sounds.def"
33 #undef DECLARE_SOUND
34 };
35
36 // FIXME: dimensionality is not a property of the sound sample.
37 // This should be decided at the time of playback
38 static int snd_mode(int snd)
39 {
40     switch (snd) {
41     case alarmsound:
42     case consolefailsound:
43     case consolesuccesssound:
44     case firestartsound:
45     case fireendsound:
46         return OPENAL_2D;
47     default:
48         return OPENAL_HW3D;
49     }
50 }
51
52 void loadAllSounds()
53 {
54     for (int i = 0; i < sounds_count; i++) {
55         char buf[64];
56         snprintf(buf, 64, ":Data:Sounds:%s", sound_data[i]);
57         samp[i] = OPENAL_Sample_Load(OPENAL_FREE,
58                                      ConvertFileName(buf),
59                                      snd_mode(i),
60                                      0, 0);
61     }
62     footstepsound = footstepsn1;
63     footstepsound2 = footstepsn2;
64     footstepsound3 = footstepst1;
65     footstepsound4 = footstepst2;
66     // Huh?
67     // OPENAL_Sample_SetMode(samp[whooshsound], OPENAL_LOOP_NORMAL);
68     for (int i = stream_firesound; i <= stream_menutheme; i++)
69         OPENAL_Stream_SetMode(samp[i], OPENAL_LOOP_NORMAL);
70 }
71
72 void
73 emit_sound_at(int soundid, const XYZ &pos, float vol)
74 {
75     PlaySoundEx (soundid, samp[soundid], NULL, true);
76     OPENAL_3D_SetAttributes_ (channels[soundid], pos, NULL);
77     OPENAL_SetVolume (channels[soundid], vol);
78     OPENAL_SetPaused (channels[soundid], false);
79 }
80
81 void
82 emit_sound_np(int soundid, float vol)
83 {
84     PlaySoundEx (soundid, samp[soundid], NULL, true);
85     OPENAL_SetVolume (channels[soundid], vol);
86     OPENAL_SetPaused (channels[soundid], false);
87 }
88
89 void
90 emit_stream_at(int soundid, const XYZ &pos, float vol)
91 {
92     PlayStreamEx (soundid, samp[soundid], NULL, true);
93     OPENAL_3D_SetAttributes_ (channels[soundid], pos, NULL);
94     OPENAL_SetVolume (channels[soundid], vol);
95     OPENAL_SetPaused (channels[soundid], false);
96 }
97
98 void
99 emit_stream_np(int soundid, float vol)
100 {
101     PlayStreamEx (soundid, samp[soundid], NULL, true);
102     OPENAL_SetVolume (channels[soundid], vol);
103     OPENAL_SetPaused (channels[soundid], false);
104 }
105
106 void
107 resume_stream(int soundid)
108 {
109     OPENAL_SetPaused (channels[soundid], false);
110 }
111
112 void
113 pause_sound(int soundid)
114 {
115     OPENAL_SetPaused (channels[soundid], true);
116 }
117