1 #ifndef __SNDINT_H
2 #define __SNDINT_H
3 
4 #include <stdio.h>
5 
6 #include "basictypes.h"
7 #include "vectors.h"
8 #include "tarray.h"
9 
10 class FileReader;
11 
12 // For convenience, this structure matches FMOD_REVERB_PROPERTIES.
13 // Since I can't very well #include system-specific stuff in the
14 // main game files, I duplicate it here.
15 struct REVERB_PROPERTIES
16 {
17 	int			 Instance;
18     int			 Environment;
19     float        EnvSize;
20     float        EnvDiffusion;
21     int          Room;
22     int          RoomHF;
23     int          RoomLF;
24     float        DecayTime;
25     float        DecayHFRatio;
26     float        DecayLFRatio;
27     int          Reflections;
28     float        ReflectionsDelay;
29     float        ReflectionsPan0;
30 	float        ReflectionsPan1;
31 	float        ReflectionsPan2;
32     int          Reverb;
33     float        ReverbDelay;
34     float        ReverbPan0;
35 	float        ReverbPan1;
36 	float        ReverbPan2;
37     float        EchoTime;
38     float        EchoDepth;
39     float        ModulationTime;
40     float        ModulationDepth;
41     float        AirAbsorptionHF;
42     float        HFReference;
43     float        LFReference;
44     float        RoomRolloffFactor;
45     float        Diffusion;
46     float        Density;
47     unsigned int Flags;
48 };
49 
50 #define REVERB_FLAGS_DECAYTIMESCALE        0x00000001
51 #define REVERB_FLAGS_REFLECTIONSSCALE      0x00000002
52 #define REVERB_FLAGS_REFLECTIONSDELAYSCALE 0x00000004
53 #define REVERB_FLAGS_REVERBSCALE           0x00000008
54 #define REVERB_FLAGS_REVERBDELAYSCALE      0x00000010
55 #define REVERB_FLAGS_DECAYHFLIMIT          0x00000020
56 #define REVERB_FLAGS_ECHOTIMESCALE         0x00000040
57 #define REVERB_FLAGS_MODULATIONTIMESCALE   0x00000080
58 
59 struct ReverbContainer
60 {
61 	ReverbContainer *Next;
62 	const char *Name;
63 	WORD ID;
64 	bool Builtin;
65 	bool Modified;
66 	REVERB_PROPERTIES Properties;
67 	bool SoftwareWater;
68 };
69 
70 struct SoundListener
71 {
72 	FVector3 position;
73 	FVector3 velocity;
74 	float angle;
75 	bool underwater;
76 	bool valid;
77 	ReverbContainer *Environment;
78 };
79 
80 // Default rolloff information.
81 struct FRolloffInfo
82 {
83 	int RolloffType;
84 	float MinDistance;
85 	union { float MaxDistance; float RolloffFactor; };
86 };
87 
88 struct SoundHandle
89 {
90 	void *data;
91 
isValidSoundHandle92 	bool isValid() const { return data != NULL; }
ClearSoundHandle93 	void Clear() { data = NULL; }
94 };
95 
96 struct FISoundChannel
97 {
98 	void		*SysChannel;	// Channel information from the system interface.
99 	QWORD_UNION	StartTime;		// Sound start time in DSP clocks.
100 
101 	// The sound interface doesn't use these directly but it needs to pass them to a
102 	// callback that can't be passed a sound channel pointer
103 	FRolloffInfo Rolloff;
104 	float		DistanceScale;
105 	float		DistanceSqr;
106 	bool		ManualRolloff;
107 };
108 
109 
110 enum SampleType
111 {
112     SampleType_UInt8,
113     SampleType_Int16
114 };
115 enum ChannelConfig
116 {
117     ChannelConfig_Mono,
118     ChannelConfig_Stereo
119 };
120 
121 const char *GetSampleTypeName(enum SampleType type);
122 const char *GetChannelConfigName(enum ChannelConfig chan);
123 
124 struct SoundDecoder
125 {
126     virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0;
127 
128     virtual size_t read(char *buffer, size_t bytes) = 0;
129     virtual TArray<char> readAll();
130     virtual bool seek(size_t ms_offset) = 0;
131     virtual size_t getSampleOffset() = 0;
getSampleLengthSoundDecoder132     virtual size_t getSampleLength() { return 0; }
133 
SoundDecoderSoundDecoder134     SoundDecoder() { }
~SoundDecoderSoundDecoder135     virtual ~SoundDecoder() { }
136 
137 protected:
138     virtual bool open(FileReader *reader) = 0;
139     friend class SoundRenderer;
140 
141 private:
142     // Make non-copyable
143     SoundDecoder(const SoundDecoder &rhs);
144     SoundDecoder& operator=(const SoundDecoder &rhs);
145 };
146 
147 #endif
148