This is a fork of Zandronum for Mac Os (Silicon and Intel)
リビジョン | ee76712daadefef8642448c0cc8f7ef826f0f914 (tree) |
---|---|
日時 | 2023-01-24 04:25:06 |
作者 | Joshua Surace <doomjoshuaboy@live...> |
コミッター | Joshua Surace |
Fixed up CMake and related sound issues.
@@ -188,6 +188,8 @@ | ||
188 | 188 | # [BB] The server doesn't need sound, GTK or OpenGL. |
189 | 189 | if( SERVERONLY ) |
190 | 190 | set( NO_SOUND ON ) |
191 | + set( NO_FMOD ON ) | |
192 | + set( NO_OPENAL ON ) | |
191 | 193 | set( NO_GTK ON ) |
192 | 194 | set( NO_GL ON ) |
193 | 195 | add_definitions ( -DSERVER_ONLY=1 ) |
@@ -351,7 +353,7 @@ | ||
351 | 353 | set( NO_FMOD ON ) |
352 | 354 | endif( FMOD_LIBRARY ) |
353 | 355 | endif( NOT NO_FMOD ) |
354 | - | |
356 | + | |
355 | 357 | if( NO_FMOD ) |
356 | 358 | add_definitions( -DNO_FMOD=1 ) |
357 | 359 | endif( NO_FMOD ) |
@@ -370,50 +372,6 @@ | ||
370 | 372 | |
371 | 373 | find_package( MPG123 ) |
372 | 374 | endif() |
373 | -# Search for FMOD include files | |
374 | - | |
375 | -if( NOT WIN32 ) | |
376 | - find_path( FMOD_INCLUDE_DIR fmod.hpp | |
377 | - PATHS ${FMOD_LOCAL_INC_DIRS} ) | |
378 | -endif( NOT WIN32 ) | |
379 | - | |
380 | -if( NOT FMOD_INCLUDE_DIR ) | |
381 | - find_path( FMOD_INCLUDE_DIR fmod.hpp | |
382 | - PATHS ${FMOD_SEARCH_PATHS} | |
383 | - ${FMOD_INC_PATH_SUFFIXES} ) | |
384 | -endif( NOT FMOD_INCLUDE_DIR ) | |
385 | - | |
386 | -if( FMOD_INCLUDE_DIR ) | |
387 | - message( STATUS "FMOD include files found at ${FMOD_INCLUDE_DIR}" ) | |
388 | -else( FMOD_INCLUDE_DIR ) | |
389 | - # [BB] Without sound, we don't need FMOD. | |
390 | - if ( NOT NO_SOUND ) | |
391 | - message( SEND_ERROR "Could not find FMOD include files" ) | |
392 | - endif ( NOT NO_SOUND ) | |
393 | -endif( FMOD_INCLUDE_DIR ) | |
394 | - | |
395 | - | |
396 | -# Search for FMOD library | |
397 | - | |
398 | -if( WIN32 OR APPLE ) | |
399 | - find_library( FMOD_LIBRARY ${FMOD_LIB_NAME} | |
400 | - PATHS ${FMOD_SEARCH_PATHS} | |
401 | - ${FMOD_LIB_PATH_SUFFIXES} ) | |
402 | -else( WIN32 OR APPLE ) | |
403 | - find_library( FMOD_LIBRARY | |
404 | - NAMES ${FMOD_VERSIONS} | |
405 | - PATHS ${FMOD_LOCAL_LIB_DIRS} ) | |
406 | -endif( WIN32 OR APPLE ) | |
407 | - | |
408 | -if( FMOD_LIBRARY ) | |
409 | - message( STATUS "FMOD library found at ${FMOD_LIBRARY}" ) | |
410 | -else( FMOD_LIBRARY ) | |
411 | - # [BB] Without sound, we don't need FMOD. | |
412 | - if ( NOT NO_SOUND ) | |
413 | - message( SEND_ERROR "Could not find FMOD library" ) | |
414 | - endif ( NOT NO_SOUND ) | |
415 | -endif( FMOD_LIBRARY ) | |
416 | - | |
417 | 375 | |
418 | 376 | # Search for FluidSynth |
419 | 377 |
@@ -1405,8 +1363,9 @@ | ||
1405 | 1363 | resourcefiles/resourcefile.cpp |
1406 | 1364 | sfmt/SFMT.cpp |
1407 | 1365 | sound/fmodsound.cpp |
1366 | + sound/oalsound.cpp | |
1408 | 1367 | sound/i_music.cpp |
1409 | - sound/i_sound.cpp | |
1368 | + sound/i_sound.cpp | |
1410 | 1369 | sound/music_cd.cpp |
1411 | 1370 | sound/music_dumb.cpp |
1412 | 1371 | sound/music_gme.cpp |
@@ -54,7 +54,7 @@ | ||
54 | 54 | #endif |
55 | 55 | |
56 | 56 | #include "templates.h" |
57 | -#ifndef NO_SOUND | |
57 | +#ifndef NO_FMOD | |
58 | 58 | #include "fmodsound.h" |
59 | 59 | #endif |
60 | 60 | #include "c_cvars.h" |
@@ -145,7 +145,7 @@ | ||
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | -#ifndef NO_SOUND | |
148 | +#ifndef NO_FMOD | |
149 | 149 | |
150 | 150 | // PRIVATE DATA DEFINITIONS ------------------------------------------------ |
151 | 151 |
@@ -1,8 +1,9 @@ | ||
1 | 1 | #ifndef FMODSOUND_H |
2 | 2 | #define FMODSOUND_H |
3 | 3 | |
4 | -#ifndef NO_SOUND | |
5 | 4 | #include "i_sound.h" |
5 | + | |
6 | +#ifndef NO_FMOD | |
6 | 7 | #include "fmod_wrap.h" |
7 | 8 | |
8 | 9 | class FMODSoundRenderer : public SoundRenderer |
@@ -60,9 +60,11 @@ | ||
60 | 60 | #include "doomtype.h" |
61 | 61 | #include <math.h> |
62 | 62 | |
63 | -#ifndef NO_SOUND | |
64 | 63 | #include "fmodsound.h" |
65 | -#endif | |
64 | +#include "oalsound.h" | |
65 | + | |
66 | +#include "mpg123_decoder.h" | |
67 | +#include "sndfile_decoder.h" | |
66 | 68 | |
67 | 69 | #include "m_swap.h" |
68 | 70 | #include "stats.h" |
@@ -87,6 +89,14 @@ | ||
87 | 89 | CVAR (Int, snd_buffersize, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) |
88 | 90 | CVAR (String, snd_output, "default", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) |
89 | 91 | |
92 | +#ifndef NO_FMOD | |
93 | +CVAR (String, snd_backend, "fmod", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) | |
94 | +#elif !defined(NO_OPENAL) | |
95 | +CVAR (String, snd_backend, "openal", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) | |
96 | +#else | |
97 | +CVAR (String, snd_backend, "null", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) | |
98 | +#endif | |
99 | + | |
90 | 100 | // killough 2/21/98: optionally use varying pitched sounds |
91 | 101 | CVAR (Bool, snd_pitched, false, CVAR_ARCHIVE) |
92 | 102 |
@@ -248,10 +258,6 @@ | ||
248 | 258 | |
249 | 259 | void I_InitSound () |
250 | 260 | { |
251 | -#ifdef NO_SOUND | |
252 | - GSnd = new NullSoundRenderer; | |
253 | - I_InitMusic (); | |
254 | -#else | |
255 | 261 | /* Get command line options: */ |
256 | 262 | nosound = !!Args->CheckParm ("-nosound") || !!Args->CheckParm("-host"); // [BB] No sound for the server |
257 | 263 | nosfx = !!Args->CheckParm ("-nosfx") || !!Args->CheckParm("-host"); // [BB] |
@@ -263,17 +269,25 @@ | ||
263 | 269 | return; |
264 | 270 | } |
265 | 271 | |
266 | - GSnd = new FMODSoundRenderer; | |
272 | + if(stricmp(snd_backend, "null") == 0) | |
273 | + GSnd = new NullSoundRenderer; | |
274 | + #ifndef NO_FMOD | |
275 | + else if(stricmp(snd_backend, "fmod") == 0) | |
276 | + GSnd = new FMODSoundRenderer; | |
277 | + #endif | |
278 | + #ifndef NO_OPENAL | |
279 | + else if(stricmp(snd_backend, "openal") == 0) | |
280 | + GSnd = new OpenALSoundRenderer; | |
281 | + #endif | |
267 | 282 | |
268 | 283 | if (!GSnd->IsValid ()) |
269 | 284 | { |
270 | 285 | I_CloseSound(); |
271 | 286 | GSnd = new NullSoundRenderer; |
272 | - Printf (TEXTCOLOR_RED"Sound init failed. Using nosound.\n"); | |
287 | + Printf ( TEXTCOLOR_RED "Sound init failed. Using nosound.\n"); | |
273 | 288 | } |
274 | 289 | I_InitMusic (); |
275 | 290 | snd_sfxvolume.Callback (); |
276 | -#endif | |
277 | 291 | } |
278 | 292 | |
279 | 293 |
@@ -336,9 +350,28 @@ | ||
336 | 350 | return "No stats for this sound renderer."; |
337 | 351 | } |
338 | 352 | |
339 | -short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType type) | |
353 | +short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype) | |
340 | 354 | { |
341 | - return NULL; | |
355 | + MemoryReader reader((const char*)coded, sizebytes); | |
356 | + short *samples = (short*)calloc(1, outlen); | |
357 | + ChannelConfig chans; | |
358 | + SampleType type; | |
359 | + int srate; | |
360 | + | |
361 | + SoundDecoder *decoder = CreateDecoder(&reader); | |
362 | + if(!decoder) return samples; | |
363 | + | |
364 | + decoder->getInfo(&srate, &chans, &type); | |
365 | + if(chans != ChannelConfig_Mono || type != SampleType_Int16) | |
366 | + { | |
367 | + DPrintf("Sample is not 16-bit mono\n"); | |
368 | + delete decoder; | |
369 | + return samples; | |
370 | + } | |
371 | + | |
372 | + decoder->read((char*)samples, outlen); | |
373 | + delete decoder; | |
374 | + return samples; | |
342 | 375 | } |
343 | 376 | |
344 | 377 | void SoundRenderer::DrawWaveDebug(int mode) |
@@ -519,3 +552,46 @@ | ||
519 | 552 | return retval; |
520 | 553 | } |
521 | 554 | |
555 | +SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader) | |
556 | +{ | |
557 | + SoundDecoder *decoder = NULL; | |
558 | + int pos = reader->Tell(); | |
559 | + | |
560 | +#ifdef HAVE_MPG123 | |
561 | + decoder = new MPG123Decoder; | |
562 | + if (decoder->open(reader)) | |
563 | + return decoder; | |
564 | + reader->Seek(pos, SEEK_SET); | |
565 | + | |
566 | + delete decoder; | |
567 | + decoder = NULL; | |
568 | +#endif | |
569 | +#ifdef HAVE_SNDFILE | |
570 | + decoder = new SndFileDecoder; | |
571 | + if (decoder->open(reader)) | |
572 | + return decoder; | |
573 | + reader->Seek(pos, SEEK_SET); | |
574 | + | |
575 | + delete decoder; | |
576 | + decoder = NULL; | |
577 | +#endif | |
578 | + return decoder; | |
579 | +} | |
580 | + | |
581 | + | |
582 | +// Default readAll implementation, for decoders that can't do anything better | |
583 | +TArray<char> SoundDecoder::readAll() | |
584 | +{ | |
585 | + TArray<char> output; | |
586 | + size_t total = 0; | |
587 | + size_t got; | |
588 | + | |
589 | + output.Resize(total+32768); | |
590 | + while((got=read(&output[total], output.Size()-total)) > 0) | |
591 | + { | |
592 | + total += got; | |
593 | + output.Resize(total*2); | |
594 | + } | |
595 | + output.Resize(total); | |
596 | + return output; | |
597 | +} |
@@ -40,44 +40,44 @@ | ||
40 | 40 | |
41 | 41 | enum ECodecType |
42 | 42 | { |
43 | - CODEC_Unknown, | |
44 | - CODEC_Vorbis, | |
43 | + CODEC_Unknown, | |
44 | + CODEC_Vorbis, | |
45 | 45 | }; |
46 | 46 | |
47 | 47 | enum EStartSoundFlags |
48 | 48 | { |
49 | - SNDF_LOOP=1, | |
50 | - SNDF_NOPAUSE=2, | |
51 | - SNDF_AREA=4, | |
52 | - SNDF_ABSTIME=8, | |
53 | - SNDF_NOREVERB=16, | |
49 | + SNDF_LOOP=1, | |
50 | + SNDF_NOPAUSE=2, | |
51 | + SNDF_AREA=4, | |
52 | + SNDF_ABSTIME=8, | |
53 | + SNDF_NOREVERB=16, | |
54 | 54 | }; |
55 | 55 | |
56 | 56 | class SoundStream |
57 | 57 | { |
58 | 58 | public: |
59 | - virtual ~SoundStream (); | |
60 | - | |
61 | - enum | |
62 | - { // For CreateStream | |
63 | - Mono = 1, | |
64 | - Bits8 = 2, | |
65 | - Bits32 = 4, | |
66 | - Float = 8, | |
59 | + virtual ~SoundStream (); | |
67 | 60 | |
68 | - // For OpenStream | |
69 | - Loop = 16 | |
70 | - }; | |
61 | + enum | |
62 | + { // For CreateStream | |
63 | + Mono = 1, | |
64 | + Bits8 = 2, | |
65 | + Bits32 = 4, | |
66 | + Float = 8, | |
71 | 67 | |
72 | - virtual bool Play(bool looping, float volume) = 0; | |
73 | - virtual void Stop() = 0; | |
74 | - virtual void SetVolume(float volume) = 0; | |
75 | - virtual bool SetPaused(bool paused) = 0; | |
76 | - virtual unsigned int GetPosition() = 0; | |
77 | - virtual bool IsEnded() = 0; | |
78 | - virtual bool SetPosition(unsigned int pos); | |
79 | - virtual bool SetOrder(int order); | |
80 | - virtual FString GetStats(); | |
68 | + // For OpenStream | |
69 | + Loop = 16 | |
70 | + }; | |
71 | + | |
72 | + virtual bool Play(bool looping, float volume) = 0; | |
73 | + virtual void Stop() = 0; | |
74 | + virtual void SetVolume(float volume) = 0; | |
75 | + virtual bool SetPaused(bool paused) = 0; | |
76 | + virtual unsigned int GetPosition() = 0; | |
77 | + virtual bool IsEnded() = 0; | |
78 | + virtual bool SetPosition(unsigned int pos); | |
79 | + virtual bool SetOrder(int order); | |
80 | + virtual FString GetStats(); | |
81 | 81 | }; |
82 | 82 | |
83 | 83 | typedef bool (*SoundStreamCallback)(SoundStream *stream, void *buff, int len, void *userdata); |
@@ -85,71 +85,73 @@ | ||
85 | 85 | class SoundRenderer |
86 | 86 | { |
87 | 87 | public: |
88 | - SoundRenderer (); | |
89 | - virtual ~SoundRenderer (); | |
90 | - | |
91 | - virtual bool IsNull() { return false; } | |
92 | - virtual void SetSfxVolume (float volume) = 0; | |
93 | - virtual void SetMusicVolume (float volume) = 0; | |
94 | - virtual SoundHandle LoadSound(BYTE *sfxdata, int length) = 0; | |
95 | - SoundHandle LoadSoundVoc(BYTE *sfxdata, int length); | |
96 | - virtual SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1) = 0; | |
97 | - virtual void UnloadSound (SoundHandle sfx) = 0; // unloads a sound from memory | |
98 | - virtual unsigned int GetMSLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency | |
99 | - virtual unsigned int GetSampleLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency | |
100 | - virtual float GetOutputRate() = 0; | |
101 | - | |
102 | - // Streaming sounds. | |
103 | - virtual SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) = 0; | |
104 | - virtual SoundStream *OpenStream (const char *filename, int flags, int offset, int length) = 0; | |
105 | - | |
106 | - // Starts a sound. | |
107 | - virtual FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) = 0; | |
108 | - virtual FISoundChannel *StartSound3D (SoundHandle sfx, SoundListener *listener, float vol, FRolloffInfo *rolloff, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, int channum, int chanflags, FISoundChannel *reuse_chan) = 0; | |
109 | - | |
110 | - // Stops a sound channel. | |
111 | - virtual void StopChannel (FISoundChannel *chan) = 0; | |
112 | - | |
113 | - // Changes a channel's volume. | |
114 | - virtual void ChannelVolume (FISoundChannel *chan, float volume) = 0; | |
115 | - | |
116 | - // Marks a channel's start time without actually playing it. | |
117 | - virtual void MarkStartTime (FISoundChannel *chan) = 0; | |
88 | + SoundRenderer (); | |
89 | + virtual ~SoundRenderer (); | |
118 | 90 | |
119 | - // Returns position of sound on this channel, in samples. | |
120 | - virtual unsigned int GetPosition(FISoundChannel *chan) = 0; | |
121 | - | |
122 | - // Gets a channel's audibility (real volume). | |
123 | - virtual float GetAudibility(FISoundChannel *chan) = 0; | |
124 | - | |
125 | - // Synchronizes following sound startups. | |
126 | - virtual void Sync (bool sync) = 0; | |
127 | - | |
128 | - // Pauses or resumes all sound effect channels. | |
129 | - virtual void SetSfxPaused (bool paused, int slot) = 0; | |
91 | + virtual bool IsNull() { return false; } | |
92 | + virtual void SetSfxVolume (float volume) = 0; | |
93 | + virtual void SetMusicVolume (float volume) = 0; | |
94 | + virtual SoundHandle LoadSound(BYTE *sfxdata, int length) = 0; | |
95 | + SoundHandle LoadSoundVoc(BYTE *sfxdata, int length); | |
96 | + virtual SoundHandle LoadSoundRaw(BYTE *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1) = 0; | |
97 | + virtual void UnloadSound (SoundHandle sfx) = 0; // unloads a sound from memory | |
98 | + virtual unsigned int GetMSLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency | |
99 | + virtual unsigned int GetSampleLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency | |
100 | + virtual float GetOutputRate() = 0; | |
130 | 101 | |
131 | - // Pauses or resumes *every* channel, including environmental reverb. | |
132 | - enum EInactiveState | |
133 | - { | |
134 | - INACTIVE_Active, // sound is active | |
135 | - INACTIVE_Complete, // sound is completely paused | |
136 | - INACTIVE_Mute // sound is only muted | |
137 | - }; | |
138 | - virtual void SetInactive(EInactiveState inactive) = 0; | |
102 | + // Streaming sounds. | |
103 | + virtual SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) = 0; | |
104 | + virtual SoundStream *OpenStream (const char *filename, int flags, int offset, int length) = 0; | |
139 | 105 | |
140 | - // Updates the volume, separation, and pitch of a sound channel. | |
141 | - virtual void UpdateSoundParams3D (SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel) = 0; | |
142 | - | |
143 | - virtual void UpdateListener (SoundListener *) = 0; | |
144 | - virtual void UpdateSounds () = 0; | |
106 | + // Starts a sound. | |
107 | + virtual FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) = 0; | |
108 | + virtual FISoundChannel *StartSound3D (SoundHandle sfx, SoundListener *listener, float vol, FRolloffInfo *rolloff, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, int channum, int chanflags, FISoundChannel *reuse_chan) = 0; | |
145 | 109 | |
146 | - virtual bool IsValid () = 0; | |
147 | - virtual void PrintStatus () = 0; | |
148 | - virtual void PrintDriversList () = 0; | |
149 | - virtual FString GatherStats (); | |
150 | - virtual short *DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType type); | |
110 | + // Stops a sound channel. | |
111 | + virtual void StopChannel (FISoundChannel *chan) = 0; | |
151 | 112 | |
152 | - virtual void DrawWaveDebug(int mode); | |
113 | + // Changes a channel's volume. | |
114 | + virtual void ChannelVolume (FISoundChannel *chan, float volume) = 0; | |
115 | + | |
116 | + // Marks a channel's start time without actually playing it. | |
117 | + virtual void MarkStartTime (FISoundChannel *chan) = 0; | |
118 | + | |
119 | + // Returns position of sound on this channel, in samples. | |
120 | + virtual unsigned int GetPosition(FISoundChannel *chan) = 0; | |
121 | + | |
122 | + // Gets a channel's audibility (real volume). | |
123 | + virtual float GetAudibility(FISoundChannel *chan) = 0; | |
124 | + | |
125 | + // Synchronizes following sound startups. | |
126 | + virtual void Sync (bool sync) = 0; | |
127 | + | |
128 | + // Pauses or resumes all sound effect channels. | |
129 | + virtual void SetSfxPaused (bool paused, int slot) = 0; | |
130 | + | |
131 | + // Pauses or resumes *every* channel, including environmental reverb. | |
132 | + enum EInactiveState | |
133 | + { | |
134 | + INACTIVE_Active, // sound is active | |
135 | + INACTIVE_Complete, // sound is completely paused | |
136 | + INACTIVE_Mute // sound is only muted | |
137 | + }; | |
138 | + virtual void SetInactive(EInactiveState inactive) = 0; | |
139 | + | |
140 | + // Updates the volume, separation, and pitch of a sound channel. | |
141 | + virtual void UpdateSoundParams3D (SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel) = 0; | |
142 | + | |
143 | + virtual void UpdateListener (SoundListener *) = 0; | |
144 | + virtual void UpdateSounds () = 0; | |
145 | + | |
146 | + virtual bool IsValid () = 0; | |
147 | + virtual void PrintStatus () = 0; | |
148 | + virtual void PrintDriversList () = 0; | |
149 | + virtual FString GatherStats (); | |
150 | + virtual short *DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType type); | |
151 | + | |
152 | + virtual void DrawWaveDebug(int mode); | |
153 | +protected: | |
154 | + virtual SoundDecoder *CreateDecoder(FileReader *reader); | |
153 | 155 | }; |
154 | 156 | |
155 | 157 | extern SoundRenderer *GSnd; |
@@ -2,14 +2,18 @@ | ||
2 | 2 | #define __SNDINT_H |
3 | 3 | |
4 | 4 | #include "basictypes.h" |
5 | +#include "vectors.h" | |
6 | +#include "tarray.h" | |
7 | + | |
8 | +class FileReader; | |
5 | 9 | |
6 | 10 | // For convenience, this structure matches FMOD_REVERB_PROPERTIES. |
7 | 11 | // Since I can't very well #include system-specific stuff in the |
8 | 12 | // main game files, I duplicate it here. |
9 | 13 | struct REVERB_PROPERTIES |
10 | -{ | |
11 | - int Instance; | |
12 | - int Environment; | |
14 | +{ | |
15 | + int Instance; | |
16 | + int Environment; | |
13 | 17 | float EnvSize; |
14 | 18 | float EnvDiffusion; |
15 | 19 | int Room; |
@@ -21,13 +25,13 @@ | ||
21 | 25 | int Reflections; |
22 | 26 | float ReflectionsDelay; |
23 | 27 | float ReflectionsPan0; |
24 | - float ReflectionsPan1; | |
25 | - float ReflectionsPan2; | |
28 | + float ReflectionsPan1; | |
29 | + float ReflectionsPan2; | |
26 | 30 | int Reverb; |
27 | 31 | float ReverbDelay; |
28 | 32 | float ReverbPan0; |
29 | - float ReverbPan1; | |
30 | - float ReverbPan2; | |
33 | + float ReverbPan1; | |
34 | + float ReverbPan2; | |
31 | 35 | float EchoTime; |
32 | 36 | float EchoDepth; |
33 | 37 | float ModulationTime; |
@@ -52,52 +56,91 @@ | ||
52 | 56 | |
53 | 57 | struct ReverbContainer |
54 | 58 | { |
55 | - ReverbContainer *Next; | |
56 | - const char *Name; | |
57 | - WORD ID; | |
58 | - bool Builtin; | |
59 | - bool Modified; | |
60 | - REVERB_PROPERTIES Properties; | |
61 | - bool SoftwareWater; | |
59 | + ReverbContainer *Next; | |
60 | + const char *Name; | |
61 | + WORD ID; | |
62 | + bool Builtin; | |
63 | + bool Modified; | |
64 | + REVERB_PROPERTIES Properties; | |
65 | + bool SoftwareWater; | |
62 | 66 | }; |
63 | 67 | |
64 | 68 | struct SoundListener |
65 | 69 | { |
66 | - FVector3 position; | |
67 | - FVector3 velocity; | |
68 | - float angle; | |
69 | - bool underwater; | |
70 | - bool valid; | |
71 | - ReverbContainer *Environment; | |
70 | + FVector3 position; | |
71 | + FVector3 velocity; | |
72 | + float angle; | |
73 | + bool underwater; | |
74 | + bool valid; | |
75 | + ReverbContainer *Environment; | |
72 | 76 | }; |
73 | 77 | |
74 | 78 | // Default rolloff information. |
75 | 79 | struct FRolloffInfo |
76 | 80 | { |
77 | - int RolloffType; | |
78 | - float MinDistance; | |
79 | - union { float MaxDistance; float RolloffFactor; }; | |
81 | + int RolloffType; | |
82 | + float MinDistance; | |
83 | + union { float MaxDistance; float RolloffFactor; }; | |
80 | 84 | }; |
81 | 85 | |
82 | 86 | struct SoundHandle |
83 | 87 | { |
84 | - void *data; | |
88 | + void *data; | |
85 | 89 | |
86 | - bool isValid() const { return data != NULL; } | |
87 | - void Clear() { data = NULL; } | |
90 | + bool isValid() const { return data != NULL; } | |
91 | + void Clear() { data = NULL; } | |
88 | 92 | }; |
89 | 93 | |
90 | 94 | struct FISoundChannel |
91 | 95 | { |
92 | - void *SysChannel; // Channel information from the system interface. | |
93 | - QWORD_UNION StartTime; // Sound start time in DSP clocks. | |
96 | + void *SysChannel; // Channel information from the system interface. | |
97 | + QWORD_UNION StartTime; // Sound start time in DSP clocks. | |
94 | 98 | |
95 | - // The sound interface doesn't use these directly but it needs to pass them to a | |
96 | - // callback that can't be passed a sound channel pointer | |
97 | - FRolloffInfo Rolloff; | |
98 | - float DistanceScale; | |
99 | + // The sound interface doesn't use these directly but it needs to pass them to a | |
100 | + // callback that can't be passed a sound channel pointer | |
101 | + FRolloffInfo Rolloff; | |
102 | + float DistanceScale; | |
103 | + float DistanceSqr; | |
104 | + bool ManualRolloff; | |
105 | +}; | |
106 | + | |
107 | +enum SampleType | |
108 | +{ | |
109 | + SampleType_UInt8, | |
110 | + SampleType_Int16 | |
111 | +}; | |
112 | +enum ChannelConfig | |
113 | +{ | |
114 | + ChannelConfig_Mono, | |
115 | + ChannelConfig_Stereo | |
116 | +}; | |
117 | + | |
118 | +const char *GetSampleTypeName(enum SampleType type); | |
119 | +const char *GetChannelConfigName(enum ChannelConfig chan); | |
120 | + | |
121 | +struct SoundDecoder | |
122 | +{ | |
123 | + virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0; | |
124 | + | |
125 | + virtual size_t read(char *buffer, size_t bytes) = 0; | |
126 | + virtual TArray<char> readAll(); | |
127 | + virtual bool seek(size_t ms_offset) = 0; | |
128 | + virtual size_t getSampleOffset() = 0; | |
129 | + virtual size_t getSampleLength() { return 0; } | |
130 | + | |
131 | + SoundDecoder() { } | |
132 | + virtual ~SoundDecoder() { } | |
133 | + | |
134 | +protected: | |
135 | + virtual bool open(FileReader *reader) = 0; | |
136 | + friend class SoundRenderer; | |
137 | + | |
138 | +private: | |
139 | + // Make non-copyable | |
140 | + SoundDecoder(const SoundDecoder &rhs); | |
141 | + SoundDecoder& operator=(const SoundDecoder &rhs); | |
99 | 142 | }; |
100 | 143 | |
101 | 144 | |
145 | +#endif | |
102 | 146 | |
103 | -#endif |
@@ -137,8 +137,18 @@ | ||
137 | 137 | { |
138 | 138 | return Array[Count-1]; |
139 | 139 | } |
140 | - | |
141 | - unsigned int Push (const T &item) | |
140 | + | |
141 | + unsigned int Find(const T& item) const | |
142 | + { | |
143 | + unsigned int i; | |
144 | + for(i = 0;i < Count;++i) | |
145 | + { | |
146 | + if(Array[i] == item) | |
147 | + break; | |
148 | + } | |
149 | + return i; | |
150 | + } | |
151 | + unsigned int Push (const T &item) | |
142 | 152 | { |
143 | 153 | Grow (1); |
144 | 154 | ::new((void*)&Array[Count]) T(item); |