summaryrefslogtreecommitdiffstats
path: root/src/audio/AudioManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/AudioManager.cpp')
-rw-r--r--src/audio/AudioManager.cpp374
1 files changed, 279 insertions, 95 deletions
diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp
index c13b8cca..e46bc07e 100644
--- a/src/audio/AudioManager.cpp
+++ b/src/audio/AudioManager.cpp
@@ -10,17 +10,18 @@
#include "sampman.h"
#include "Camera.h"
#include "World.h"
-#include "Entity.h"
+#include "ZoneCull.h"
cAudioManager AudioManager;
#define SPEED_OF_SOUND 343.f
-#define TIME_SPENT 50
+#define TIME_SPENT 40
cAudioManager::cAudioManager()
{
m_bIsInitialised = FALSE;
m_bIsSurround = TRUE;
+ m_nChannelOffset = 0;
m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT;
m_nTimeSpent = TIME_SPENT;
m_nActiveSamples = NUM_CHANNELS_GENERIC;
@@ -233,11 +234,11 @@ cAudioManager::GetEntityPointer(int32 id)
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, 5, 5, 3, 5, 2, 2, 1, 1, 3, 1, 3, 3, 1, 1, 1, 4, 4, 3, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 1, 1, 3, 2, 2, 2, 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,
- 2, 2, 0, 0, 0, 0, 3, 3, 5, 1, 1, 1, 1, 3, 4, 7, 6, 6, 6, 6, 1, 3, 4, 3, 4, 2, 1, 3, 5, 4, 6, 6, 1, 3,
- 1, 1, 1, 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, 0, 0, 0, 0};
+ 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) {
@@ -293,6 +294,12 @@ cAudioManager::SetMusicMasterVolume(uint8 volume)
}
void
+cAudioManager::SetMP3BoostVolume(uint8 volume)
+{
+ SampleManager.SetMP3BoostVolume(volume);
+}
+
+void
cAudioManager::SetEffectsFadeVol(uint8 volume)
{
SampleManager.SetEffectsFadeVolume(volume);
@@ -305,9 +312,9 @@ cAudioManager::SetMusicFadeVol(uint8 volume)
}
void
-cAudioManager::SetMonoMode(bool8 mono)
+cAudioManager::SetOutputMode(bool8 surround)
{
- SampleManager.SetMonoMode(mono);
+ // on ps2 this calls another method of cAudioManager to set DTS mode on or off
}
void
@@ -327,11 +334,13 @@ cAudioManager::ResetTimers(uint32 time)
m_nActiveSampleQueue = 0;
}
ClearActiveSamples();
- ClearMissionAudio();
+ ClearMissionAudio(0);
+ ClearMissionAudio(1);
SampleManager.StopChannel(CHANNEL_POLICE_RADIO);
SampleManager.SetEffectsFadeVolume(0);
SampleManager.SetMusicFadeVolume(0);
MusicManager.ResetMusicAfterReload();
+ m_bIsPlayerShutUp = FALSE;
#ifdef AUDIO_OAL
SampleManager.Service();
#endif
@@ -350,7 +359,7 @@ cAudioManager::DestroyAllGameCreatedEntities()
case AUDIOTYPE_PHYSICAL:
case AUDIOTYPE_EXPLOSION:
case AUDIOTYPE_WEATHER:
- case AUDIOTYPE_CRANE:
+ //case AUDIOTYPE_CRANE:
case AUDIOTYPE_GARAGE:
case AUDIOTYPE_FIREHYDRANT:
DestroyEntity(i);
@@ -415,6 +424,17 @@ cAudioManager::GetCurrent3DProviderIndex()
}
int8
+cAudioManager::AutoDetect3DProviders()
+{
+#ifdef EXTERNAL_3D_SOUND
+ if (m_bIsInitialised)
+ return SampleManager.AutoDetect3DProviders();
+#endif
+
+ return -1;
+}
+
+int8
cAudioManager::SetCurrent3DProvider(uint8 which)
{
#ifndef EXTERNAL_3D_SOUND
@@ -433,11 +453,9 @@ cAudioManager::SetCurrent3DProvider(uint8 which)
ClearActiveSamples();
int8 current = SampleManager.SetCurrent3DProvider(which);
if (current > 0) {
-#ifdef EXTERNAL_3D_SOUND
m_nActiveSamples = SampleManager.GetMaximumSupportedChannels();
if (m_nActiveSamples > 1)
--m_nActiveSamples;
-#endif
}
return current;
#endif
@@ -495,7 +513,6 @@ cAudioManager::GetCDAudioDriveLetter()
{
if (m_bIsInitialised)
return SampleManager.GetCDAudioDriveLetter();
-
return '\0';
}
@@ -515,9 +532,28 @@ cAudioManager::ServiceSoundEffects()
#endif
m_bReduceReleasingPriority = (m_FrameCounter++ % 5) == 0;
if (m_nUserPause && !m_nPreviousUserPause) {
- for (int32 i = 0; i < NUM_CHANNELS; i++)
- SampleManager.StopChannel(i);
+#ifdef GTA_PS2
+ if (m_bIsSurround) {
+ for (uint32 i = 0; i < NUM_CHANNELS_DTS_GENERIC; i++)
+ SampleManager.StopChannel(i);
+
+ SampleManager.SetChannelFrequency(CHANNEL_DTS_POLICE_RADIO, 0);
+ SampleManager.SetChannelFrequency(CHANNEL_DTS_MISSION_AUDIO_1, 0);
+ SampleManager.SetChannelFrequency(CHANNEL_DTS_MISSION_AUDIO_2, 0);
+ SampleManager.SetChannelFrequency(CHANNEL_DTS_PLAYER_VEHICLE_ENGINE, 0);
+ } else {
+ for (uint32 i = 0; i < NUM_CHANNELS_GENERIC; i++)
+ SampleManager.StopChannel(i);
+ SampleManager.SetChannelFrequency(CHANNEL_POLICE_RADIO, 0);
+ SampleManager.SetChannelFrequency(CHANNEL_MISSION_AUDIO_1, 0);
+ SampleManager.SetChannelFrequency(CHANNEL_MISSION_AUDIO_2, 0);
+ SampleManager.SetChannelFrequency(CHANNEL_PLAYER_VEHICLE_ENGINE, 0);
+ }
+#else
+ for (uint32 i = 0; i < NUM_CHANNELS; i++)
+ SampleManager.StopChannel(i);
+#endif
ClearRequestedQueue();
if (m_nActiveSampleQueue) {
m_nActiveSampleQueue = 0;
@@ -531,7 +567,9 @@ cAudioManager::ServiceSoundEffects()
ClearActiveSamples();
}
m_nActiveSampleQueue = m_nActiveSampleQueue == 1 ? 0 : 1;
- ProcessReverb();
+#ifdef AUDIO_REVERB
+ if(m_bIsSurround) ProcessReverb();
+#endif
ProcessSpecial();
ClearRequestedQueue();
InterrogateAudioEntities();
@@ -556,22 +594,22 @@ cAudioManager::ServiceSoundEffects()
m_sAudioScriptObjectManager.m_nScriptObjectEntityTotal = 0;
}
-uint32
-cAudioManager::FL(float f)
-{
- return SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex) * f;
-}
-
uint8
cAudioManager::ComputeVolume(uint8 emittingVolume, float maxDistance, float distance)
{
float minDistance;
+ uint8 newEmittingVolume;
+
if (maxDistance <= 0.0f)
return 0;
+
minDistance = maxDistance / 5.0f;
- if (minDistance <= distance)
- emittingVolume = sq((maxDistance - minDistance - (distance - minDistance)) / (maxDistance - minDistance)) * emittingVolume;
- return emittingVolume;
+ if (minDistance > distance)
+ return emittingVolume;
+
+ newEmittingVolume = emittingVolume * SQR((maxDistance - minDistance - (distance - minDistance))
+ / (maxDistance - minDistance));
+ return Min(127, newEmittingVolume);
}
void
@@ -580,12 +618,23 @@ cAudioManager::TranslateEntity(Const CVector *in, CVector *out)
*out = MultiplyInverse(TheCamera.GetMatrix(), *in);
}
+Const static 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
-cAudioManager::ComputePan(float dist, CVector *vec)
+cAudioManager::ComputeFrontRearMix(float dist, CVector *vec)
{
- Const static 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 = vec->y / (dist / 64.f);
+ index = Min(63, ABS(index));
+
+ if (vec->y > 0.f)
+ return Max(0, 63 - (int8)PanTable[index]);
+ return Min(127, PanTable[index] + 63);
+}
+int32
+cAudioManager::ComputePan(float dist, CVector *vec)
+{
int32 index = vec->x / (dist / 64.f);
index = Min(63, ABS(index));
@@ -661,18 +710,10 @@ cAudioManager::AddSampleToRequestedQueue()
} else {
++m_SampleRequestQueuesStatus[m_nActiveSampleQueue];
}
-#if GTA_VERSION < GTA3_PC_10
- if (m_sQueueSample.m_bStatic) {
- if (m_sQueueSample.m_nLoopCount > 0)
- m_sQueueSample.unk = m_nTimeSpent * SampleManager.GetSampleLength(m_sQueueSample.m_nSampleIndex) / m_sQueueSample.m_nFrequency;
- else
- m_sQueueSample.unk = -3;
- }
-#endif
m_sQueueSample.m_nFinalPriority = finalPriority;
m_sQueueSample.m_bIsPlayingFinished = FALSE;
#ifdef AUDIO_REFLECTIONS
- if (m_sQueueSample.m_bIs2D) {
+ if (m_sQueueSample.m_bIs2D || CCullZones::InRoomForAudio()) {
m_sQueueSample.m_bReflections = FALSE;
m_sQueueSample.m_nReflectionDelay = 0;
}
@@ -684,9 +725,13 @@ cAudioManager::AddSampleToRequestedQueue()
}
m_sQueueSample.m_bReflections = FALSE;
+ if ( m_bIsSurround && m_sQueueSample.m_bIs2D )
+ m_sQueueSample.m_nFrontRearPan = 30;
+#ifdef AUDIO_REVERB
if (!m_bDynamicAcousticModelingStatus)
m_sQueueSample.m_bReverb = FALSE;
#endif
+#endif
m_asSamples[m_nActiveSampleQueue][sampleIndex] = m_sQueueSample;
@@ -702,7 +747,7 @@ void
cAudioManager::AddDetailsToRequestedOrderList(uint8 sample)
{
uint32 i = 0;
- if (sample != 0) {
+ if (sample > 0) {
for (; i < sample; i++) {
if (m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]].m_nFinalPriority >
m_asSamples[m_nActiveSampleQueue][sample].m_nFinalPriority)
@@ -719,26 +764,52 @@ cAudioManager::AddDetailsToRequestedOrderList(uint8 sample)
void
cAudioManager::AddReflectionsToRequestedQueue()
{
+#ifdef FIX_BUGS
+ uint32 oldFreq = 0;
+#else
+ uint32 oldFreq;
+#endif
float reflectionDistance;
int32 noise;
- uint8 emittingVolume = (m_sQueueSample.m_nVolume / 2) + (m_sQueueSample.m_nVolume / 8);
+ 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 {
+ emittingVolume = (9 * m_sQueueSample.m_nVolume) / 16;
+ }
+ m_sQueueSample.m_MaxDistance /= 2.f;
+
+ uint32 halfOldFreq = oldFreq >> 1;
for (uint32 i = 0; i < ARRAY_SIZE(m_afReflectionsDistances); i++) {
+ if ( CTimer::GetIsSlowMotionActive() )
+ m_afReflectionsDistances[i] = (m_anRandomTable[i % 4] % 3) * 100.f / 8.f;
+
reflectionDistance = m_afReflectionsDistances[i];
if (reflectionDistance > 0.0f && reflectionDistance < 100.f && reflectionDistance < m_sQueueSample.m_MaxDistance) {
- m_sQueueSample.m_nReflectionDelay = (reflectionDistance * 500.f / 1029.f);
- if (m_sQueueSample.m_nReflectionDelay > 5) {
+ m_sQueueSample.m_nReflectionDelay = CTimer::GetIsSlowMotionActive() ? (reflectionDistance * 800.f / 1029.f) : (reflectionDistance * 500.f / 1029.f);
+ 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 += (i + 1) * 256;
+ m_sQueueSample.m_nCounter = oldCounter + (i + 1) * 256;
if (m_sQueueSample.m_nLoopCount > 0) {
- noise = RandomDisplacement(m_sQueueSample.m_nFrequency / 32);
- if (noise > 0)
- m_sQueueSample.m_nFrequency -= noise;
- else
- m_sQueueSample.m_nFrequency += noise;
+ 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_nPriority += 20;
m_sQueueSample.m_vecPos = m_avecReflectionsPos[i];
@@ -747,6 +818,8 @@ cAudioManager::AddReflectionsToRequestedQueue()
}
}
}
+ m_sQueueSample.m_vecPos = oldPos;
+ m_sQueueSample.m_fDistance = oldDist;
}
void
@@ -756,6 +829,7 @@ cAudioManager::UpdateReflections()
CColPoint colpoint;
CEntity *ent;
+#if GTA_VERSION < GTAVC_PC_10
if (m_FrameCounter % 8 == 0) {
camPos = TheCamera.GetPosition();
m_avecReflectionsPos[0] = camPos;
@@ -797,6 +871,77 @@ cAudioManager::UpdateReflections()
else
m_afReflectionsDistances[4] = 50.0f;
}
+#else
+ if (m_FrameCounter % 8 == 0) {
+ camPos = TheCamera.GetPosition();
+ m_avecReflectionsPos[0] = camPos;
+ 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
+ m_afReflectionsDistances[0] = 100.0f;
+ } else if ((m_FrameCounter + 1) % 8 == 0) {
+ camPos = TheCamera.GetPosition();
+ m_avecReflectionsPos[1] = camPos;
+ 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
+ m_afReflectionsDistances[1] = 100.0f;
+ } else if ((m_FrameCounter + 2) % 8 == 0) {
+ camPos = TheCamera.GetPosition();
+ m_avecReflectionsPos[2] = camPos;
+ 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
+ m_afReflectionsDistances[2] = 100.0f;
+ } else if ((m_FrameCounter + 3) % 8 == 0) {
+ camPos = TheCamera.GetPosition();
+ m_avecReflectionsPos[3] = camPos;
+ 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
+ m_afReflectionsDistances[3] = 100.0f;
+ } else if ((m_FrameCounter + 4) % 8 == 0) {
+ camPos = TheCamera.GetPosition();
+ camPos.y += 1.0f;
+ m_avecReflectionsPos[4] = camPos;
+ 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
+ m_afReflectionsDistances[4] = 100.0f;
+ } else if ((m_FrameCounter + 5) % 8 == 0) {
+ camPos = TheCamera.GetPosition();
+ 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 = TheCamera.GetPosition();
+ 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 = TheCamera.GetPosition();
+ 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;
+ }
+#endif
}
#endif // AUDIO_REFLECTIONS
@@ -825,9 +970,9 @@ cAudioManager::AddReleasingSounds()
break;
}
}
- if (!toProcess[i]) {
+ if(!toProcess[i]) {
#ifdef AUDIO_REFLECTIONS
- if (sample.m_nCounter <= 255 || sample.m_nReflectionDelay == 0) // check if not delayed reflection
+ if(sample.m_nCounter <= 255 || sample.m_nReflectionDelay == 0) // check if not delayed reflection
#endif
{
#ifdef ATTACH_RELEASING_SOUNDS_TO_ENTITIES
@@ -867,7 +1012,6 @@ cAudioManager::AddReleasingSounds()
}
#endif
#ifdef FIX_BUGS
- // fixing emitting volume not being lowered and high fps bugs
if (sample.m_nFramesToPlay <= 0)
continue;
if (sample.m_nLoopCount == 0) {
@@ -947,11 +1091,14 @@ cAudioManager::ProcessActiveQueues()
uint8 emittingVol;
CVector position;
+ bool8 isPhoneCall;
+ uint8 channelOffset = 0;
+
#ifdef EXTERNAL_3D_SOUND
#define WORKING_VOLUME_FIELD m_nEmittingVolume
#else
#define WORKING_VOLUME_FIELD m_nVolume
-#endif
+#endif
#ifdef USE_TIME_SCALE_FOR_AUDIO
float timeScale = m_nUserPause ? 1.0f : CTimer::GetTimeScale();
@@ -967,27 +1114,22 @@ cAudioManager::ProcessActiveQueues()
if (sample.m_nSampleIndex != NO_SAMPLE) {
for (int32 j = 0; j < m_nActiveSamples; j++) {
if (sample.m_nEntityIndex == m_asActiveSamples[j].m_nEntityIndex && sample.m_nCounter == m_asActiveSamples[j].m_nCounter &&
- sample.m_nSampleIndex == m_asActiveSamples[j].m_nSampleIndex) {
+ sample.m_nSampleIndex == m_asActiveSamples[j].m_nSampleIndex) {
if (sample.m_nLoopCount > 0) {
-#if GTA_VERSION >= GTA3_PC_10
if (m_FrameCounter & 1)
flag = !!(j & 1);
else
flag = !(j & 1);
+
if (flag && !SampleManager.GetChannelUsedFlag(j)) {
-#else
- if (m_asActiveSamples[j].unk != 0)
- m_asActiveSamples[j].unk--;
- else if (SampleManager.GetChannelUsedFlag(j))
- m_asActiveSamples[j].unk = m_nTimeSpent * SampleManager.GetSampleLength(m_asActiveSamples[j].m_nSampleIndex) / m_asActiveSamples[j].m_nFrequency;
- else {
-#endif
sample.m_bIsPlayingFinished = TRUE;
m_asActiveSamples[j].m_bIsPlayingFinished = TRUE;
m_asActiveSamples[j].m_nSampleIndex = NO_SAMPLE;
m_asActiveSamples[j].m_nEntityIndex = AEHANDLE_NONE;
continue;
}
+ if (sample.m_nFramesToPlay == 0)
+ sample.m_nFramesToPlay = 1;
}
sample.m_bIsBeingPlayed = TRUE;
m_asActiveSamples[j].m_bIsBeingPlayed = TRUE;
@@ -1004,7 +1146,7 @@ cAudioManager::ProcessActiveQueues()
SampleManager.SetChannelEmittingVolume(j, emittingVol);
#else
SampleManager.SetChannelPan(j, sample.m_nPan);
- SampleManager.SetChannelVolume(j, sample.m_nVolume);
+ SampleManager.SetChannelVolume(j, emittingVol);
#endif
} else {
position2 = sample.m_fDistance;
@@ -1020,20 +1162,37 @@ cAudioManager::ProcessActiveQueues()
SampleManager.SetChannelFrequency(j, freq);
#endif
}
-
#ifdef EXTERNAL_3D_SOUND
if (sample.m_nEmittingVolume != m_asActiveSamples[j].m_nEmittingVolume) {
vol = Clamp2((int8)sample.m_nEmittingVolume, (int8)m_asActiveSamples[j].m_nEmittingVolume, 10);
- SampleManager.SetChannelEmittingVolume(j, m_bDoubleVolume ? 2 * Min(63, vol) : vol);
- m_asActiveSamples[j].m_nEmittingVolume = vol;
- }
#else
if (sample.m_nVolume != m_asActiveSamples[j].m_nVolume) {
vol = Clamp2((int8)sample.m_nVolume, (int8)m_asActiveSamples[j].m_nVolume, 10);
+#endif
+ emittingVol = m_bDoubleVolume ? 2 * Min(63, vol) : vol;
+
+ isPhoneCall = FALSE;
+ for (int32 k = 0; k < MISSION_AUDIO_SLOTS; k++) {
+ if (m_bIsMissionAudioPhoneCall[k]) {
+ isPhoneCall = TRUE;
+ break;
+ }
+ }
+ if (isPhoneCall) {
+ emittingVol = (emittingVol * m_nGlobalSfxVolumeMultiplier) / 127;
+ } else {
+ if (m_nGlobalSfxVolumeMultiplier < 127)
+ emittingVol = (emittingVol * m_nGlobalSfxVolumeMultiplier) / 127;
+ }
+
+#ifdef EXTERNAL_3D_SOUND
+ SampleManager.SetChannelEmittingVolume(j, emittingVol);
+ m_asActiveSamples[j].m_nEmittingVolume = vol;
+#else
+ SampleManager.SetChannelVolume(j, emittingVol);
m_asActiveSamples[j].m_nVolume = vol;
- }
- SampleManager.SetChannelVolume(j, m_bDoubleVolume ? 2 * Min(63, vol) : vol);
#endif
+ }
TranslateEntity(&sample.m_vecPos, &position);
#ifdef EXTERNAL_3D_SOUND
SampleManager.SetChannel3DPosition(j, position.x, position.y, position.z);
@@ -1043,11 +1202,14 @@ cAudioManager::ProcessActiveQueues()
SampleManager.SetChannelPan(j, sample.m_nPan);
#endif
}
+#if !defined(GTA_PS2) || defined(AUDIO_REVERB)
SampleManager.SetChannelReverbFlag(j, sample.m_bReverb);
- break;
+#endif
+ break; //continue for i
}
sample.m_bIsBeingPlayed = FALSE;
m_asActiveSamples[j].m_bIsBeingPlayed = FALSE;
+ //continue for j
}
}
}
@@ -1070,7 +1232,8 @@ cAudioManager::ProcessActiveQueues()
#endif
{
for (uint8 j = 0; j < m_nActiveSamples; j++) {
- if (!m_asActiveSamples[j].m_bIsBeingPlayed) {
+ uint8 k = (j + m_nChannelOffset) % m_nActiveSamples;
+ if (!m_asActiveSamples[k].m_bIsBeingPlayed) {
if (sample.m_nLoopCount > 0) {
samplesPerFrame = sample.m_nFrequency / m_nTimeSpent;
samplesToPlay = sample.m_nLoopCount * SampleManager.GetSampleLength(sample.m_nSampleIndex);
@@ -1078,9 +1241,9 @@ cAudioManager::ProcessActiveQueues()
continue;
sample.m_nFramesToPlay = samplesToPlay / samplesPerFrame + 1;
}
- memcpy(&m_asActiveSamples[j], &sample, sizeof(tSound));
- if (!m_asActiveSamples[j].m_bIs2D) {
- TranslateEntity(&m_asActiveSamples[j].m_vecPos, &position);
+ memcpy(&m_asActiveSamples[k], &sample, sizeof(tSound));
+ if (!m_asActiveSamples[k].m_bIs2D) {
+ TranslateEntity(&m_asActiveSamples[k].m_vecPos, &position);
#ifndef EXTERNAL_3D_SOUND
m_asActiveSamples[j].m_nPan = ComputePan(m_asActiveSamples[j].m_fDistance, &position);
#endif
@@ -1088,50 +1251,67 @@ cAudioManager::ProcessActiveQueues()
emittingVol = m_bDoubleVolume ? 2 * Min(63, m_asActiveSamples[j].WORKING_VOLUME_FIELD) : m_asActiveSamples[j].WORKING_VOLUME_FIELD;
#ifdef GTA_PS2
{
- SampleManager.InitialiseChannel(j, m_asActiveSamples[j].m_nSampleIndex, m_asActiveSamples[j].m_nBankIndex);
+ SampleManager.InitialiseChannel(k, m_asActiveSamples[k].m_nSampleIndex, m_asActiveSamples[k].m_nBankIndex);
#else
- if (SampleManager.InitialiseChannel(j, m_asActiveSamples[j].m_nSampleIndex, m_asActiveSamples[j].m_nBankIndex)) {
+ if (SampleManager.InitialiseChannel(k, m_asActiveSamples[k].m_nSampleIndex, m_asActiveSamples[k].m_nBankIndex)) {
#endif
#ifdef USE_TIME_SCALE_FOR_AUDIO
- SampleManager.SetChannelFrequency(j, m_asActiveSamples[j].m_nFrequency * timeScale);
+ SampleManager.SetChannelFrequency(k, m_asActiveSamples[k].m_nFrequency * timeScale);
#else
- SampleManager.SetChannelFrequency(j, m_asActiveSamples[j].m_nFrequency);
+ SampleManager.SetChannelFrequency(k, m_asActiveSamples[k].m_nFrequency);
#endif
+ isPhoneCall = FALSE;
+ for (int32 l = 0; l < MISSION_AUDIO_SLOTS; l++) {
+ if (m_bIsMissionAudioPhoneCall[l]) {
+ isPhoneCall = TRUE;
+ break;
+ }
+ }
+ if (!isPhoneCall || m_asActiveSamples[k].m_bIs2D) {
+ if (m_nGlobalSfxVolumeMultiplier < 127)
+ emittingVol = (emittingVol * m_nGlobalSfxVolumeMultiplier) / 127;
+ vol = emittingVol;
+ } else {
+ vol = (emittingVol * m_nGlobalSfxVolumeMultiplier) / 127;
+ }
#ifdef EXTERNAL_3D_SOUND
- SampleManager.SetChannelEmittingVolume(j, emittingVol);
+ SampleManager.SetChannelEmittingVolume(k, vol);
#else
SampleManager.SetChannelVolume(j, emittingVol);
SampleManager.SetChannelPan(j, m_asActiveSamples[j].m_nPan);
#endif
#ifndef GTA_PS2
- SampleManager.SetChannelLoopPoints(j, m_asActiveSamples[j].m_nLoopStart, m_asActiveSamples[j].m_nLoopEnd);
+ SampleManager.SetChannelLoopPoints(k, m_asActiveSamples[k].m_nLoopStart, m_asActiveSamples[k].m_nLoopEnd);
+#endif
+ SampleManager.SetChannelLoopCount(k, m_asActiveSamples[k].m_nLoopCount);
+#if !defined(GTA_PS2) || defined(AUDIO_REVERB)
+ SampleManager.SetChannelReverbFlag(k, m_asActiveSamples[k].m_bReverb);
#endif
- SampleManager.SetChannelLoopCount(j, m_asActiveSamples[j].m_nLoopCount);
- SampleManager.SetChannelReverbFlag(j, m_asActiveSamples[j].m_bReverb);
#ifdef EXTERNAL_3D_SOUND
- if (m_asActiveSamples[j].m_bIs2D) {
- uint8 offset = m_asActiveSamples[j].m_nPan;
+ if (m_asActiveSamples[k].m_bIs2D) {
+ uint8 offset = m_asActiveSamples[k].m_nPan;
if (offset == 63)
- x = 0.f;
+ x = 0.0f;
else if (offset >= 63)
x = (offset - 63) * 1000.0f / 63;
else
- x = -(63 - offset) * 1000.0f / 63;
+ x = -(63 - offset) * 1000.0f / 63; //same like line below
usedX = x;
usedY = 0.0f;
usedZ = 0.0f;
- m_asActiveSamples[j].m_MaxDistance = 100000.0f;
+ m_asActiveSamples[k].m_MaxDistance = 100000.0f;
} else {
usedX = position.x;
usedY = position.y;
usedZ = position.z;
}
- SampleManager.SetChannel3DPosition(j, usedX, usedY, usedZ);
- SampleManager.SetChannel3DDistances(j, m_asActiveSamples[j].m_MaxDistance, 0.25f * m_asActiveSamples[j].m_MaxDistance);
+ SampleManager.SetChannel3DPosition(k, usedX, usedY, usedZ);
+ SampleManager.SetChannel3DDistances(k, m_asActiveSamples[k].m_MaxDistance, 0.25f * m_asActiveSamples[k].m_MaxDistance);
#endif
- SampleManager.StartChannel(j);
+ SampleManager.StartChannel(k);
}
- m_asActiveSamples[j].m_bIsBeingPlayed = TRUE;
+ m_asActiveSamples[k].m_bIsBeingPlayed = TRUE;
+ channelOffset++;
sample.m_bIsBeingPlayed = TRUE;
sample.m_nVolumeChange = -1;
break;
@@ -1141,6 +1321,11 @@ cAudioManager::ProcessActiveQueues()
}
}
+#ifdef GTA_PS2
+ m_nChannelOffset += channelOffset;
+#endif
+ m_nChannelOffset %= m_nActiveSamples;
+
#ifdef USE_TIME_SCALE_FOR_AUDIO
for (uint8 i = 0; i < m_nActiveSamples; i++) {
if (m_asActiveSamples[i].m_nSampleIndex != NO_SAMPLE && m_asActiveSamples[i].m_bIsBeingPlayed)
@@ -1148,7 +1333,7 @@ cAudioManager::ProcessActiveQueues()
}
#endif
- #undef WORKING_VOLUME_FIELD
+#undef WORKING_VOLUME_FIELD
}
void
@@ -1187,18 +1372,17 @@ cAudioManager::ClearActiveSamples()
m_asActiveSamples[i].m_MaxDistance = 200.0f;
m_asActiveSamples[i].m_nPan = 63;
m_asActiveSamples[i].m_bStatic = FALSE;
-#if GTA_VERSION < GTA3_PC_10
- m_asActiveSamples[i].unk = -3;
-#endif
m_asActiveSamples[i].m_nFinalPriority = 0;
m_asActiveSamples[i].m_nFramesToPlay = 0;
m_asActiveSamples[i].m_nVolumeChange = -1;
m_asActiveSamples[i].m_vecPos = CVector(0.0f, 0.0f, 0.0f);
+#ifdef AUDIO_REVERB
m_asActiveSamples[i].m_bReverb = FALSE;
+#endif // AUDIO_REVERB
#ifdef AUDIO_REFLECTIONS
m_asActiveSamples[i].m_nReflectionDelay = 0;
m_asActiveSamples[i].m_bReflections = FALSE;
-#endif
+#endif // AUDIO_REFLECTIONS
}
}