1 2 #ifndef AUDIO_H 3 #define AUDIO_H 4 5 #include <stdint.h> 6 7 // AL_UNITS constant is used to translate native TR coordinates into 8 // OpenAL coordinates. By default, it's the same as geometry grid 9 // resolution (1024). 10 11 #define TR_AUDIO_AL_UNITS 1024.0 12 13 // MAX_CHANNELS defines maximum amount of sound sources (channels) 14 // that can play at the same time. Contemporary devices can play 15 // up to 256 channels, but we set it to 32 for compatibility 16 // reasons. 17 18 #define TR_AUDIO_MAX_CHANNELS 32 19 20 // NUMSOURCES tells the engine how many sources we should reserve for 21 // in-game music and BGMs, considering crossfades. By default, it's 6, 22 // as it's more than enough for typical TR audio setup (one BGM track 23 // plus one one-shot track or chat track in TR5). 24 25 #define TR_AUDIO_STREAM_NUMSOURCES 6 26 27 28 // Sound flags are found at offset 7 of SoundDetail unit and specify 29 // certain sound modifications. 30 31 #define TR_AUDIO_FLAG_RAND_PITCH 0x20 // P flag. Slight random pitch shift. 32 #define TR_AUDIO_FLAG_RAND_VOLUME 0x40 // V flag. Slight random gain shift. 33 #define TR_AUDIO_FLAG_UNKNOWN 0x10 // N flag. UNKNOWN MEANING! 34 35 // Looped field is located at offset 6 of SoundDetail structure and 36 // combined with SampleIndexes value. This field is responsible for 37 // looping behaviour of each sound. 38 // L flag sets sound to continous looped state, while W flag waits 39 // for any sound with similar ID to finish, and only then plays it 40 // again. R flag rewinds sound, if sound with similar ID is being 41 // sent to sources. 42 43 #define TR_AUDIO_LOOP_LOOPED 0x03 // L flag. Normal looped. 44 #define TR_AUDIO_LOOP_REWIND 0x02 // R flag. Rewind on re-send. 45 #define TR_AUDIO_LOOP_WAIT 0x01 // W flag. Wait until play is over. 46 #define TR_AUDIO_LOOP_NONE 0x00 // No looping. 47 48 // Sample number mask is a mask value used in bitwise operation with 49 // "num_samples_and_flags_1" field to extract amount of samples per 50 // effect. 51 52 #define TR_AUDIO_SAMPLE_NUMBER_MASK 0x0F 53 54 // Entity types are used to identify different sound emitter types. Since 55 // sounds in TR games could be emitted either by entities, sound sources 56 // or global events, we have defined these three types of emitters. 57 58 #define TR_AUDIO_EMITTER_ENTITY 0 // Entity (movable) 59 #define TR_AUDIO_EMITTER_SOUNDSOURCE 1 // Sound source (static) 60 #define TR_AUDIO_EMITTER_GLOBAL 2 // Global sound (menus, secret, etc.) 61 62 // Possible types of errors returned by Audio_Send / Audio_Kill functions. 63 64 #define TR_AUDIO_SEND_NOSAMPLE (-2) 65 #define TR_AUDIO_SEND_NOCHANNEL (-1) 66 #define TR_AUDIO_SEND_IGNORED 0 67 #define TR_AUDIO_SEND_PROCESSED 1 68 69 // Define some common samples across ALL TR versions. 70 71 #define TR_AUDIO_SOUND_NO 2 72 #define TR_AUDIO_SOUND_SLIDING 3 73 #define TR_AUDIO_SOUND_LANDING 4 74 #define TR_AUDIO_SOUND_HOLSTEROUT 6 75 #define TR_AUDIO_SOUND_HOLSTERIN 7 76 #define TR_AUDIO_SOUND_SHOTPISTOLS 8 77 #define TR_AUDIO_SOUND_RELOAD 9 78 #define TR_AUDIO_SOUND_RICOCHET 10 79 #define TR_AUDIO_SOUND_LARASCREAM 30 80 #define TR_AUDIO_SOUND_LARAINJURY 31 81 #define TR_AUDIO_SOUND_SPLASH 33 82 #define TR_AUDIO_SOUND_FROMWATER 34 83 #define TR_AUDIO_SOUND_SWIM 35 84 #define TR_AUDIO_SOUND_LARABREATH 36 85 #define TR_AUDIO_SOUND_BUBBLE 37 86 #define TR_AUDIO_SOUND_USEKEY 39 87 #define TR_AUDIO_SOUND_SHOTUZI 43 88 #define TR_AUDIO_SOUND_SHOTSHOTGUN 45 89 #define TR_AUDIO_SOUND_UNDERWATER 60 90 #define TR_AUDIO_SOUND_PUSHABLE 63 91 #define TR_AUDIO_SOUND_MENUROTATE 108 92 #define TR_AUDIO_SOUND_MENUSELECT 109 93 #define TR_AUDIO_SOUND_MENUOPEN 111 94 #define TR_AUDIO_SOUND_MENUCLOSE 112 // Only used in TR1-3. 95 #define TR_AUDIO_SOUND_MENUCLANG 114 96 #define TR_AUDIO_SOUND_MENUPAGE 115 97 #define TR_AUDIO_SOUND_MEDIPACK 116 98 99 // Certain sound effect indexes were changed across different TR 100 // versions, despite remaining the same - mostly, it happened with 101 // menu sounds and some general sounds. For such effects, we specify 102 // additional remap enumeration list, which is fed into Lua script 103 // to get actual effect ID for current game version. 104 105 enum TR_AUDIO_SOUND_GLOBALID 106 { 107 TR_AUDIO_SOUND_GLOBALID_MENUOPEN, 108 TR_AUDIO_SOUND_GLOBALID_MENUCLOSE, 109 TR_AUDIO_SOUND_GLOBALID_MENUROTATE, 110 TR_AUDIO_SOUND_GLOBALID_MENUPAGE, 111 TR_AUDIO_SOUND_GLOBALID_MENUSELECT, 112 TR_AUDIO_SOUND_GLOBALID_MENUWEAPON, 113 TR_AUDIO_SOUND_GLOBALID_MENUCLANG, 114 TR_AUDIO_SOUND_GLOBALID_MENUAUDIOTEST, 115 TR_AUDIO_SOUND_GLOBALID_LASTINDEX 116 }; 117 118 119 // Possible errors produced by Audio_StreamPlay / Audio_StreamStop functions. 120 #define TR_AUDIO_STREAMPLAY_PLAYERROR (-4) 121 #define TR_AUDIO_STREAMPLAY_LOADERROR (-3) 122 #define TR_AUDIO_STREAMPLAY_WRONGTRACK (-2) 123 #define TR_AUDIO_STREAMPLAY_NOFREESTREAM (-1) 124 #define TR_AUDIO_STREAMPLAY_IGNORED 0 125 #define TR_AUDIO_STREAMPLAY_PROCESSED 1 126 127 // Audio stream type defines stream behaviour. While background track 128 // loops forever until interrupted by other background track, one-shot 129 // and chat tracks doesn't interrupt them, playing in parallel instead. 130 // However, all stream types could be interrupted by next pending track 131 // with same type. 132 133 enum TR_AUDIO_STREAM_TYPE 134 { 135 TR_AUDIO_STREAM_TYPE_BACKGROUND, // BGM tracks. 136 TR_AUDIO_STREAM_TYPE_ONESHOT, // One-shot music pieces. 137 TR_AUDIO_STREAM_TYPE_CHAT, // Chat tracks. 138 TR_AUDIO_STREAM_TYPE_LASTINDEX 139 }; 140 141 // Audio settings structure. 142 143 typedef struct audio_settings_s 144 { 145 float music_volume; 146 float sound_volume; 147 uint32_t use_effects : 1; 148 uint32_t listener_is_player : 1; // RESERVED FOR FUTURE USE 149 }audio_settings_t, *audio_settings_p; 150 151 152 extern struct audio_settings_s audio_settings; 153 154 // General audio routines. 155 156 void Audio_InitGlobals(); 157 158 void Audio_CoreInit(); 159 void Audio_CoreDeinit(); 160 void Audio_Init(uint32_t num_Sources = TR_AUDIO_MAX_CHANNELS); 161 void Audio_GenSamples(class VT_Level *tr); 162 void Audio_CacheTrack(int id); 163 int Audio_DeInit(); 164 void Audio_Update(float time); 165 166 // Audio source (samples) routines. 167 int Audio_IsEffectPlaying(int effect_ID, int entity_type = TR_AUDIO_EMITTER_GLOBAL, int entity_ID = 0); 168 169 int Audio_Send(int effect_ID, int entity_type = TR_AUDIO_EMITTER_GLOBAL, int entity_ID = 0); // Send to play effect with given parameters. 170 int Audio_Kill(int effect_ID, int entity_type = TR_AUDIO_EMITTER_GLOBAL, int entity_ID = 0); // If exist, immediately stop and destroy all effects with given parameters. 171 172 // Stream tracks (music / BGM) routines. 173 int Audio_EndStreams(int stream_type = -1); // End ALL streams (with crossfade). 174 int Audio_StopStreams(int stream_type = -1); // Immediately stop ALL streams. 175 int Audio_PauseStreams(int stream_type = -1); // Pause ALL streams (of specified type). 176 int Audio_ResumeStreams(int stream_type = -1); // Resume ALL streams. 177 178 // Generally, you need only this function to trigger any track. 179 int Audio_StreamPlay(const uint32_t track_index, const uint8_t mask = 0); 180 181 182 struct stream_track_s *Audio_GetStreamExternal(); 183 184 #endif // AUDIO_H 185