1 /* 2 * Copyright (C) Volition, Inc. 1999. All rights reserved. 3 * 4 * All source code herein is the property of Volition, Inc. You may not sell 5 * or otherwise commercially exploit the source or things you created based on the 6 * source. 7 * 8 */ 9 10 11 12 #ifndef __DS_H__ 13 #define __DS_H__ 14 15 #include "globalincs/pstypes.h" 16 #include "sound/IAudioFile.h" 17 #include "utils/id.h" 18 19 // Constants that DirectSound should assign, but doesn't 20 #define MIN_PITCH 100 21 #define MAX_PITCH 100000 22 23 24 // User specified sound quality 25 #define DS_SQ_LOW 0 26 #define DS_SQ_MEDIUM 1 27 #define DS_SQ_HIGH 2 28 29 extern int Ds_sound_quality; 30 extern int Ds_float_supported; 31 32 // limits placed on how many concurrent sounds of the same type can play simultaneously 33 #define DS_MUST_PLAY 0 34 #define DS_LIMIT_ONE 1 35 #define DS_LIMIT_TWO 2 36 #define DS_LIMIT_THREE 3 37 38 struct EnhancedSoundData; 39 40 #define DS_3D (1<<0) 41 42 typedef struct sound_info { 43 uint size; 44 int sample_rate; 45 int avg_bytes_per_sec; 46 int bits; 47 int n_channels; 48 int duration; // time in ms for duration of sound 49 } sound_info; 50 51 extern int ds_initialized; 52 53 struct ds_sound_handle_tag { 54 }; 55 using ds_sound_handle = ::util::ID<ds_sound_handle_tag, int, -1>; 56 57 int ds_init(); 58 void ds_close(); 59 int ds_load_buffer(int *sid, int flags, sound::IAudioFile* file); 60 void ds_unload_buffer(int sid); 61 ds_sound_handle ds_play(int sid, int snd_id, int priority, const EnhancedSoundData* enhanced_sound_data, float volume, 62 float pan, int looping, bool is_voice_msg = false); 63 int ds_get_channel(ds_sound_handle sig); 64 int ds_is_channel_playing(int channel); 65 void ds_stop_channel(int channel); 66 void ds_stop_channel_all(); 67 void ds_set_volume( int channel, float vol ); 68 void ds_set_pan( int channel, float pan ); 69 /** 70 * @brief Get the pitch of a channel 71 * 72 * @details A pitch value of 1.0 means that the original sound is not changed. 73 */ 74 float ds_get_pitch(int channel); 75 /** 76 * @brief Set the pitch of a channel 77 * 78 * @details A pitch value of 1.0 means that the original sound is not changed. 79 */ 80 void ds_set_pitch(int channel, float pitch); 81 void ds_set_position(int channel, unsigned int offset); 82 unsigned int ds_get_play_position(int channel); 83 int ds_get_data(int sid, char *data); 84 int ds_get_size(int sid, int *size); 85 86 int ds_create_buffer(int frequency, int bits_per_sample, int nchannels, int nseconds); 87 int ds_lock_data(int sid, unsigned char *data, int size); 88 void ds_stop_easy(int sid); 89 int ds_get_channel_size(int channel); 90 91 int ds_get_sound_id(int channel); 92 int ds_get_sound_index(int channel_id); 93 94 // Returns the number of channels that are actually playing 95 int ds_get_number_channels(); 96 97 ds_sound_handle ds3d_play(int sid, int snd_id, vec3d* pos, vec3d* vel, float min, float max, int looping, 98 float max_volume, float estimated_vol, const EnhancedSoundData* enhanced_sound_data, 99 int priority = DS_MUST_PLAY, bool is_ambient = false); 100 101 void ds_do_frame(); 102 103 // -------------------- 104 // 105 // Creative eax.h 106 // 107 // -------------------- 108 109 // use this structure for get/set all properties... 110 111 // used for const array of default values 112 typedef struct EFXREVERBPROPERTIES_list 113 { 114 const char *name; 115 float flDensity; 116 float flDiffusion; 117 float flGain; 118 float flGainHF; 119 float flGainLF; 120 float flDecayTime; 121 float flDecayHFRatio; 122 float flDecayLFRatio; 123 float flReflectionsGain; 124 float flReflectionsDelay; 125 float flReflectionsPan[3]; 126 float flLateReverbGain; 127 float flLateReverbDelay; 128 float flLateReverbPan[3]; 129 float flEchoTime; 130 float flEchoDepth; 131 float flModulationTime; 132 float flModulationDepth; 133 float flAirAbsorptionGainHF; 134 float flHFReference; 135 float flLFReference; 136 float flRoomRolloffFactor; 137 int iDecayHFLimit; 138 } EFXREVERBPROPERTIES_list; 139 140 typedef struct EFXREVERBPROPERTIES 141 { 142 SCP_string name; 143 float flDensity; 144 float flDiffusion; 145 float flGain; 146 float flGainHF; 147 float flGainLF; 148 float flDecayTime; 149 float flDecayHFRatio; 150 float flDecayLFRatio; 151 float flReflectionsGain; 152 float flReflectionsDelay; 153 float flReflectionsPan[3]; 154 float flLateReverbGain; 155 float flLateReverbDelay; 156 float flLateReverbPan[3]; 157 float flEchoTime; 158 float flEchoDepth; 159 float flModulationTime; 160 float flModulationDepth; 161 float flAirAbsorptionGainHF; 162 float flHFReference; 163 float flLFReference; 164 float flRoomRolloffFactor; 165 int iDecayHFLimit; EFXREVERBPROPERTIESEFXREVERBPROPERTIES166 EFXREVERBPROPERTIES() 167 { 168 } 169 EFXREVERBPROPERTIES(const EFXREVERBPROPERTIES_list &list); 170 } EFXREVERBPROPERTIES; 171 172 extern SCP_vector<EFXREVERBPROPERTIES> EFX_presets; 173 174 typedef struct 175 { 176 size_t environment; // 0 to EAX_ENVIRONMENT_COUNT-1 177 float fVolume; // 0 to 1 178 float fDecayTime_sec; // seconds, 0.1 to 100 179 float fDamping; // 0 to 1 180 } EAX_REVERBPROPERTIES; 181 182 enum 183 { 184 EAX_ENVIRONMENT_GENERIC, 185 EAX_ENVIRONMENT_PADDEDCELL, 186 EAX_ENVIRONMENT_ROOM, 187 EAX_ENVIRONMENT_BATHROOM, 188 EAX_ENVIRONMENT_LIVINGROOM, 189 EAX_ENVIRONMENT_STONEROOM, 190 EAX_ENVIRONMENT_AUDITORIUM, 191 EAX_ENVIRONMENT_CONCERTHALL, 192 EAX_ENVIRONMENT_CAVE, 193 EAX_ENVIRONMENT_ARENA, 194 EAX_ENVIRONMENT_HANGAR, 195 EAX_ENVIRONMENT_CARPETEDHALLWAY, 196 EAX_ENVIRONMENT_HALLWAY, 197 EAX_ENVIRONMENT_STONECORRIDOR, 198 EAX_ENVIRONMENT_ALLEY, 199 EAX_ENVIRONMENT_FOREST, 200 EAX_ENVIRONMENT_CITY, 201 EAX_ENVIRONMENT_MOUNTAINS, 202 EAX_ENVIRONMENT_QUARRY, 203 EAX_ENVIRONMENT_PLAIN, 204 EAX_ENVIRONMENT_PARKINGLOT, 205 EAX_ENVIRONMENT_SEWERPIPE, 206 EAX_ENVIRONMENT_UNDERWATER, 207 EAX_ENVIRONMENT_DRUGGED, 208 EAX_ENVIRONMENT_DIZZY, 209 EAX_ENVIRONMENT_PSYCHOTIC, 210 EAX_ENVIRONMENT_COUNT // total number of environments 211 }; 212 213 #define EAX_MAX_ENVIRONMENT (EAX_ENVIRONMENT_COUNT - 1) 214 215 216 // prototypes 217 218 int ds_eax_init(); 219 void ds_eax_close(); 220 221 int ds_eax_get_preset_id(const char *name); 222 int ds_eax_get_prop(EFXREVERBPROPERTIES **props, const char *name, const char *template_name = NULL); 223 224 int ds_eax_set_volume(float volume); 225 int ds_eax_set_decay_time(float seconds); 226 int ds_eax_set_damping(float damp); 227 int ds_eax_set_all(unsigned long id, float volume, float damping, float decay); 228 int ds_eax_get_all(EAX_REVERBPROPERTIES *er, int id = -1); 229 int ds_eax_is_inited(); 230 231 #endif /* __DS_H__ */ 232