| 161 | } |
| 162 | |
| 163 | static void updateSingleVehicleSound(Vehicles::VehicleBase& base, Vehicles::VehicleSound& sound, EntityId headId) |
| 164 | { |
| 165 | if (sound.drivingSoundId == SoundObjectId::null) |
| 166 | { |
| 167 | if (sound.audioHandle != AudioHandle::null) |
| 168 | { |
| 169 | stopVehicleSound(sound); |
| 170 | } |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | auto* viewport = findBestViewportForEntity(base.position, headId); |
| 175 | if (viewport == nullptr) |
| 176 | { |
| 177 | if (sound.audioHandle != AudioHandle::null) |
| 178 | { |
| 179 | stopVehicleSound(sound); |
| 180 | } |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | auto sid = makeObjectSoundId(sound.drivingSoundId); |
| 185 | auto attribs = getVehicleAudioAttributes(base, sound, *viewport); |
| 186 | |
| 187 | if (sound.audioHandle == AudioHandle::null) |
| 188 | { |
| 189 | attribs.loop = shouldSoundLoop(sid); |
| 190 | auto buffer = getSoundBuffer(sid); |
| 191 | if (buffer) |
| 192 | { |
| 193 | sound.activeSoundId = sound.drivingSoundId; |
| 194 | sound.audioHandle = create(*buffer, ChannelId::vehicles, attribs); |
| 195 | setReverb(sound.audioHandle, isUnderground(base.position) ? kTunnelReverb : kNoReverb); |
| 196 | Audio::play(sound.audioHandle); |
| 197 | } |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | if (sound.drivingSoundId != sound.activeSoundId) |
| 202 | { |
| 203 | stopVehicleSound(sound); |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | setVolume(sound.audioHandle, attribs.volume); |
| 208 | setPan(sound.audioHandle, attribs.pan); |
| 209 | setPitch(sound.audioHandle, attribs.frequency); |
| 210 | setReverb(sound.audioHandle, isUnderground(base.position) ? kTunnelReverb : kNoReverb); |
| 211 | } |
| 212 | |
| 213 | void updateVehicleNoise() |
| 214 | { |
no test coverage detected