siren and horn

This commit is contained in:
Roman Masanin 2020-10-17 00:27:28 +03:00
parent a4fd1a9f39
commit 894a1ae93a
3 changed files with 120 additions and 101 deletions

View File

@ -1981,49 +1981,62 @@ cAudioManager::GetVehicleNonDriveWheelSkidValue(uint8 wheel, CAutomobile *automo
return Max(relativeVelChange, Min(1.0f, Abs(automobile->m_vecTurnSpeed.z) * 20.0f)); return Max(relativeVelChange, Min(1.0f, Abs(automobile->m_vecTurnSpeed.z) * 20.0f));
} }
void bool
cAudioManager::ProcessVehicleHorn(cVehicleParams *params) cAudioManager::ProcessVehicleHorn(cVehicleParams* params)
{ {
const float SOUND_INTENSITY = 40.0f; const float SOUND_INTENSITY = 40.0f;
CAutomobile *automobile; CVehicle *veh;
uint8 volume;
if (params->m_fDistance < SQR(SOUND_INTENSITY)) { if (params->m_fDistance >= SQR(SOUND_INTENSITY))
automobile = (CAutomobile *)params->m_pVehicle; return false;
if ((!automobile->m_bSirenOrAlarm || !UsesSirenSwitching(params->m_nIndex)) && automobile->GetModelIndex() != MI_MRWHOOP) {
if (automobile->m_nCarHornTimer) {
if (params->m_pVehicle->GetStatus() != STATUS_PLAYER) {
automobile->m_nCarHornTimer = Min(44, automobile->m_nCarHornTimer);
if (automobile->m_nCarHornTimer == 44)
automobile->m_nCarHornPattern = (m_FrameCounter + m_sQueueSample.m_nEntityIndex) & 7;
if (!hornPatternsArray[automobile->m_nCarHornPattern][44 - automobile->m_nCarHornTimer])
return;
}
CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); veh = params->m_pVehicle;
m_sQueueSample.m_nVolume = ComputeVolume(80, SOUND_INTENSITY, m_sQueueSample.m_fDistance); if (veh->m_bSirenOrAlarm && UsesSirenSwitching(params))
if (m_sQueueSample.m_nVolume != 0) { return true;
m_sQueueSample.m_nCounter = 4;
m_sQueueSample.m_nSampleIndex = aVehicleSettings[params->m_nIndex].m_nHornSample; if (veh->m_modelIndex == MI_MRWHOOP)
m_sQueueSample.m_nBankIndex = SFX_BANK_0; return true;
m_sQueueSample.m_bIs2D = false;
m_sQueueSample.m_nReleasingVolumeModificator = 2; veh->m_nAlarmState;
m_sQueueSample.m_nFrequency = aVehicleSettings[params->m_nIndex].m_nHornFrequency; if (veh->IsAlarmOn())
m_sQueueSample.m_nLoopCount = 0; return true;
m_sQueueSample.m_nEmittingVolume = 80;
m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); if (veh->m_nCarHornTimer != 0) {
m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); if (veh->GetStatus() != STATUS_PLAYER) {
m_sQueueSample.m_fSpeedMultiplier = 5.0f; veh->m_nCarHornTimer = Min(44, veh->m_nCarHornTimer);
m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; if (veh->m_nCarHornTimer == 44)
m_sQueueSample.m_bReleasingSoundFlag = false; veh->m_nCarHornPattern = (m_FrameCounter + m_sQueueSample.m_nEntityIndex) & 7;
m_sQueueSample.m_nReleasingVolumeDivider = 3;
m_sQueueSample.m_bReverbFlag = true; if (!hornPatternsArray[veh->m_nCarHornPattern][44 - veh->m_nCarHornTimer])
m_sQueueSample.m_bRequireReflection = false; return true;
AddSampleToRequestedQueue(); }
}
} CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance);
volume = veh->bIsDrowning ? 20 : 80;
m_sQueueSample.m_nVolume = ComputeVolume(volume, SOUND_INTENSITY, m_sQueueSample.m_fDistance);
if (m_sQueueSample.m_nVolume != 0) {
m_sQueueSample.m_nCounter = 4;
m_sQueueSample.m_nSampleIndex = aVehicleSettings[params->m_nIndex].m_nHornSample;
m_sQueueSample.m_nBankIndex = SFX_BANK_0;
m_sQueueSample.m_bIs2D = false;
m_sQueueSample.m_nReleasingVolumeModificator = 2;
m_sQueueSample.m_nFrequency = aVehicleSettings[params->m_nIndex].m_nHornFrequency;
m_sQueueSample.m_nLoopCount = 0;
m_sQueueSample.m_nEmittingVolume = 80; //mb bug?
m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex);
m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex);
m_sQueueSample.m_fSpeedMultiplier = 5.0f;
m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY;
m_sQueueSample.m_bReleasingSoundFlag = false;
m_sQueueSample.m_nReleasingVolumeDivider = 4;
m_sQueueSample.m_bReverbFlag = true;
m_sQueueSample.m_bRequireReflection = false;
AddSampleToRequestedQueue();
} }
} }
return true;
} }
bool bool
@ -2037,68 +2050,74 @@ cAudioManager::UsesSirenSwitching(cVehicleParams *params) const
{ {
if (params->m_nIndex == FIRETRUK || params->m_nIndex == MRWHOOP) if (params->m_nIndex == FIRETRUK || params->m_nIndex == MRWHOOP)
return false; return false;
return params->m_pVehicle->UsesSiren(); return UsesSiren(params);
} }
bool bool
cAudioManager::ProcessVehicleSirenOrAlarm(cVehicleParams *params) cAudioManager::ProcessVehicleSirenOrAlarm(cVehicleParams* params)
{ {
const float SOUND_INTENSITY = 110.0f; const float SOUND_INTENSITY = 110.0f;
if (params->m_fDistance < SQR(SOUND_INTENSITY)) { CVehicle* veh;
CVehicle *veh = params->m_pVehicle; uint8 volume;
if (veh->m_bSirenOrAlarm == false && !veh->IsAlarmOn())
if (params->m_fDistance >= SQR(SOUND_INTENSITY))
return false;
veh = params->m_pVehicle;
if (!veh->m_bSirenOrAlarm && !veh->IsAlarmOn())
return true;
if (veh->IsAlarmOn()) {
if (CTimer::GetTimeInMilliseconds() > veh->m_nCarHornTimer)
veh->m_nCarHornTimer = CTimer::GetTimeInMilliseconds() + 750;
if (veh->m_nCarHornTimer < CTimer::GetTimeInMilliseconds() + 375)
return true; return true;
}
if (veh->IsAlarmOn()) { CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance);
if (CTimer::GetTimeInMilliseconds() > veh->m_bRainAudioCounter) volume = veh->bIsDrowning ? 20 : 80;
veh->m_bRainAudioCounter = CTimer::GetTimeInMilliseconds() + 750; m_sQueueSample.m_nVolume = ComputeVolume(volume, SOUND_INTENSITY, m_sQueueSample.m_fDistance);
if (m_sQueueSample.m_nVolume != 0) {
if (veh->m_bRainAudioCounter < CTimer::GetTimeInMilliseconds() + 375) m_sQueueSample.m_nCounter = 5;
if (UsesSiren(params)) {
if (params->m_pVehicle->GetStatus() == STATUS_ABANDONED)
return true; return true;
} if (veh->m_nCarHornTimer != 0 && params->m_nIndex != FIRETRUK && params->m_nIndex != MRWHOOP) {
m_sQueueSample.m_nSampleIndex = SFX_SIREN_FAST;
CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); if (params->m_nIndex == FBIRANCH)
m_sQueueSample.m_nVolume = ComputeVolume(veh->bIsDrowning ? 20 : 80, SOUND_INTENSITY, m_sQueueSample.m_fDistance); m_sQueueSample.m_nFrequency = 12668;
if (m_sQueueSample.m_nVolume != 0) { else
m_sQueueSample.m_nCounter = 5; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_SIREN_FAST);
if (UsesSiren(params->m_nIndex)) { m_sQueueSample.m_nCounter = 60;
if (params->m_pVehicle->GetStatus() == STATUS_ABANDONED) } else if (params->m_nIndex == VICECHEE) {
return true; m_sQueueSample.m_nSampleIndex = SFX_POLICE_SIREN_SLOW;
if (veh->m_nCarHornTimer && params->m_nIndex != FIRETRUK) { m_sQueueSample.m_nFrequency = 11440;
m_sQueueSample.m_nSampleIndex = SFX_SIREN_FAST;
if (params->m_nIndex == FBICAR)
m_sQueueSample.m_nFrequency = 16113;
else
m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_SIREN_FAST);
m_sQueueSample.m_nCounter = 60;
} else {
m_sQueueSample.m_nSampleIndex = aVehicleSettings[params->m_nIndex].m_nSirenOrAlarmSample;
m_sQueueSample.m_nFrequency = aVehicleSettings[params->m_nIndex].m_nSirenOrAlarmFrequency;
}
} else { } else {
m_sQueueSample.m_nSampleIndex = aVehicleSettings[params->m_nIndex].m_nSirenOrAlarmSample; m_sQueueSample.m_nSampleIndex = aVehicleSettings[params->m_nIndex].m_nSirenOrAlarmSample;
m_sQueueSample.m_nFrequency = aVehicleSettings[params->m_nIndex].m_nSirenOrAlarmFrequency; m_sQueueSample.m_nFrequency = aVehicleSettings[params->m_nIndex].m_nSirenOrAlarmFrequency;
} }
m_sQueueSample.m_nBankIndex = SFX_BANK_0; } else {
m_sQueueSample.m_bIs2D = false; m_sQueueSample.m_nSampleIndex = aVehicleSettings[params->m_nIndex].m_nHornSample;
m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = aVehicleSettings[params->m_nIndex].m_nHornFrequency;
m_sQueueSample.m_nLoopCount = 0; }
m_sQueueSample.m_nEmittingVolume = 80; m_sQueueSample.m_nBankIndex = SFX_BANK_0;
m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_bIs2D = false;
m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nReleasingVolumeModificator = 1;
m_sQueueSample.m_fSpeedMultiplier = 7.0f; m_sQueueSample.m_nLoopCount = 0;
m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; m_sQueueSample.m_nEmittingVolume = volume;
m_sQueueSample.m_bReleasingSoundFlag = false; m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex);
m_sQueueSample.m_nReleasingVolumeDivider = 5; m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex);
m_sQueueSample.m_bReverbFlag = true; m_sQueueSample.m_fSpeedMultiplier = 7.0f;
m_sQueueSample.m_bRequireReflection = false; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY;
AddSampleToRequestedQueue(); m_sQueueSample.m_bReleasingSoundFlag = false;
return true; m_sQueueSample.m_nReleasingVolumeDivider = 5;
} else m_sQueueSample.m_bReverbFlag = true;
return true; m_sQueueSample.m_bRequireReflection = false;
} else AddSampleToRequestedQueue();
return false; }
return true;
} }
bool bool
@ -2194,10 +2213,11 @@ cAudioManager::ProcessVehicleDoors(cVehicleParams *params)
bool bool
cAudioManager::ProcessAirBrakes(cVehicleParams *params) cAudioManager::ProcessAirBrakes(cVehicleParams *params)
{ {
const float SOUND_INTENSITY = 30.0f;
CAutomobile *automobile; CAutomobile *automobile;
uint8 rand; uint8 volume;
if (params->m_fDistance > SQR(30)) if (params->m_fDistance > SQR(SOUND_INTENSITY))
return false; return false;
automobile = (CAutomobile *)params->m_pVehicle; automobile = (CAutomobile *)params->m_pVehicle;
if (!automobile->bEngineOn) if (!automobile->bEngineOn)
@ -2208,8 +2228,8 @@ cAudioManager::ProcessAirBrakes(cVehicleParams *params)
return true; return true;
CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance); CalculateDistance(params->m_bDistanceCalculated, params->m_fDistance);
rand = m_anRandomTable[0] % 10 + 70; volume = m_anRandomTable[0] % 10 + 70;
m_sQueueSample.m_nVolume = ComputeVolume(rand, 30.0f, m_sQueueSample.m_fDistance); m_sQueueSample.m_nVolume = ComputeVolume(volume, SOUND_INTENSITY, m_sQueueSample.m_fDistance);
if (m_sQueueSample.m_nVolume != 0) { if (m_sQueueSample.m_nVolume != 0) {
m_sQueueSample.m_nCounter = 13; m_sQueueSample.m_nCounter = 13;
m_sQueueSample.m_nSampleIndex = SFX_AIR_BRAKES; m_sQueueSample.m_nSampleIndex = SFX_AIR_BRAKES;
@ -2219,11 +2239,11 @@ cAudioManager::ProcessAirBrakes(cVehicleParams *params)
m_sQueueSample.m_bIs2D = false; m_sQueueSample.m_bIs2D = false;
m_sQueueSample.m_nReleasingVolumeModificator = 10; m_sQueueSample.m_nReleasingVolumeModificator = 10;
m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.m_nLoopCount = 1;
m_sQueueSample.m_nEmittingVolume = rand; m_sQueueSample.m_nEmittingVolume = volume;
m_sQueueSample.m_nLoopStart = 0; m_sQueueSample.m_nLoopStart = 0;
m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.m_nLoopEnd = -1;
m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSpeedMultiplier = 0.0f;
m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY;
m_sQueueSample.m_bReleasingSoundFlag = true; m_sQueueSample.m_bReleasingSoundFlag = true;
m_sQueueSample.m_bReverbFlag = true; m_sQueueSample.m_bReverbFlag = true;
m_sQueueSample.m_bRequireReflection = false; m_sQueueSample.m_bRequireReflection = false;

View File

@ -298,7 +298,7 @@ public:
void PlayLoadedMissionAudio(uint8 slot); // done void PlayLoadedMissionAudio(uint8 slot); // done
void PlayOneShot(int32 index, int16 sound, float vol); // done void PlayOneShot(int32 index, int16 sound, float vol); // done
void PlaySuspectLastSeen(float x, float y, float z); // void PlaySuspectLastSeen(float x, float y, float z); // done
void PlayerJustGotInCar() const; // done void PlayerJustGotInCar() const; // done
void PlayerJustLeftCar() const; // done void PlayerJustLeftCar() const; // done
void PostInitialiseGameSpecificSetup(); // done void PostInitialiseGameSpecificSetup(); // done
@ -308,7 +308,7 @@ public:
void PreTerminateGameSpecificShutdown(); // done void PreTerminateGameSpecificShutdown(); // done
/// processX - main logic of adding new sounds /// processX - main logic of adding new sounds
void ProcessActiveQueues(); // done void ProcessActiveQueues(); // done
bool ProcessAirBrakes(cVehicleParams *params); bool ProcessAirBrakes(cVehicleParams *params); // done
bool ProcessBoatEngine(cVehicleParams *params); bool ProcessBoatEngine(cVehicleParams *params);
bool ProcessBoatMovingOverWater(cVehicleParams *params); bool ProcessBoatMovingOverWater(cVehicleParams *params);
#ifdef GTA_BRIDGE #ifdef GTA_BRIDGE
@ -359,11 +359,11 @@ public:
bool ProcessVehicleDoors(cVehicleParams *params); // done bool ProcessVehicleDoors(cVehicleParams *params); // done
void ProcessVehicleEngine(cVehicleParams *params); // done void ProcessVehicleEngine(cVehicleParams *params); // done
void UpdateGasPedalAudio(CVehicle* veh, int vehType); // done void UpdateGasPedalAudio(CVehicle* veh, int vehType); // done
void ProcessVehicleHorn(cVehicleParams *params); // bool ProcessVehicleHorn(cVehicleParams *params); // done
void ProcessVehicleOneShots(cVehicleParams *params); // void ProcessVehicleOneShots(cVehicleParams *params); //
bool ProcessVehicleReverseWarning(cVehicleParams *params); // bool ProcessVehicleReverseWarning(cVehicleParams *params); //
bool ProcessVehicleRoadNoise(cVehicleParams *params); // bool ProcessVehicleRoadNoise(cVehicleParams *params); //
bool ProcessVehicleSirenOrAlarm(cVehicleParams *params); // bool ProcessVehicleSirenOrAlarm(cVehicleParams *params); // done
bool ProcessVehicleSkidding(cVehicleParams *params); // bool ProcessVehicleSkidding(cVehicleParams *params); //
void ProcessWaterCannon(int32); // void ProcessWaterCannon(int32); //
void ProcessWeather(int32 id); // done void ProcessWeather(int32 id); // done

View File

@ -671,7 +671,6 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z)
float halfY; float halfY;
float quarterX; float quarterX;
float quarterY; float quarterY;
int32 sample;
bool processed = false; bool processed = false;
CVector vec = CVector(x, y, z); CVector vec = CVector(x, y, z);
@ -683,8 +682,7 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z)
zone = CTheZones::GetAudioZone(audioZone); zone = CTheZones::GetAudioZone(audioZone);
for (int i = 0; i < NUMAUDIOZONES; i++) { for (int i = 0; i < NUMAUDIOZONES; i++) {
if (strcmp(zone->name, ZoneSfx[i].m_aName) == 0) { if (strcmp(zone->name, ZoneSfx[i].m_aName) == 0) {
sample = ZoneSfx[i].m_nSampleIndex; m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_MESSAGE_NOISE_1);
m_sPoliceRadioQueue.Add(m_anRandomTable[4] % 3 + SFX_POLICE_RADIO_MESSAGE_NOISE_1);
m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_SUSPECT); m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_SUSPECT);
m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_LAST_SEEN); m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_LAST_SEEN);
m_sPoliceRadioQueue.Add(SFX_IN); m_sPoliceRadioQueue.Add(SFX_IN);
@ -709,9 +707,10 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z)
m_sPoliceRadioQueue.Add(SFX_WEST); m_sPoliceRadioQueue.Add(SFX_WEST);
else if (!processed) else if (!processed)
m_sPoliceRadioQueue.Add(SFX_CENTRAL); m_sPoliceRadioQueue.Add(SFX_CENTRAL);
m_sPoliceRadioQueue.Add(sample);
m_sPoliceRadioQueue.Add(m_anRandomTable[2] % 3 + SFX_POLICE_RADIO_MESSAGE_NOISE_1); m_sPoliceRadioQueue.Add(ZoneSfx[i].m_nSampleIndex);
m_sPoliceRadioQueue.Add(TOTAL_AUDIO_SAMPLES); m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_MESSAGE_NOISE_1);
m_sPoliceRadioQueue.Add(NO_SAMPLE);
gSpecialSuspectLastSeenReport = true; gSpecialSuspectLastSeenReport = true;
break; break;
} }