mirror of
https://github.com/GTAmodding/re3.git
synced 2024-12-27 21:45:43 +00:00
Audio: small refactoring
This commit is contained in:
parent
abe6c22f56
commit
a04a84e00b
1 changed files with 30 additions and 29 deletions
|
@ -200,7 +200,7 @@ cAudioManager::DestroyEntity(int32 id)
|
|||
for (uint32 i = 0; i < m_nAudioEntitiesCount; ++i) {
|
||||
if (id == m_aAudioEntityOrderList[i]) {
|
||||
if (i < NUM_AUDIOENTITIES - 1)
|
||||
memmove(&m_aAudioEntityOrderList[i], &m_aAudioEntityOrderList[i + 1], NUM_AUDIOENTITY_EVENTS * (m_nAudioEntitiesCount - (i + 1)));
|
||||
memmove(&m_aAudioEntityOrderList[i], &m_aAudioEntityOrderList[i + 1], sizeof(uint32) * (m_nAudioEntitiesCount - (i + 1)));
|
||||
m_aAudioEntityOrderList[--m_nAudioEntitiesCount] = NUM_AUDIOENTITIES;
|
||||
return;
|
||||
}
|
||||
|
@ -231,14 +231,17 @@ cAudioManager::GetEntityPointer(int32 id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
void
|
||||
cAudioManager::PlayOneShot(int32 index, uint16 sound, float vol)
|
||||
{
|
||||
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 };
|
||||
|
||||
if (m_bIsInitialised) {
|
||||
if (index >= 0 && index < NUM_AUDIOENTITIES) {
|
||||
|
@ -255,7 +258,7 @@ cAudioManager::PlayOneShot(int32 index, uint16 sound, float vol)
|
|||
int32 i = 0;
|
||||
while (TRUE) {
|
||||
if (i >= entity.m_AudioEvents) {
|
||||
if (entity.m_AudioEvents < ARRAY_SIZE(entity.m_awAudioEvent)) {
|
||||
if (entity.m_AudioEvents < NUM_AUDIOENTITY_EVENTS) {
|
||||
entity.m_awAudioEvent[i] = sound;
|
||||
entity.m_afVolume[i] = vol;
|
||||
entity.m_AudioEvents++;
|
||||
|
@ -267,12 +270,12 @@ cAudioManager::PlayOneShot(int32 index, uint16 sound, float vol)
|
|||
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);
|
||||
memmove(&entity.m_awAudioEvent[i + 1], &entity.m_awAudioEvent[i], (NUM_AUDIOENTITY_EVENTS - 1 - i) * sizeof(int16));
|
||||
memmove(&entity.m_afVolume[i + 1], &entity.m_afVolume[i], (NUM_AUDIOENTITY_EVENTS - 1 - i) * sizeof(float));
|
||||
}
|
||||
entity.m_awAudioEvent[i] = sound;
|
||||
entity.m_afVolume[i] = vol;
|
||||
if (entity.m_AudioEvents < ARRAY_SIZE(entity.m_awAudioEvent))
|
||||
if (entity.m_AudioEvents < NUM_AUDIOENTITY_EVENTS)
|
||||
entity.m_AudioEvents++;
|
||||
}
|
||||
}
|
||||
|
@ -481,17 +484,15 @@ cAudioManager::IsMP3RadioChannelAvailable()
|
|||
void
|
||||
cAudioManager::ReleaseDigitalHandle()
|
||||
{
|
||||
if (m_bIsInitialised) {
|
||||
if (m_bIsInitialised)
|
||||
SampleManager.ReleaseDigitalHandle();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cAudioManager::ReacquireDigitalHandle()
|
||||
{
|
||||
if (m_bIsInitialised) {
|
||||
if (m_bIsInitialised)
|
||||
SampleManager.ReacquireDigitalHandle();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef AUDIO_REFLECTIONS
|
||||
|
@ -624,10 +625,10 @@ Const static uint8 PanTable[64] = { 0, 3, 8, 12, 16, 19, 22, 24, 26, 28, 30, 3
|
|||
int32
|
||||
cAudioManager::ComputeFrontRearMix(float dist, CVector *vec)
|
||||
{
|
||||
int32 index = vec->y / (dist / 64.f);
|
||||
int32 index = vec->y / (dist / 64.0f);
|
||||
index = Min(63, ABS(index));
|
||||
|
||||
if (vec->y > 0.f)
|
||||
if (vec->y > 0.0f)
|
||||
return Max(0, 63 - (int8)PanTable[index]);
|
||||
return Min(127, PanTable[index] + 63);
|
||||
}
|
||||
|
@ -635,10 +636,10 @@ cAudioManager::ComputeFrontRearMix(float dist, CVector *vec)
|
|||
int32
|
||||
cAudioManager::ComputePan(float dist, CVector *vec)
|
||||
{
|
||||
int32 index = vec->x / (dist / 64.f);
|
||||
int32 index = vec->x / (dist / 64.0f);
|
||||
index = Min(63, ABS(index));
|
||||
|
||||
if (vec->x > 0.f)
|
||||
if (vec->x > 0.0f)
|
||||
return Max(20, 63 - (int8)PanTable[index]);
|
||||
return Min(107, PanTable[index] + 63);
|
||||
}
|
||||
|
@ -668,15 +669,15 @@ cAudioManager::RandomDisplacement(uint32 seed)
|
|||
static bool8 bPos = TRUE;
|
||||
static uint32 Adjustment = 0;
|
||||
|
||||
if (!seed)
|
||||
if (seed == 0)
|
||||
return 0;
|
||||
|
||||
value = m_anRandomTable[(Adjustment + seed) % 5] % seed;
|
||||
Adjustment += value;
|
||||
|
||||
if (value % 2) {
|
||||
if (value % 2)
|
||||
bPos = !bPos;
|
||||
}
|
||||
|
||||
if (!bPos)
|
||||
value = -value;
|
||||
return value;
|
||||
|
@ -780,7 +781,7 @@ cAudioManager::AddReflectionsToRequestedQueue()
|
|||
oldFreq = m_sQueueSample.m_nFrequency;
|
||||
} else
|
||||
#endif
|
||||
emittingVolume = (9 * m_sQueueSample.m_nVolume) / 16;
|
||||
emittingVolume = (9 * m_sQueueSample.m_nVolume) >> 4;
|
||||
m_sQueueSample.m_MaxDistance /= 2.0f;
|
||||
|
||||
uint32 halfOldFreq = oldFreq >> 1;
|
||||
|
@ -788,23 +789,23 @@ cAudioManager::AddReflectionsToRequestedQueue()
|
|||
for (uint32 i = 0; i < ARRAY_SIZE(m_afReflectionsDistances); i++) {
|
||||
#ifndef USE_TIME_SCALE_FOR_AUDIO
|
||||
if ( CTimer::GetIsSlowMotionActive() )
|
||||
m_afReflectionsDistances[i] = (m_anRandomTable[i % 4] % 3) * 100.f / 8.f;
|
||||
m_afReflectionsDistances[i] = (m_anRandomTable[i % 4] % 3) * 100.0f / 8.0f;
|
||||
#endif
|
||||
|
||||
reflectionDistance = m_afReflectionsDistances[i];
|
||||
if (reflectionDistance > 0.0f && reflectionDistance < 100.f && reflectionDistance < m_sQueueSample.m_MaxDistance) {
|
||||
if (reflectionDistance > 0.0f && reflectionDistance < 100.0f && reflectionDistance < m_sQueueSample.m_MaxDistance) {
|
||||
#ifndef USE_TIME_SCALE_FOR_AUDIO
|
||||
m_sQueueSample.m_nReflectionDelay = CTimer::GetIsSlowMotionActive() ? (reflectionDistance * 800.f / 1029.f) : (reflectionDistance * 500.f / 1029.f);
|
||||
m_sQueueSample.m_nReflectionDelay = CTimer::GetIsSlowMotionActive() ? (reflectionDistance * 800.0f / 1029.0f) : (reflectionDistance * 500.0f / 1029.0f);
|
||||
#else
|
||||
m_sQueueSample.m_nReflectionDelay = reflectionDistance * 500.f / 1029.f;
|
||||
m_sQueueSample.m_nReflectionDelay = reflectionDistance * 500.0f / 1029.0f;
|
||||
#endif
|
||||
if (m_sQueueSample.m_nReflectionDelay > 3) {
|
||||
m_sQueueSample.m_fDistance = m_afReflectionsDistances[i];
|
||||
SET_EMITTING_VOLUME(emittingVolume);
|
||||
m_sQueueSample.m_nVolume = ComputeVolume(emittingVolume, m_sQueueSample.m_MaxDistance, m_sQueueSample.m_fDistance);
|
||||
|
||||
if (m_sQueueSample.m_nVolume > emittingVolume / 16) {
|
||||
m_sQueueSample.m_nCounter = oldCounter + (i + 1) * 256;
|
||||
if (m_sQueueSample.m_nVolume > emittingVolume >> 4) {
|
||||
m_sQueueSample.m_nCounter = oldCounter + ((i + 1) << 8);
|
||||
if (m_sQueueSample.m_nLoopCount > 0) {
|
||||
#ifndef USE_TIME_SCALE_FOR_AUDIO
|
||||
if ( CTimer::GetIsSlowMotionActive() ) {
|
||||
|
@ -812,7 +813,7 @@ cAudioManager::AddReflectionsToRequestedQueue()
|
|||
} else
|
||||
#endif
|
||||
{
|
||||
noise = RandomDisplacement(m_sQueueSample.m_nFrequency / 32);
|
||||
noise = RandomDisplacement(m_sQueueSample.m_nFrequency >> 5);
|
||||
if (noise > 0)
|
||||
m_sQueueSample.m_nFrequency -= noise;
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue