1 /***************************************************************************** 2 * Copyright (c) 2014-2020 OpenRCT2 developers 3 * 4 * For a complete list of all authors, please refer to contributors.md 5 * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 6 * 7 * OpenRCT2 is licensed under the GNU General Public License version 3. 8 *****************************************************************************/ 9 10 #pragma once 11 12 #include "../common.h" 13 #include "../ride/RideTypes.h" 14 15 #include <vector> 16 17 struct CoordsXYZ; 18 19 namespace OpenRCT2::Audio 20 { 21 constexpr size_t MaxDeviceNameSize = 256; 22 constexpr size_t MaxVehicleSounds = 14; 23 constexpr size_t MaxDefaultMusic = 46; 24 constexpr uint16_t SoundIdNull = 0xFFFF; 25 26 #define AUDIO_PLAY_AT_CENTRE 0x8000 27 28 enum class SoundId : uint8_t; 29 30 struct Sound 31 { 32 SoundId Id; 33 int16_t Volume; 34 int16_t Pan; 35 uint16_t Frequency; 36 void* Channel; 37 }; 38 39 struct VehicleSound 40 { 41 uint16_t id; 42 int16_t volume; 43 Sound TrackSound; 44 Sound OtherSound; 45 }; 46 47 struct VehicleSoundParams 48 { 49 uint16_t id; 50 int16_t pan_x; 51 int16_t pan_y; 52 uint16_t frequency; 53 int16_t volume; 54 uint16_t priority; 55 }; 56 57 enum class SoundId : uint8_t 58 { 59 LiftClassic, 60 TrackFrictionClassicWood, 61 FrictionClassic, 62 Scream1, 63 Click1, 64 Click2, 65 PlaceItem, 66 Scream2, 67 Scream3, 68 Scream4, 69 Scream5, 70 Scream6, 71 LiftFrictionWheels, 72 Purchase, 73 Crash, 74 LayingOutWater, 75 Water1, 76 Water2, 77 TrainWhistle, 78 TrainDeparting, 79 WaterSplash, 80 GoKartEngine, 81 RideLaunch1, 82 RideLaunch2, 83 Cough1, 84 Cough2, 85 Cough3, 86 Cough4, 87 Rain, 88 Thunder1, 89 Thunder2, 90 TrackFrictionTrain, 91 TrackFrictionWater, 92 BalloonPop, 93 MechanicFix, 94 Scream7, 95 ToiletFlush, 96 Click3, 97 Quack, 98 NewsItem, 99 WindowOpen, 100 Laugh1, 101 Laugh2, 102 Laugh3, 103 Applause, 104 HauntedHouseScare, 105 HauntedHouseScream1, 106 HauntedHouseScream2, 107 BlockBrakeClose, 108 BlockBrakeRelease, 109 Error, 110 BrakeRelease, 111 LiftArrow, 112 LiftWood, 113 TrackFrictionWood, 114 LiftWildMouse, 115 LiftBM, 116 TrackFrictionBM, 117 Scream8, 118 Tram, 119 DoorOpen, 120 DoorClose, 121 Portcullis, 122 NoScream = 254, 123 Null = 255 124 }; 125 126 constexpr uint8_t RCT2SoundCount = static_cast<uint32_t>(SoundId::Portcullis) + 1; 127 128 extern bool gGameSoundsOff; 129 extern int32_t gVolumeAdjustZoom; 130 131 extern void* gTitleMusicChannel; 132 extern void* gWeatherSoundChannel; 133 134 extern VehicleSound gVehicleSoundList[MaxVehicleSounds]; 135 136 /** 137 * Returns false when no audio device is available or when audio is turned off, otherwise true. 138 */ 139 bool IsAvailable(); 140 141 /* 142 * Returns the amount of available audio devices. 143 */ 144 int32_t GetDeviceCount(); 145 146 /** 147 * Returns the device name by index. 148 */ 149 const std::string& GetDeviceName(int32_t index); 150 151 /** 152 * Returns the currently used device index, -1 if not available. 153 */ 154 int32_t GetCurrentDeviceIndex(); 155 156 /** 157 * Deregisters the audio device. 158 * rct2: 0x006BAB21 159 */ 160 void Close(); 161 162 /** 163 * Initialises the audio subsystem. 164 */ 165 void Init(); 166 167 /** 168 * Loads the ride sounds and info. 169 * rct2: 0x006BA8E0 170 */ 171 void InitRideSoundsAndInfo(); 172 173 /** 174 * Loads the ride sounds. 175 * rct2: 0x006BA9B5 176 */ 177 void InitRideSounds(int32_t device); 178 179 /** 180 * Temporarily stops playing sounds until audio_unpause_sounds() is called. 181 * rct2: 0x006BABB4 182 */ 183 void Pause(); 184 185 /** 186 * Plays the specified sound. 187 * @param soundId The sound effect to play. 188 * @param volume The volume at which the sound effect should be played. 189 * @param pan The pan at which the sound effect should be played. If set to anything other than AUDIO_PLAY_AT_CENTRE, plays 190 * the sound at a position relative to the centre of the viewport. 191 */ 192 void Play(SoundId soundId, int32_t volume, int32_t pan); 193 194 /** 195 * Plays the specified sound at a virtual location. 196 * @param soundId The sound effect to play. 197 * @param x The x coordinate of the location. 198 * @param y The y coordinate of the location. 199 * @param z The z coordinate of the location. 200 */ 201 void Play3D(SoundId soundId, const CoordsXYZ& loc); 202 203 /** 204 * Populates the gAudioDevices array with the available audio devices. 205 */ 206 void PopulateDevices(); 207 208 /** 209 * Starts playing the title music. 210 * rct2: 0x006BD0F8 211 */ 212 void PlayTitleMusic(); 213 214 /** 215 * Stops the weather sound effect from playing. 216 */ 217 void StopWeatherSound(); 218 219 /** 220 * Stops the title music from playing. 221 * rct2: 0x006BD0BD 222 */ 223 void StopTitleMusic(); 224 225 /** 226 * Stops vehicle sounds from playing. 227 * rct2: 0x006BABDF 228 */ 229 void StopVehicleSounds(); 230 231 /** 232 * Toggles whether all sounds should be played. 233 * rct2: 0x006BAB8A 234 */ 235 void ToggleAllSounds(); 236 237 /** 238 * Resumes playing sounds that had been paused by a call to audio_pause_sounds(). 239 * rct2: 0x006BABD8 240 */ 241 void Resume(); 242 243 void StopAll(); 244 245 } // namespace OpenRCT2::Audio 246