6b20bbd321ebcce199c8d806648bb600cf60595e
[oweals/minetest.git] / src / sound.h
1 /*
2 Minetest-c55
3 Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
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 General Public License for more details.
14
15 You should have received a copy of the GNU 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.
18 */
19
20 #ifndef SOUND_HEADER
21 #define SOUND_HEADER
22
23 #include "irrlichttypes.h"
24 #include <string>
25 #include <vector>
26 #include <set>
27
28 class OnDemandSoundFetcher
29 {
30 public:
31         virtual void getSoundFilenames(const std::string &name,
32                         std::set<std::string> &dst);
33 };
34
35 class ISoundManager
36 {
37 public:
38         virtual ~ISoundManager(){}
39         
40         // Multiple sounds can be loaded per name; when played, the sound
41         // should be chosen randomly from alternatives
42         // Return value determines success/failure
43         virtual bool loadSound(const std::string &name,
44                         const std::string &filepath) = 0;
45         virtual bool loadSound(const std::string &name,
46                         const std::vector<char> &filedata) = 0;
47
48         virtual void updateListener(v3f pos, v3f vel, v3f at, v3f up) = 0;
49         // playSound functions return -1 on failure, otherwise a handle to the
50         // sound
51         virtual int playSound(const std::string &name, int loopcount,
52                         float volume) = 0;
53         virtual int playSoundAt(const std::string &name, int loopcount,
54                         v3f pos, float volume) = 0;
55         virtual void stopSound(int sound) = 0;
56 };
57
58 class DummySoundManager: public ISoundManager
59 {
60 public:
61         virtual bool loadSound(const std::string &name,
62                         const std::string &filepath) {return true;}
63         virtual bool loadSound(const std::string &name,
64                         const std::vector<char> &filedata) {return true;}
65         void updateListener(v3f pos, v3f vel, v3f at, v3f up) {}
66         int playSound(const std::string &name, int loopcount,
67                         float volume) {return 0;}
68         int playSoundAt(const std::string &name, int loopcount,
69                         v3f pos, float volume) {return 0;}
70         void stopSound(int sound) {}
71 };
72
73 // Global DummySoundManager singleton
74 extern DummySoundManager dummySoundManager;
75
76 #endif
77