3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "irrlichttypes_bloated.h"
26 class OnDemandSoundFetcher
29 virtual void fetchSounds(const std::string &name,
30 std::set<std::string> &dst_paths,
31 std::set<std::string> &dst_datas) = 0;
34 struct SimpleSoundSpec
36 SimpleSoundSpec(const std::string &name = "", float gain = 1.0f,
37 float fade = 0.0f, float pitch = 1.0f) :
39 gain(gain), fade(fade), pitch(pitch)
43 bool exists() const { return !name.empty(); }
45 std::string name = "";
54 virtual ~ISoundManager() = default;
56 // Multiple sounds can be loaded per name; when played, the sound
57 // should be chosen randomly from alternatives
58 // Return value determines success/failure
59 virtual bool loadSoundFile(
60 const std::string &name, const std::string &filepath) = 0;
61 virtual bool loadSoundData(
62 const std::string &name, const std::string &filedata) = 0;
64 virtual void updateListener(v3f pos, v3f vel, v3f at, v3f up) = 0;
65 virtual void setListenerGain(float gain) = 0;
67 // playSound functions return -1 on failure, otherwise a handle to the
68 // sound. If name=="", call should be ignored without error.
69 virtual int playSound(const std::string &name, bool loop, float volume,
70 float fade = 0.0f, float pitch = 1.0f) = 0;
71 virtual int playSoundAt(const std::string &name, bool loop, float volume, v3f pos,
72 float pitch = 1.0f) = 0;
73 virtual void stopSound(int sound) = 0;
74 virtual bool soundExists(int sound) = 0;
75 virtual void updateSoundPosition(int sound, v3f pos) = 0;
76 virtual bool updateSoundGain(int id, float gain) = 0;
77 virtual float getSoundGain(int id) = 0;
78 virtual void step(float dtime) = 0;
79 virtual void fadeSound(int sound, float step, float gain) = 0;
81 int playSound(const SimpleSoundSpec &spec, bool loop)
83 return playSound(spec.name, loop, spec.gain, spec.fade, spec.pitch);
85 int playSoundAt(const SimpleSoundSpec &spec, bool loop, const v3f &pos)
87 return playSoundAt(spec.name, loop, spec.gain, pos, spec.pitch);
91 class DummySoundManager : public ISoundManager
94 virtual bool loadSoundFile(const std::string &name, const std::string &filepath)
98 virtual bool loadSoundData(const std::string &name, const std::string &filedata)
102 void updateListener(v3f pos, v3f vel, v3f at, v3f up) {}
103 void setListenerGain(float gain) {}
104 int playSound(const std::string &name, bool loop, float volume, float fade,
109 int playSoundAt(const std::string &name, bool loop, float volume, v3f pos,
114 void stopSound(int sound) {}
115 bool soundExists(int sound) { return false; }
116 void updateSoundPosition(int sound, v3f pos) {}
117 bool updateSoundGain(int id, float gain) { return false; }
118 float getSoundGain(int id) { return 0; }
119 void step(float dtime) {}
120 void fadeSound(int sound, float step, float gain) {}
123 // Global DummySoundManager singleton
124 extern DummySoundManager dummySoundManager;