diff options
Diffstat (limited to 'libraries/irrlicht-1.8/examples/21.Quake3Explorer/sound.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/examples/21.Quake3Explorer/sound.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/examples/21.Quake3Explorer/sound.cpp b/libraries/irrlicht-1.8/examples/21.Quake3Explorer/sound.cpp new file mode 100644 index 0000000..75615c1 --- /dev/null +++ b/libraries/irrlicht-1.8/examples/21.Quake3Explorer/sound.cpp | |||
@@ -0,0 +1,98 @@ | |||
1 | /*! | ||
2 | Sound Factory. | ||
3 | provides a sound interface | ||
4 | |||
5 | */ | ||
6 | |||
7 | #include "sound.h" | ||
8 | |||
9 | |||
10 | //#define USE_IRRKLANG | ||
11 | |||
12 | #ifdef USE_IRRKLANG | ||
13 | |||
14 | #include <irrKlang.h> | ||
15 | #ifdef _IRR_WINDOWS_ | ||
16 | #pragma comment (lib, "irrKlang.lib") | ||
17 | #endif | ||
18 | |||
19 | using namespace irrklang; | ||
20 | |||
21 | struct soundfile: public IFileReader | ||
22 | { | ||
23 | soundfile ( io::IReadFile* f ): file (f ) {} | ||
24 | virtual ~soundfile () { file->drop (); } | ||
25 | |||
26 | virtual ik_s32 read(void* buffer, ik_u32 sizeToRead) { return file->read ( buffer, sizeToRead ); } | ||
27 | virtual bool seek(ik_s32 finalPos, bool relativeMovement = false) { return file->seek ( finalPos, relativeMovement ); } | ||
28 | virtual ik_s32 getSize(){ return file->getSize (); } | ||
29 | virtual ik_s32 getPos() {return file->getPos (); } | ||
30 | virtual const ik_c8* getFileName() { return file->getFileName (); } | ||
31 | io::IReadFile* file; | ||
32 | }; | ||
33 | |||
34 | struct klangFactory : public irrklang::IFileFactory | ||
35 | { | ||
36 | klangFactory ( IrrlichtDevice *device ) { Device = device; } | ||
37 | |||
38 | virtual irrklang::IFileReader* createFileReader(const ik_c8* filename) | ||
39 | { | ||
40 | io::IReadFile* file = Device->getFileSystem()->createAndOpenFile(filename); | ||
41 | if ( 0 == file ) | ||
42 | return 0; | ||
43 | |||
44 | return new soundfile ( file ); | ||
45 | } | ||
46 | |||
47 | IrrlichtDevice *Device; | ||
48 | }; | ||
49 | |||
50 | ISoundEngine *engine = 0; | ||
51 | ISound *backMusic = 0; | ||
52 | |||
53 | void sound_init ( IrrlichtDevice *device ) | ||
54 | { | ||
55 | engine = createIrrKlangDevice (); | ||
56 | if ( 0 == engine ) | ||
57 | return; | ||
58 | |||
59 | klangFactory *f = new klangFactory ( device ); | ||
60 | engine->addFileFactory ( f ); | ||
61 | } | ||
62 | |||
63 | void sound_shutdown () | ||
64 | { | ||
65 | if ( backMusic ) | ||
66 | backMusic->drop (); | ||
67 | |||
68 | if ( engine ) | ||
69 | engine->drop (); | ||
70 | } | ||
71 | |||
72 | void background_music ( const c8 * file ) | ||
73 | { | ||
74 | if ( 0 == engine ) | ||
75 | return; | ||
76 | |||
77 | if ( backMusic ) | ||
78 | { | ||
79 | backMusic->stop (); | ||
80 | backMusic->drop (); | ||
81 | } | ||
82 | |||
83 | backMusic = engine->play2D ( file, true, false, true ); | ||
84 | |||
85 | if ( backMusic ) | ||
86 | { | ||
87 | backMusic->setVolume ( 0.5f ); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | #else | ||
92 | |||
93 | void sound_init ( IrrlichtDevice *device ) {} | ||
94 | void sound_shutdown () {} | ||
95 | void background_music ( const c8 * file ) {} | ||
96 | |||
97 | #endif | ||
98 | |||