1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-23 23:10:01 +00:00
re3/src/audio/AudioManager.cpp

1087 lines
33 KiB
C++
Raw Normal View History

2020-04-15 12:05:24 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2019-06-27 16:45:16 +00:00
#include "AudioManager.h"
2020-05-02 13:27:40 +00:00
#include "audio_enums.h"
2019-07-02 18:35:47 +00:00
#include "AudioScriptObject.h"
2019-07-02 18:35:47 +00:00
#include "MusicManager.h"
#include "Timer.h"
#include "DMAudio.h"
2019-08-02 15:43:40 +00:00
#include "sampman.h"
#include "Camera.h"
#include "World.h"
2021-01-04 22:31:31 +00:00
#include "ZoneCull.h"
2019-07-02 18:35:47 +00:00
2020-04-14 14:13:38 +00:00
cAudioManager AudioManager;
2019-10-26 14:47:57 +00:00
2020-03-21 13:51:30 +00:00
const int channels = ARRAY_SIZE(cAudioManager::m_asActiveSamples);
const int policeChannel = channels + 1;
const int allChannels = channels + 2;
2021-01-03 14:43:58 +00:00
#define SPEED_OF_SOUND 343.f
#define TIME_SPENT 40
2020-04-13 01:19:20 +00:00
cAudioManager::cAudioManager()
{
2020-04-14 14:13:38 +00:00
m_bIsInitialised = false;
2020-12-22 13:53:45 +00:00
m_bReverb = true;
field_6 = 0;
2021-01-03 14:43:58 +00:00
m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT;
m_nTimeSpent = TIME_SPENT;
m_nActiveSamples = NUM_SOUNDS_SAMPLES_SLOTS;
2020-05-02 14:10:51 +00:00
m_nActiveSampleQueue = 1;
2020-04-13 01:19:20 +00:00
ClearRequestedQueue();
2020-05-02 14:10:51 +00:00
m_nActiveSampleQueue = 0;
2020-04-13 01:19:20 +00:00
ClearRequestedQueue();
ClearActiveSamples();
GenerateIntegerRandomNumberTable();
field_4 = 0;
2020-05-16 18:00:27 +00:00
m_bDynamicAcousticModelingStatus = true;
2020-04-13 01:19:20 +00:00
2020-05-02 13:27:40 +00:00
for (int i = 0; i < NUM_AUDIOENTITIES; i++) {
2020-04-13 01:19:20 +00:00
m_asAudioEntities[i].m_bIsUsed = false;
m_anAudioEntityIndices[i] = NUM_AUDIOENTITIES;
}
m_nAudioEntitiesTotal = 0;
m_FrameCounter = 0;
2020-05-23 20:25:14 +00:00
m_bFifthFrameFlag = false;
m_bTimerJustReset = false;
2020-04-13 01:19:20 +00:00
m_nTimer = 0;
}
cAudioManager::~cAudioManager()
{
2020-05-02 13:27:40 +00:00
if (m_bIsInitialised)
Terminate();
2020-04-13 01:19:20 +00:00
}
2019-07-08 19:44:32 +00:00
void
cAudioManager::Initialise()
2019-07-08 19:44:32 +00:00
{
if (!m_bIsInitialised) {
PreInitialiseGameSpecificSetup();
m_bIsInitialised = SampleManager.Initialise();
if (m_bIsInitialised) {
m_nActiveSamples = SampleManager.GetMaximumSupportedChannels();
if (m_nActiveSamples <= 1) {
Terminate();
} else {
--m_nActiveSamples;
PostInitialiseGameSpecificSetup();
InitialisePoliceRadioZones();
InitialisePoliceRadio();
MusicManager.Initialise();
}
2019-07-08 19:44:32 +00:00
}
}
}
void
cAudioManager::Terminate()
2019-07-08 19:44:32 +00:00
{
if (m_bIsInitialised) {
MusicManager.Terminate();
for (uint32 i = 0; i < NUM_AUDIOENTITIES; i++) {
m_asAudioEntities[i].m_bIsUsed = false;
m_anAudioEntityIndices[i] = ARRAY_SIZE(m_anAudioEntityIndices);
2019-07-08 19:44:32 +00:00
}
m_nAudioEntitiesTotal = 0;
m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal = 0;
PreTerminateGameSpecificShutdown();
2019-07-08 19:44:32 +00:00
for (uint32 i = 0; i < MAX_SFX_BANKS; i++) {
if (SampleManager.IsSampleBankLoaded(i))
SampleManager.UnloadSampleBank(i);
2019-07-08 19:44:32 +00:00
}
SampleManager.Terminate();
m_bIsInitialised = false;
PostTerminateGameSpecificShutdown();
2019-07-08 19:44:32 +00:00
}
}
2019-07-16 15:03:37 +00:00
2019-08-29 22:44:57 +00:00
void
cAudioManager::Service()
2019-07-08 19:44:32 +00:00
{
GenerateIntegerRandomNumberTable();
if (m_bTimerJustReset) {
ResetAudioLogicTimers(m_nTimer);
MusicManager.ResetTimers(m_nTimer);
m_bTimerJustReset = false;
}
if (m_bIsInitialised) {
m_nPreviousUserPause = m_nUserPause;
m_nUserPause = CTimer::GetIsUserPaused();
UpdateReflections();
ServiceSoundEffects();
MusicManager.Service();
}
}
2019-10-27 13:15:39 +00:00
int32
cAudioManager::CreateEntity(eAudioType type, void *entity)
{
if (!m_bIsInitialised)
return AEHANDLE_ERROR_NOAUDIOSYS;
if (!entity)
return AEHANDLE_ERROR_NOENTITY;
if (type >= TOTAL_AUDIO_TYPES)
return AEHANDLE_ERROR_BADAUDIOTYPE;
for (uint32 i = 0; i < ARRAY_SIZE(m_asAudioEntities); i++) {
if (!m_asAudioEntities[i].m_bIsUsed) {
m_asAudioEntities[i].m_bIsUsed = true;
m_asAudioEntities[i].m_bStatus = false;
m_asAudioEntities[i].m_nType = type;
m_asAudioEntities[i].m_pEntity = entity;
m_asAudioEntities[i].m_awAudioEvent[0] = SOUND_NO_SOUND;
m_asAudioEntities[i].m_awAudioEvent[1] = SOUND_NO_SOUND;
m_asAudioEntities[i].m_awAudioEvent[2] = SOUND_NO_SOUND;
m_asAudioEntities[i].m_awAudioEvent[3] = SOUND_NO_SOUND;
m_asAudioEntities[i].m_AudioEvents = 0;
m_anAudioEntityIndices[m_nAudioEntitiesTotal++] = i;
return i;
2019-08-29 22:44:57 +00:00
}
}
return AEHANDLE_ERROR_NOFREESLOT;
2019-07-08 19:44:32 +00:00
}
2019-07-07 14:32:28 +00:00
void
cAudioManager::DestroyEntity(int32 id)
2019-07-07 14:32:28 +00:00
{
if (m_bIsInitialised && id >= 0 && id < NUM_AUDIOENTITIES && m_asAudioEntities[id].m_bIsUsed) {
m_asAudioEntities[id].m_bIsUsed = false;
for (int32 i = 0; i < m_nAudioEntitiesTotal; ++i) {
if (id == m_anAudioEntityIndices[i]) {
if (i < NUM_AUDIOENTITIES - 1)
memmove(&m_anAudioEntityIndices[i], &m_anAudioEntityIndices[i + 1], NUM_AUDIOENTITY_EVENTS * (m_nAudioEntitiesTotal - (i + 1)));
m_anAudioEntityIndices[--m_nAudioEntitiesTotal] = NUM_AUDIOENTITIES;
2020-04-13 01:19:20 +00:00
return;
}
2019-07-07 14:32:28 +00:00
}
}
}
2019-07-08 19:44:32 +00:00
void
cAudioManager::SetEntityStatus(int32 id, uint8 status)
2019-07-08 19:44:32 +00:00
{
if (m_bIsInitialised && id >= 0 && id < NUM_AUDIOENTITIES && m_asAudioEntities[id].m_bIsUsed)
m_asAudioEntities[id].m_bStatus = status;
2019-07-08 19:44:32 +00:00
}
void
cAudioManager::PlayOneShot(int32 index, uint16 sound, float vol)
2019-07-08 19:44:32 +00:00
{
2020-07-18 11:15:06 +00:00
static const uint8 OneShotPriority[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 2, 5, 5, 3, 5, 2, 2, 1, 1, 3, 1, 3, 3, 1, 1, 1, 1, 4, 4, 4, 3, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 6, 1, 1, 1, 1, 1, 1, 3, 4, 2, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3, 1, 1, 1, 9, 0, 0, 0, 1, 2, 2, 0, 0, 2, 3, 3, 3, 5, 1, 1,
1, 1, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 7, 1, 4, 3, 4, 2, 2, 2, 3, 1, 2, 1, 3, 5, 3, 4, 6, 4, 6, 3, 0, 0, 0, 0, 0,
0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 3, 1, 1, 2, 1, 1, 0, 0, 0, 0, 0, 3, 3, 1, 0 };
2019-08-29 22:44:57 +00:00
2020-05-02 13:27:40 +00:00
if (m_bIsInitialised) {
if (index >= 0 && index < NUM_AUDIOENTITIES) {
tAudioEntity &entity = m_asAudioEntities[index];
if (entity.m_bIsUsed) {
if (sound < SOUND_TOTAL_SOUNDS) {
if (entity.m_nType == AUDIOTYPE_SCRIPTOBJECT) {
if (m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal < ARRAY_SIZE(m_sAudioScriptObjectManager.m_anScriptObjectEntityIndices)) {
entity.m_awAudioEvent[0] = sound;
entity.m_AudioEvents = 1;
m_sAudioScriptObjectManager.m_anScriptObjectEntityIndices[m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal++] = index;
}
} else {
int32 i = 0;
while (true) {
if (i >= entity.m_AudioEvents) {
if (entity.m_AudioEvents < ARRAY_SIZE(entity.m_awAudioEvent)) {
entity.m_awAudioEvent[i] = sound;
entity.m_afVolume[i] = vol;
++entity.m_AudioEvents;
}
return;
}
if (OneShotPriority[entity.m_awAudioEvent[i]] > OneShotPriority[sound])
break;
++i;
}
if (i < NUM_AUDIOENTITY_EVENTS - 1) {
memmove(&entity.m_awAudioEvent[i + 1], &entity.m_awAudioEvent[i], (NUM_AUDIOENTITY_EVENTS - 1 - i) * NUM_AUDIOENTITY_EVENTS / 2);
memmove(&entity.m_afVolume[i + 1], &entity.m_afVolume[i], (NUM_AUDIOENTITY_EVENTS - 1 - i) * NUM_AUDIOENTITY_EVENTS);
}
entity.m_awAudioEvent[i] = sound;
entity.m_afVolume[i] = vol;
if (entity.m_AudioEvents < ARRAY_SIZE(entity.m_awAudioEvent))
++entity.m_AudioEvents;
}
}
}
}
2019-07-08 19:44:32 +00:00
}
}
2019-07-07 14:32:28 +00:00
void
cAudioManager::SetMP3BoostVolume(uint8 volume) const
{
SampleManager.SetMP3BoostVolume(volume);
}
2019-07-08 19:44:32 +00:00
void
cAudioManager::SetEffectsMasterVolume(uint8 volume) const
2019-07-08 19:44:32 +00:00
{
SampleManager.SetEffectsMasterVolume(volume);
2019-07-08 19:44:32 +00:00
}
void
cAudioManager::SetMusicMasterVolume(uint8 volume) const
2019-07-08 19:44:32 +00:00
{
SampleManager.SetMusicMasterVolume(volume);
2019-07-08 19:44:32 +00:00
}
void
cAudioManager::SetEffectsFadeVol(uint8 volume) const
2019-07-08 19:44:32 +00:00
{
SampleManager.SetEffectsFadeVolume(volume);
2019-07-07 14:32:28 +00:00
}
2020-06-29 06:37:53 +00:00
void
cAudioManager::SetMonoMode(uint8 mono)
2019-07-08 19:44:32 +00:00
{
2020-06-29 06:37:53 +00:00
SampleManager.SetMonoMode(mono);
2019-07-07 14:32:28 +00:00
}
void
cAudioManager::SetMusicFadeVol(uint8 volume) const
2019-07-07 14:32:28 +00:00
{
SampleManager.SetMusicFadeVolume(volume);
2019-07-07 14:32:28 +00:00
}
void
cAudioManager::ResetTimers(uint32 time)
2019-07-08 19:44:32 +00:00
{
if (m_bIsInitialised) {
m_bTimerJustReset = true;
m_nTimer = time;
ClearRequestedQueue();
if (m_nActiveSampleQueue) {
m_nActiveSampleQueue = 0;
ClearRequestedQueue();
m_nActiveSampleQueue = 1;
} else {
m_nActiveSampleQueue = 1;
ClearRequestedQueue();
m_nActiveSampleQueue = 0;
2019-07-08 19:44:32 +00:00
}
ClearActiveSamples();
2020-06-08 07:34:31 +00:00
ClearMissionAudio(0);
ClearMissionAudio(1);
SampleManager.StopChannel(policeChannel);
SampleManager.SetEffectsFadeVolume(0);
SampleManager.SetMusicFadeVolume(0);
MusicManager.ResetMusicAfterReload();
m_bIsPlayerShutUp = false;
#ifdef AUDIO_OAL
SampleManager.Service();
#endif
2019-07-08 19:44:32 +00:00
}
}
void
cAudioManager::DestroyAllGameCreatedEntities()
{
cAudioScriptObject *entity;
2020-05-02 13:27:40 +00:00
if (m_bIsInitialised) {
for (uint32 i = 0; i < ARRAY_SIZE(m_asAudioEntities); i++) {
if (m_asAudioEntities[i].m_bIsUsed) {
switch (m_asAudioEntities[i].m_nType) {
2019-07-08 19:44:32 +00:00
case AUDIOTYPE_PHYSICAL:
case AUDIOTYPE_EXPLOSION:
case AUDIOTYPE_WEATHER:
2020-06-08 11:29:55 +00:00
//case AUDIOTYPE_CRANE:
2019-07-08 19:44:32 +00:00
case AUDIOTYPE_GARAGE:
2020-05-02 13:27:40 +00:00
case AUDIOTYPE_FIREHYDRANT:
DestroyEntity(i);
break;
2019-08-15 01:43:00 +00:00
case AUDIOTYPE_SCRIPTOBJECT:
2020-05-02 13:27:40 +00:00
entity = (cAudioScriptObject *)m_asAudioEntities[i].m_pEntity;
if (entity) {
2019-10-12 20:21:44 +00:00
delete entity;
2019-09-24 11:33:16 +00:00
m_asAudioEntities[i].m_pEntity = nil;
}
2019-07-16 15:03:37 +00:00
DestroyEntity(i);
2019-07-08 19:44:32 +00:00
break;
2020-05-02 13:27:40 +00:00
default:
break;
2019-07-08 19:44:32 +00:00
}
}
}
2020-04-14 14:13:38 +00:00
m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal = 0;
2019-07-08 19:44:32 +00:00
}
}
uint8
cAudioManager::GetNum3DProvidersAvailable() const
2019-07-08 19:44:32 +00:00
{
if (m_bIsInitialised)
return SampleManager.GetNum3DProvidersAvailable();
return 0;
2019-07-08 19:44:32 +00:00
}
char *
cAudioManager::Get3DProviderName(uint8 id) const
2019-08-27 18:50:59 +00:00
{
if (!m_bIsInitialised)
return nil;
2020-10-11 02:25:15 +00:00
#ifdef AUDIO_OAL
id = clamp(id, 0, SampleManager.GetNum3DProvidersAvailable() - 1);
#else
// We don't want that either since it will crash the game, but skipping for now
if (id >= SampleManager.GetNum3DProvidersAvailable())
return nil;
2020-10-11 02:25:15 +00:00
#endif
return SampleManager.Get3DProviderName(id);
2019-08-27 18:50:59 +00:00
}
int8
cAudioManager::GetCurrent3DProviderIndex() const
2019-07-08 19:44:32 +00:00
{
if (m_bIsInitialised)
return SampleManager.GetCurrent3DProviderIndex();
2019-07-08 19:44:32 +00:00
return -1;
2019-07-05 19:15:32 +00:00
}
int8
cAudioManager::AutoDetect3DProviders() const
{
if (m_bIsInitialised)
return SampleManager.AutoDetect3DProviders();
return -1;
}
int8
cAudioManager::SetCurrent3DProvider(uint8 which)
2019-07-05 19:15:32 +00:00
{
if (!m_bIsInitialised)
return -1;
for (uint8 i = 0; i < m_nActiveSamples + 1; ++i)
SampleManager.StopChannel(i);
ClearRequestedQueue();
if (m_nActiveSampleQueue == 0)
m_nActiveSampleQueue = 1;
else
m_nActiveSampleQueue = 0;
ClearRequestedQueue();
ClearActiveSamples();
int8 current = SampleManager.SetCurrent3DProvider(which);
if (current > 0) {
m_nActiveSamples = SampleManager.GetMaximumSupportedChannels();
if (m_nActiveSamples > 1)
--m_nActiveSamples;
2019-08-27 18:50:59 +00:00
}
return current;
2019-07-05 19:15:32 +00:00
}
void
cAudioManager::SetSpeakerConfig(int32 conf) const
2019-07-05 19:15:32 +00:00
{
SampleManager.SetSpeakerConfig(conf);
2019-08-27 18:50:59 +00:00
}
2019-07-05 19:15:32 +00:00
bool
cAudioManager::IsMP3RadioChannelAvailable() const
2019-08-27 18:50:59 +00:00
{
if (m_bIsInitialised)
return SampleManager.IsMP3RadioChannelAvailable();
2019-07-05 19:15:32 +00:00
return false;
2019-07-02 18:35:47 +00:00
}
void
cAudioManager::ReleaseDigitalHandle() const
2019-07-02 18:35:47 +00:00
{
if (m_bIsInitialised) {
SampleManager.ReleaseDigitalHandle();
2020-05-02 13:27:40 +00:00
}
2019-07-02 18:35:47 +00:00
}
void
cAudioManager::ReacquireDigitalHandle() const
2019-07-02 18:35:47 +00:00
{
if (m_bIsInitialised) {
SampleManager.ReacquireDigitalHandle();
2019-08-27 18:50:59 +00:00
}
2019-07-02 18:35:47 +00:00
}
void
2020-06-29 06:37:53 +00:00
cAudioManager::SetDynamicAcousticModelingStatus(uint8 status)
2019-07-02 18:35:47 +00:00
{
2020-06-29 06:37:53 +00:00
m_bDynamicAcousticModelingStatus = status!=0;
2019-07-02 18:35:47 +00:00
}
2020-10-02 17:35:16 +00:00
bool
cAudioManager::CheckForAnAudioFileOnCD() const
{
return SampleManager.CheckForAnAudioFileOnCD();
}
2019-06-27 16:45:16 +00:00
uint8
cAudioManager::GetCDAudioDriveLetter() const
2019-06-27 16:45:16 +00:00
{
2020-12-22 13:53:45 +00:00
if(m_bIsInitialised) return SampleManager.GetCDAudioDriveLetter();
return 0;
2019-06-27 16:45:16 +00:00
}
bool
cAudioManager::IsAudioInitialised() const
2019-06-27 16:45:16 +00:00
{
return m_bIsInitialised;
2019-06-27 16:45:16 +00:00
}
void
cAudioManager::ServiceSoundEffects()
2019-06-27 16:45:16 +00:00
{
m_bFifthFrameFlag = (m_FrameCounter++ % 5) == 0;
if (m_nUserPause && !m_nPreviousUserPause) {
for (int32 i = 0; i < allChannels; i++)
SampleManager.StopChannel(i);
2019-06-27 16:45:16 +00:00
ClearRequestedQueue();
if (m_nActiveSampleQueue) {
m_nActiveSampleQueue = 0;
ClearRequestedQueue();
m_nActiveSampleQueue = 1;
} else {
m_nActiveSampleQueue = 1;
ClearRequestedQueue();
m_nActiveSampleQueue = 0;
}
ClearActiveSamples();
2019-06-27 16:45:16 +00:00
}
2020-06-30 16:06:58 +00:00
m_nActiveSampleQueue = m_nActiveSampleQueue == 1 ? 0 : 1;
2020-12-22 13:53:45 +00:00
if(m_bReverb) ProcessReverb();
ProcessSpecial();
ClearRequestedQueue();
InterrogateAudioEntities();
m_sPedComments.Process();
ServicePoliceRadio();
ServiceCollisions();
AddReleasingSounds();
ProcessMissionAudio();
#ifdef GTA_PC
AdjustSamplesVolume();
#endif
ProcessActiveQueues();
#ifdef AUDIO_OAL
SampleManager.Service();
#endif
for (int32 i = 0; i < m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal; ++i) {
cAudioScriptObject *object = (cAudioScriptObject *)m_asAudioEntities[m_sAudioScriptObjectManager.m_anScriptObjectEntityIndices[i]].m_pEntity;
delete object;
m_asAudioEntities[m_sAudioScriptObjectManager.m_anScriptObjectEntityIndices[i]].m_pEntity = nil;
DestroyEntity(m_sAudioScriptObjectManager.m_anScriptObjectEntityIndices[i]);
2019-06-27 16:45:16 +00:00
}
m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal = 0;
2019-06-27 16:45:16 +00:00
}
2019-06-13 19:16:55 +00:00
uint8
cAudioManager::ComputeVolume(uint8 emittingVolume, float soundIntensity, float distance) const
2019-06-13 19:16:55 +00:00
{
float newSoundIntensity;
2020-10-02 01:59:06 +00:00
float newEmittingVolume;
if (soundIntensity <= 0.0f)
return 0;
2020-10-02 01:59:06 +00:00
newSoundIntensity = soundIntensity / 5.0f;
2020-10-02 01:59:06 +00:00
if (newSoundIntensity > distance)
return emittingVolume;
newEmittingVolume = emittingVolume * SQR((soundIntensity - newSoundIntensity - (distance - newSoundIntensity))
/ (soundIntensity - newSoundIntensity));
return Min(127u, newEmittingVolume);
2019-06-27 16:45:16 +00:00
}
void
cAudioManager::TranslateEntity(Const CVector *in, CVector *out) const
2019-06-27 16:45:16 +00:00
{
*out = MultiplyInverse(TheCamera.GetMatrix(), *in);
2019-06-27 16:45:16 +00:00
}
int32
cAudioManager::ComputePan(float dist, CVector *vec)
2019-06-27 16:45:16 +00:00
{
2020-10-02 01:59:06 +00:00
const uint8 PanTable[64] = { 0, 3, 8, 12, 16, 19, 22, 24, 26, 28, 30, 31, 33, 34, 36, 37, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 53,
54, 55, 55, 56, 56, 57, 57, 58, 58, 58, 59, 59, 59, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, 63};
int32 index = Min(63, Abs(int32(vec->x / (dist / 64.f))));
2019-06-13 19:16:55 +00:00
if (vec->x > 0.f)
return Max(20, 63 - PanTable[index]);
return Min(107, PanTable[index] + 63);
2019-06-29 11:44:20 +00:00
}
2020-10-02 00:55:26 +00:00
uint32
cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, float speedMultiplier) const
2019-06-29 11:44:20 +00:00
{
uint32 newFreq = oldFreq;
if (!TheCamera.Get_Just_Switched_Status() && speedMultiplier != 0.0f) {
float dist = position2 - position1;
if (dist != 0.0f) {
float speedOfSource = (dist / m_nTimeSpent) * speedMultiplier;
if (m_fSpeedOfSound > Abs(speedOfSource)) {
2020-10-02 00:55:26 +00:00
speedOfSource = clamp2(speedOfSource, 0.0f, 1.5f);
newFreq = (oldFreq * m_fSpeedOfSound) / (speedOfSource + m_fSpeedOfSound);
}
}
2019-06-29 11:44:20 +00:00
}
return newFreq;
2019-06-29 11:44:20 +00:00
}
int32
cAudioManager::RandomDisplacement(uint32 seed) const
2019-06-29 11:44:20 +00:00
{
int32 value;
2019-06-13 19:16:55 +00:00
2020-05-16 18:00:27 +00:00
static bool bPos = true;
static uint32 Adjustment = 0;
2019-06-29 11:44:20 +00:00
if (!seed)
return 0;
2019-06-25 12:25:39 +00:00
2020-05-16 18:00:27 +00:00
value = m_anRandomTable[(Adjustment + seed) % 5] % seed;
Adjustment += value;
2019-06-29 11:44:20 +00:00
if (value % 2) {
2020-05-16 18:00:27 +00:00
bPos = !bPos;
2019-06-29 11:44:20 +00:00
}
2020-05-16 18:00:27 +00:00
if (!bPos)
value = -value;
return value;
2019-06-29 11:44:20 +00:00
}
void
cAudioManager::InterrogateAudioEntities()
2019-06-29 11:44:20 +00:00
{
for (int32 i = 0; i < m_nAudioEntitiesTotal; i++) {
ProcessEntity(m_anAudioEntityIndices[i]);
m_asAudioEntities[m_anAudioEntityIndices[i]].m_AudioEvents = 0;
2019-06-29 11:44:20 +00:00
}
}
void
cAudioManager::AddSampleToRequestedQueue()
2019-06-29 11:44:20 +00:00
{
int32 calculatedVolume;
uint8 sampleIndex;
bool bReflections;
2019-06-29 11:44:20 +00:00
if (m_sQueueSample.m_nSampleIndex < TOTAL_AUDIO_SAMPLES) {
2020-05-18 17:17:24 +00:00
calculatedVolume = m_sQueueSample.m_nReleasingVolumeModificator * (MAX_VOLUME - m_sQueueSample.m_nVolume);
sampleIndex = m_SampleRequestQueuesStatus[m_nActiveSampleQueue];
if (sampleIndex >= m_nActiveSamples) {
sampleIndex = m_abSampleQueueIndexTable[m_nActiveSampleQueue][m_nActiveSamples - 1];
if (m_asSamples[m_nActiveSampleQueue][sampleIndex].m_nCalculatedVolume <= calculatedVolume)
return;
} else {
++m_SampleRequestQueuesStatus[m_nActiveSampleQueue];
}
m_sQueueSample.m_nCalculatedVolume = calculatedVolume;
m_sQueueSample.m_bLoopEnded = false;
2021-01-04 22:31:31 +00:00
if (m_sQueueSample.m_bIs2D || CCullZones::InRoomForAudio()) {
m_sQueueSample.m_bRequireReflection = false;
m_sQueueSample.m_nLoopsRemaining = 0;
}
if (m_bDynamicAcousticModelingStatus && m_sQueueSample.m_nLoopCount) {
bReflections = m_sQueueSample.m_bRequireReflection;
} else {
bReflections = false;
m_sQueueSample.m_nLoopsRemaining = 0;
}
m_sQueueSample.m_bRequireReflection = false;
2019-06-29 11:44:20 +00:00
2021-01-04 22:31:31 +00:00
if ( m_bReverb && m_sQueueSample.m_bIs2D )
m_sQueueSample.field_4C = 30;
if (!m_bDynamicAcousticModelingStatus)
m_sQueueSample.m_bReverbFlag = false;
2019-06-29 11:44:20 +00:00
m_asSamples[m_nActiveSampleQueue][sampleIndex] = m_sQueueSample;
2019-06-29 11:44:20 +00:00
AddDetailsToRequestedOrderList(sampleIndex);
if (bReflections)
AddReflectionsToRequestedQueue();
2019-06-29 11:44:20 +00:00
}
}
void
cAudioManager::AddDetailsToRequestedOrderList(uint8 sample)
2019-06-29 11:44:20 +00:00
{
uint32 i = 0;
if (sample != 0) {
for (; i < sample; i++) {
if (m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]].m_nCalculatedVolume >
m_asSamples[m_nActiveSampleQueue][sample].m_nCalculatedVolume)
break;
}
if (i < sample) {
memmove(&m_abSampleQueueIndexTable[m_nActiveSampleQueue][i + 1], &m_abSampleQueueIndexTable[m_nActiveSampleQueue][i], m_nActiveSamples - i - 1);
}
2019-06-29 11:44:20 +00:00
}
m_abSampleQueueIndexTable[m_nActiveSampleQueue][i] = sample;
2019-06-29 11:44:20 +00:00
}
void
cAudioManager::AddReflectionsToRequestedQueue()
2019-06-29 11:44:20 +00:00
{
2020-10-11 02:25:15 +00:00
#ifdef FIX_BUGS
uint32 oldFreq = 0;
#else
uint32 oldFreq;
#endif
float reflectionDistance;
int32 noise;
2020-10-11 02:25:15 +00:00
uint8 emittingVolume;
uint32 oldCounter = m_sQueueSample.m_nCounter;
float oldDist = m_sQueueSample.m_fDistance;
CVector oldPos = m_sQueueSample.m_vecPos;
if ( CTimer::GetIsSlowMotionActive() ) {
emittingVolume = m_sQueueSample.m_nVolume;
oldFreq = m_sQueueSample.m_nFrequency;
} else {
2021-01-04 22:31:31 +00:00
emittingVolume = (9 * m_sQueueSample.m_nVolume) / 16;
2020-10-11 02:25:15 +00:00
}
2021-01-04 22:31:31 +00:00
m_sQueueSample.m_fSoundIntensity /= 2.f;
2020-10-11 02:25:15 +00:00
int halfOldFreq = oldFreq >> 1;
2019-06-29 11:44:20 +00:00
for (uint32 i = 0; i < ARRAY_SIZE(m_afReflectionsDistances); i++) {
2020-10-11 02:25:15 +00:00
if ( CTimer::GetIsSlowMotionActive() )
m_afReflectionsDistances[i] = GetRandomNumberInRange(i % 4, 0, 2) * 100.f / 8.f;
reflectionDistance = m_afReflectionsDistances[i];
if (reflectionDistance > 0.0f && reflectionDistance < 100.f && reflectionDistance < m_sQueueSample.m_fSoundIntensity) {
2020-10-11 02:25:15 +00:00
m_sQueueSample.m_nLoopsRemaining = CTimer::GetIsSlowMotionActive() ? (reflectionDistance * 800.f / 1029.f) : (reflectionDistance * 500.f / 1029.f);
if (m_sQueueSample.m_nLoopsRemaining > 3) {
m_sQueueSample.m_fDistance = m_afReflectionsDistances[i];
m_sQueueSample.m_nEmittingVolume = emittingVolume;
m_sQueueSample.m_nVolume = ComputeVolume(emittingVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance);
2020-10-11 02:25:15 +00:00
if (m_sQueueSample.m_nVolume > emittingVolume / 16) {
2020-10-11 02:25:15 +00:00
m_sQueueSample.m_nCounter = oldCounter + (i + 1) * 256;
if (m_sQueueSample.m_nLoopCount) {
2020-10-11 02:25:15 +00:00
if ( CTimer::GetIsSlowMotionActive() ) {
m_sQueueSample.m_nFrequency = halfOldFreq + ((halfOldFreq * i) / ARRAY_SIZE(m_afReflectionsDistances));
} else {
noise = RandomDisplacement(m_sQueueSample.m_nFrequency / 32);
if (noise <= 0)
m_sQueueSample.m_nFrequency += noise;
else
m_sQueueSample.m_nFrequency -= noise;
}
}
m_sQueueSample.m_nReleasingVolumeModificator += 20;
m_sQueueSample.m_vecPos = m_avecReflectionsPos[i];
AddSampleToRequestedQueue();
}
}
}
2019-06-29 11:44:20 +00:00
}
2020-10-11 02:25:15 +00:00
m_sQueueSample.m_vecPos = oldPos;
m_sQueueSample.m_fDistance = oldDist;
2019-06-29 11:44:20 +00:00
}
void
cAudioManager::UpdateReflections()
2019-06-29 11:44:20 +00:00
{
2020-10-11 02:25:15 +00:00
CVector camPos = TheCamera.GetPosition();
CColPoint colpoint;
CEntity *ent;
2019-06-29 11:44:20 +00:00
if (m_FrameCounter % 8 == 0) {
m_avecReflectionsPos[0] = camPos;
2020-10-11 02:25:15 +00:00
m_avecReflectionsPos[0].y += 100.f;
if (CWorld::ProcessLineOfSight(camPos, m_avecReflectionsPos[0], colpoint, ent, true, false, false, true, false, true, true))
m_afReflectionsDistances[0] = Distance(camPos, colpoint.point);
else
2020-10-11 02:25:15 +00:00
m_afReflectionsDistances[0] = 100.0f;
} else if ((m_FrameCounter + 1) % 8 == 0) {
m_avecReflectionsPos[1] = camPos;
2020-10-11 02:25:15 +00:00
m_avecReflectionsPos[1].y -= 100.0f;
if (CWorld::ProcessLineOfSight(camPos, m_avecReflectionsPos[1], colpoint, ent, true, false, false, true, false, true, true))
m_afReflectionsDistances[1] = Distance(camPos, colpoint.point);
else
2020-10-11 02:25:15 +00:00
m_afReflectionsDistances[1] = 100.0f;
} else if ((m_FrameCounter + 2) % 8 == 0) {
m_avecReflectionsPos[2] = camPos;
2020-10-11 02:25:15 +00:00
m_avecReflectionsPos[2].x -= 100.0f;
if (CWorld::ProcessLineOfSight(camPos, m_avecReflectionsPos[2], colpoint, ent, true, false, false, true, false, true, true))
m_afReflectionsDistances[2] = Distance(camPos, colpoint.point);
else
2020-10-11 02:25:15 +00:00
m_afReflectionsDistances[2] = 100.0f;
} else if ((m_FrameCounter + 3) % 8 == 0) {
m_avecReflectionsPos[3] = camPos;
2020-10-11 02:25:15 +00:00
m_avecReflectionsPos[3].x += 100.0f;
if (CWorld::ProcessLineOfSight(camPos, m_avecReflectionsPos[3], colpoint, ent, true, false, false, true, false, true, true))
m_afReflectionsDistances[3] = Distance(camPos, colpoint.point);
else
2020-10-11 02:25:15 +00:00
m_afReflectionsDistances[3] = 100.0f;
} else if ((m_FrameCounter + 4) % 8 == 0) {
2020-10-11 02:25:15 +00:00
camPos.y += 1.0f;
m_avecReflectionsPos[4] = camPos;
2020-10-11 02:25:15 +00:00
m_avecReflectionsPos[4].z += 100.0f;
if (CWorld::ProcessVerticalLine(camPos, m_avecReflectionsPos[4].z, colpoint, ent, true, false, false, false, true, false, nil))
m_afReflectionsDistances[4] = colpoint.point.z - camPos.z;
else
2020-10-11 02:25:15 +00:00
m_afReflectionsDistances[4] = 100.0f;
} else if ((m_FrameCounter + 5) % 8 == 0) {
camPos.y -= 1.0f;
m_avecReflectionsPos[5] = camPos;
m_avecReflectionsPos[5].z += 100.0f;
if (CWorld::ProcessVerticalLine(camPos, m_avecReflectionsPos[5].z, colpoint, ent, true, false, false, false, true, false, nil))
m_afReflectionsDistances[5] = colpoint.point.z - camPos.z;
else
m_afReflectionsDistances[5] = 100.0f;
} else if ((m_FrameCounter + 6) % 8 == 0) {
camPos.x -= 1.0f;
m_avecReflectionsPos[6] = camPos;
m_avecReflectionsPos[6].z += 100.0f;
if (CWorld::ProcessVerticalLine(camPos, m_avecReflectionsPos[6].z, colpoint, ent, true, false, false, false, true, false, nil))
m_afReflectionsDistances[6] = colpoint.point.z - camPos.z;
else
m_afReflectionsDistances[6] = 100.0f;
} else if ((m_FrameCounter + 7) % 8 == 0) {
camPos.x += 1.0f;
m_avecReflectionsPos[7] = camPos;
m_avecReflectionsPos[7].z += 100.0f;
if (CWorld::ProcessVerticalLine(camPos, m_avecReflectionsPos[7].z, colpoint, ent, true, false, false, false, true, false, nil))
m_afReflectionsDistances[7] = colpoint.point.z - camPos.z;
else
m_afReflectionsDistances[7] = 100.0f;
2019-06-29 11:44:20 +00:00
}
}
void
cAudioManager::AddReleasingSounds()
2019-06-29 11:44:20 +00:00
{
bool toProcess[44]; // why not 27?
2019-06-29 11:44:20 +00:00
2020-06-30 16:06:58 +00:00
int8 queue = m_nActiveSampleQueue == 0 ? 1 : 0;
2019-06-29 11:44:20 +00:00
for (int32 i = 0; i < m_SampleRequestQueuesStatus[queue]; i++) {
tSound &sample = m_asSamples[queue][m_abSampleQueueIndexTable[queue][i]];
if (sample.m_bLoopEnded)
continue;
2019-07-31 15:54:18 +00:00
toProcess[i] = false;
for (int32 j = 0; j < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; j++) {
if (sample.m_nEntityIndex == m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][j]].m_nEntityIndex &&
sample.m_nCounter == m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][j]].m_nCounter) {
toProcess[i] = true;
2020-05-02 14:10:51 +00:00
break;
}
2019-08-27 18:50:59 +00:00
}
if (!toProcess[i]) {
if (sample.m_nCounter <= 255 || !sample.m_nLoopsRemaining) {
if (!sample.m_nReleasingVolumeDivider)
continue;
if (!sample.m_nLoopCount) {
if (sample.m_nVolumeChange == -1) {
sample.m_nVolumeChange = sample.m_nVolume / sample.m_nReleasingVolumeDivider;
if (sample.m_nVolumeChange <= 0)
sample.m_nVolumeChange = 1;
}
if (sample.m_nVolume <= sample.m_nVolumeChange) {
sample.m_nReleasingVolumeDivider = 0;
continue;
}
sample.m_nVolume -= sample.m_nVolumeChange;
}
--sample.m_nReleasingVolumeDivider;
if (m_bFifthFrameFlag) {
if (sample.m_nReleasingVolumeModificator < 20)
++sample.m_nReleasingVolumeModificator;
}
2020-12-25 00:29:18 +00:00
sample.m_bReleasingSoundFlag = false;
}
memcpy(&m_sQueueSample, &sample, sizeof(tSound));
AddSampleToRequestedQueue();
2019-08-27 18:50:59 +00:00
}
}
2019-08-15 01:43:00 +00:00
}
2020-10-01 20:48:35 +00:00
void
cAudioManager::ProcessActiveQueues()
2020-10-01 20:11:20 +00:00
{
2020-10-01 21:11:51 +00:00
CVector position;
uint32 freqDivided;
uint32 loopCount;
uint8 emittingVol;
uint8 vol;
uint8 offset;
float x;
bool flag;
bool missionState;
2019-08-27 18:50:59 +00:00
for (int32 i = 0; i < m_nActiveSamples; i++) {
m_asSamples[m_nActiveSampleQueue][i].m_bIsProcessed = false;
m_asActiveSamples[i].m_bIsProcessed = false;
2019-08-27 18:50:59 +00:00
}
2020-10-01 21:11:51 +00:00
for (int32 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) {
2020-10-01 20:11:20 +00:00
tSound& sample = m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]];
if (sample.m_nSampleIndex != NO_SAMPLE) {
2020-10-01 21:11:51 +00:00
for (int32 j = 0; j < m_nActiveSamples; j++) {
2020-10-01 20:48:35 +00:00
if (sample.m_nEntityIndex == m_asActiveSamples[j].m_nEntityIndex &&
sample.m_nCounter == m_asActiveSamples[j].m_nCounter &&
2020-10-01 21:11:51 +00:00
sample.m_nSampleIndex == m_asActiveSamples[j].m_nSampleIndex) {
if (sample.m_nLoopCount) {
2020-10-01 20:48:35 +00:00
if (m_FrameCounter & 1) {
2020-10-01 21:11:51 +00:00
if (!(j & 1)) {
flag = false;
2020-10-01 20:11:20 +00:00
} else {
2020-10-01 21:11:51 +00:00
flag = true;
2020-10-01 20:11:20 +00:00
}
2020-10-01 21:11:51 +00:00
} else if (j & 1) {
flag = false;
} else {
2020-10-01 21:11:51 +00:00
flag = true;
}
2020-10-01 20:11:20 +00:00
2020-10-01 21:11:51 +00:00
if (flag && !SampleManager.GetChannelUsedFlag(j)) {
sample.m_bLoopEnded = true;
m_asActiveSamples[j].m_bLoopEnded = true;
2020-10-01 20:48:35 +00:00
m_asActiveSamples[j].m_nSampleIndex = NO_SAMPLE;
m_asActiveSamples[j].m_nEntityIndex = AEHANDLE_NONE;
continue;
}
2020-10-01 20:11:20 +00:00
if (!sample.m_nReleasingVolumeDivider)
sample.m_nReleasingVolumeDivider = 1;
}
sample.m_bIsProcessed = true;
m_asActiveSamples[j].m_bIsProcessed = true;
sample.m_nVolumeChange = -1;
2020-10-01 21:11:51 +00:00
if (!sample.m_bReleasingSoundFlag) {
if (sample.m_bIs2D) {
if (field_4) {
2020-10-01 20:48:35 +00:00
emittingVol = 2 * Min(63, sample.m_nEmittingVolume);
} else {
emittingVol = sample.m_nEmittingVolume;
}
SampleManager.SetChannelFrequency(j, sample.m_nFrequency);
SampleManager.SetChannelEmittingVolume(j, emittingVol);
} else {
m_asActiveSamples[j].m_fDistance = sample.m_fDistance;
2020-10-01 20:11:20 +00:00
sample.m_nFrequency = ComputeDopplerEffectedFrequency(
sample.m_nFrequency,
m_asActiveSamples[j].m_fDistance,
sample.m_fDistance,
sample.m_fSpeedMultiplier);
2020-10-01 21:11:51 +00:00
if (sample.m_nFrequency != m_asActiveSamples[j].m_nFrequency) {
2020-10-01 20:11:20 +00:00
m_asActiveSamples[j].m_nFrequency = clamp2((int32)sample.m_nFrequency, (int32)m_asActiveSamples[j].m_nFrequency, 6000);
SampleManager.SetChannelFrequency(j, m_asActiveSamples[j].m_nFrequency);
}
2020-10-01 21:11:51 +00:00
if (sample.m_nEmittingVolume != m_asActiveSamples[j].m_nEmittingVolume) {
vol = clamp2((int8)sample.m_nEmittingVolume, (int8)m_asActiveSamples[j].m_nEmittingVolume, 10);
2020-10-01 20:11:20 +00:00
2020-10-01 21:11:51 +00:00
if (field_4) {
emittingVol = 2 * Min(63, vol);
} else {
2020-10-01 21:11:51 +00:00
emittingVol = vol;
}
2020-10-01 20:11:20 +00:00
missionState = false;
2020-10-01 21:11:51 +00:00
for (int32 k = 0; k < ARRAY_SIZE(m_sMissionAudio.m_bIsMobile); k++) {
2020-10-01 20:11:20 +00:00
if (m_sMissionAudio.m_bIsMobile[k]) {
missionState = true;
break;
}
}
2020-10-01 21:11:51 +00:00
if (missionState) {
emittingVol = (emittingVol * field_5538) / 127;
} else {
2020-10-01 20:11:20 +00:00
if (field_5538 < 127)
2020-10-01 21:11:51 +00:00
emittingVol = (emittingVol * field_5538) / 127;
}
2020-10-01 20:11:20 +00:00
2020-10-01 21:11:51 +00:00
SampleManager.SetChannelEmittingVolume(j, emittingVol);
m_asActiveSamples[j].m_nEmittingVolume = vol;
}
2020-10-01 20:48:35 +00:00
TranslateEntity(&sample.m_vecPos, &position);
SampleManager.SetChannel3DPosition(j, position.x, position.y, position.z);
SampleManager.SetChannel3DDistances(j, sample.m_fSoundIntensity, 0.25f * sample.m_fSoundIntensity);
}
SampleManager.SetChannelReverbFlag(j, sample.m_bReverbFlag);
2020-10-01 20:48:35 +00:00
break; //continue for i
}
sample.m_bIsProcessed = false;
m_asActiveSamples[j].m_bIsProcessed = false;
2020-10-01 20:48:35 +00:00
//continue for j
}
}
}
}
2020-10-01 21:11:51 +00:00
for (int32 i = 0; i < m_nActiveSamples; i++) {
if (m_asActiveSamples[i].m_nSampleIndex != NO_SAMPLE && !m_asActiveSamples[i].m_bIsProcessed) {
SampleManager.StopChannel(i);
m_asActiveSamples[i].m_nSampleIndex = NO_SAMPLE;
m_asActiveSamples[i].m_nEntityIndex = AEHANDLE_NONE;
}
}
2020-10-01 21:11:51 +00:00
for (uint8 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) {
2020-10-01 20:11:20 +00:00
tSound& sample = m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]];
2020-10-01 20:48:35 +00:00
if (!sample.m_bIsProcessed && !sample.m_bLoopEnded &&
2020-10-01 21:11:51 +00:00
m_asAudioEntities[sample.m_nEntityIndex].m_bIsUsed && sample.m_nSampleIndex < NO_SAMPLE) {
if (sample.m_nCounter > 255 && sample.m_nLoopCount && sample.m_nLoopsRemaining) {
2020-10-01 20:11:20 +00:00
sample.m_nLoopsRemaining--;
sample.m_nReleasingVolumeDivider = 1;
} else {
2020-10-01 21:11:51 +00:00
for (uint8 j = 0; j < m_nActiveSamples; j++) {
2020-10-01 20:11:20 +00:00
uint8 k = (j + field_6) % m_nActiveSamples;
2020-10-01 21:11:51 +00:00
if (!m_asActiveSamples[k].m_bIsProcessed) {
if (sample.m_nLoopCount != 0) {
2020-10-01 20:11:20 +00:00
freqDivided = sample.m_nFrequency / m_nTimeSpent;
loopCount = sample.m_nLoopCount * SampleManager.GetSampleLength(sample.m_nSampleIndex);
2020-10-01 21:11:51 +00:00
if (freqDivided == 0)
continue;
2020-10-01 20:11:20 +00:00
sample.m_nReleasingVolumeDivider = loopCount / freqDivided + 1;
}
2020-10-01 20:11:20 +00:00
memcpy(&m_asActiveSamples[k], &sample, sizeof(tSound));
2020-10-01 21:11:51 +00:00
if (!m_asActiveSamples[k].m_bIs2D)
2020-10-01 20:11:20 +00:00
TranslateEntity(&m_asActiveSamples[k].m_vecPos, &position);
2020-10-01 21:11:51 +00:00
if (field_4) {
emittingVol = 2 * Min(63, m_asActiveSamples[k].m_nEmittingVolume);
} else {
2020-10-01 21:11:51 +00:00
emittingVol = m_asActiveSamples[k].m_nEmittingVolume;
}
2020-10-01 20:11:20 +00:00
if (SampleManager.InitialiseChannel(k, m_asActiveSamples[k].m_nSampleIndex, m_asActiveSamples[k].m_nBankIndex)) {
SampleManager.SetChannelFrequency(k, m_asActiveSamples[k].m_nFrequency);
bool isMobile = false;
2020-10-01 21:11:51 +00:00
for (int32 l = 0; l < ARRAY_SIZE(m_sMissionAudio.m_bIsMobile); l++) {
if (m_sMissionAudio.m_bIsMobile[l]) {
2020-10-01 20:11:20 +00:00
isMobile = true;
break;
}
}
2020-10-01 21:11:51 +00:00
if (!isMobile || m_asActiveSamples[k].m_bIs2D) {
if (field_5538 < 127)
emittingVol *= field_5538 / 127;
vol = emittingVol;
2020-10-01 20:11:20 +00:00
} else {
2020-10-01 21:11:51 +00:00
vol = (emittingVol * field_5538 / 127);
2020-10-01 20:11:20 +00:00
}
2020-10-01 21:11:51 +00:00
SampleManager.SetChannelEmittingVolume(k, vol);
2020-10-01 20:11:20 +00:00
SampleManager.SetChannelLoopPoints(k, m_asActiveSamples[k].m_nLoopStart, m_asActiveSamples[k].m_nLoopEnd);
SampleManager.SetChannelLoopCount(k, m_asActiveSamples[k].m_nLoopCount);
SampleManager.SetChannelReverbFlag(k, m_asActiveSamples[k].m_bReverbFlag);
2020-10-01 21:11:51 +00:00
if (m_asActiveSamples[k].m_bIs2D) {
2020-10-01 20:11:20 +00:00
offset = m_asActiveSamples[k].m_nOffset;
2020-10-01 21:11:51 +00:00
if (offset == 63) {
2020-10-01 20:11:20 +00:00
x = 0.0f;
2020-10-01 21:11:51 +00:00
} else if (offset >= 63) {
2020-10-01 20:48:35 +00:00
x = (offset - 63) * 1000.0f / 63;
} else {
2020-10-01 21:11:51 +00:00
x = -(63 - offset) * 1000.0f / 63; //same like line below
}
2020-10-01 20:11:20 +00:00
position = CVector(x, 0.0f, 0.0f);
m_asActiveSamples[k].m_fSoundIntensity = 100000.0f;
}
2020-10-01 20:11:20 +00:00
SampleManager.SetChannel3DPosition(k, position.x, position.y, position.z);
SampleManager.SetChannel3DDistances(k, m_asActiveSamples[k].m_fSoundIntensity, 0.25f * m_asActiveSamples[k].m_fSoundIntensity);
SampleManager.StartChannel(k);
}
2020-10-01 20:11:20 +00:00
m_asActiveSamples[k].m_bIsProcessed = true;
sample.m_bIsProcessed = true;
sample.m_nVolumeChange = -1;
break;
}
}
}
}
2019-11-04 23:31:50 +00:00
}
2020-10-01 21:11:51 +00:00
field_6 %= m_nActiveSamples;
2019-09-21 20:10:35 +00:00
}
2020-10-01 21:11:51 +00:00
void
cAudioManager::ClearRequestedQueue()
2019-08-15 01:43:00 +00:00
{
for (int32 i = 0; i < m_nActiveSamples; i++) {
m_abSampleQueueIndexTable[m_nActiveSampleQueue][i] = m_nActiveSamples;
}
m_SampleRequestQueuesStatus[m_nActiveSampleQueue] = 0;
2019-08-15 01:43:00 +00:00
}
void
cAudioManager::ClearActiveSamples()
2019-08-15 01:43:00 +00:00
{
2020-10-02 00:55:26 +00:00
for (uint8 i = 0; i < m_nActiveSamples; i++) {
m_asActiveSamples[i].m_nEntityIndex = AEHANDLE_NONE;
m_asActiveSamples[i].m_nCounter = 0;
m_asActiveSamples[i].m_nSampleIndex = NO_SAMPLE;
m_asActiveSamples[i].m_nBankIndex = INVALID_SFX_BANK;
m_asActiveSamples[i].m_bIs2D = false;
m_asActiveSamples[i].m_nReleasingVolumeModificator = 5;
m_asActiveSamples[i].m_nFrequency = 0;
m_asActiveSamples[i].m_nVolume = 0;
m_asActiveSamples[i].m_nEmittingVolume = 0;
m_asActiveSamples[i].m_fDistance = 0.0f;
m_asActiveSamples[i].m_bIsProcessed = false;
m_asActiveSamples[i].m_bLoopEnded = false;
m_asActiveSamples[i].m_nLoopCount = 1;
m_asActiveSamples[i].m_nLoopStart = 0;
m_asActiveSamples[i].m_nLoopEnd = -1;
m_asActiveSamples[i].m_fSpeedMultiplier = 0.0f;
m_asActiveSamples[i].m_fSoundIntensity = 200.0f;
m_asActiveSamples[i].m_nOffset = 63;
m_asActiveSamples[i].m_bReleasingSoundFlag = false;
m_asActiveSamples[i].m_nCalculatedVolume = 0;
m_asActiveSamples[i].m_nReleasingVolumeDivider = 0;
m_asActiveSamples[i].m_nVolumeChange = -1;
2020-10-02 17:35:16 +00:00
m_asActiveSamples[i].m_vecPos = CVector(0.0f, 0.0f, 0.0f);
m_asActiveSamples[i].m_bReverbFlag = false;
m_asActiveSamples[i].m_nLoopsRemaining = 0;
m_asActiveSamples[i].m_bRequireReflection = false;
2019-08-27 18:50:59 +00:00
}
2019-08-15 01:43:00 +00:00
}
void
cAudioManager::GenerateIntegerRandomNumberTable()
2019-08-15 01:43:00 +00:00
{
for (int32 i = 0; i < ARRAY_SIZE(m_anRandomTable); i++) {
2020-05-18 17:17:24 +00:00
m_anRandomTable[i] = myrand();
2019-08-27 18:50:59 +00:00
}
2019-08-15 01:43:00 +00:00
}
#ifdef GTA_PC
2019-08-29 22:44:57 +00:00
void
2019-10-19 11:21:35 +00:00
cAudioManager::AdjustSamplesVolume()
2019-08-29 22:44:57 +00:00
{
2020-05-02 14:10:51 +00:00
for (int i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) {
tSound *pSample = &m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i] + 1];
2019-10-19 11:21:35 +00:00
2020-05-02 13:27:40 +00:00
if (!pSample->m_bIs2D)
pSample->m_nEmittingVolume = ComputeEmittingVolume(pSample->m_nEmittingVolume, pSample->m_fSoundIntensity, pSample->m_fDistance);
2019-10-19 11:21:35 +00:00
}
2019-08-29 22:44:57 +00:00
}
uint8
2019-10-25 16:39:26 +00:00
cAudioManager::ComputeEmittingVolume(uint8 emittingVolume, float intensity, float dist)
2019-10-19 11:21:35 +00:00
{
float quatIntensity = intensity / 4.0f;
float diffIntensity = intensity - quatIntensity;
2020-05-02 13:27:40 +00:00
if (dist > diffIntensity)
return (quatIntensity - (dist - diffIntensity)) * (float)emittingVolume / quatIntensity;
2019-10-19 11:21:35 +00:00
return emittingVolume;
2019-08-29 22:44:57 +00:00
}
2020-10-11 02:25:15 +00:00
#endif