mirror of
https://gitlab.com/GaryOderNichts/re3-wiiu.git
synced 2024-11-25 10:36:53 +01:00
Audio refactoring:
* renamed tSound fields, added descriptions for each field * getting rid of term 'intensity' in favour of 'max distance' * renamed two cAudioManager fields * fix volume not being reduced for stopping sounds that are looped * reverse a few PS2 bits
This commit is contained in:
parent
0e5ffb8c34
commit
c168786b42
@ -261,14 +261,14 @@ cAudioManager::SetUpOneShotCollisionSound(const cAudioCollision &col)
|
||||
m_sQueueSample.m_vecPos = col.m_vecPosition;
|
||||
m_sQueueSample.m_nBankIndex = SFX_BANK_0;
|
||||
m_sQueueSample.m_bIs2D = FALSE;
|
||||
m_sQueueSample.m_nReleasingVolumeModificator = 11;
|
||||
m_sQueueSample.m_nPriority = 11;
|
||||
m_sQueueSample.m_nLoopCount = 1;
|
||||
SET_EMITTING_VOLUME(emittingVol);
|
||||
RESET_LOOP_OFFSETS
|
||||
m_sQueueSample.m_fSpeedMultiplier = 4.0f;
|
||||
m_sQueueSample.m_SoundIntensity = CollisionSoundIntensity;
|
||||
m_sQueueSample.m_bReleasingSoundFlag = TRUE;
|
||||
m_sQueueSample.m_bReverbFlag = TRUE;
|
||||
m_sQueueSample.m_MaxDistance = CollisionSoundIntensity;
|
||||
m_sQueueSample.m_bStatic = TRUE;
|
||||
m_sQueueSample.m_bReverb = TRUE;
|
||||
SET_SOUND_REFLECTION(FALSE);
|
||||
AddSampleToRequestedQueue();
|
||||
}
|
||||
@ -290,15 +290,15 @@ cAudioManager::SetUpLoopingCollisionSound(const cAudioCollision &col, uint8 coun
|
||||
m_sQueueSample.m_vecPos = col.m_vecPosition;
|
||||
m_sQueueSample.m_nBankIndex = SFX_BANK_0;
|
||||
m_sQueueSample.m_bIs2D = FALSE;
|
||||
m_sQueueSample.m_nReleasingVolumeModificator = 7;
|
||||
m_sQueueSample.m_nPriority = 7;
|
||||
m_sQueueSample.m_nLoopCount = 0;
|
||||
SET_EMITTING_VOLUME(emittingVol);
|
||||
SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex);
|
||||
m_sQueueSample.m_fSpeedMultiplier = 4.0f;
|
||||
m_sQueueSample.m_SoundIntensity = CollisionSoundIntensity;
|
||||
m_sQueueSample.m_bReleasingSoundFlag = FALSE;
|
||||
m_sQueueSample.m_nReleasingVolumeDivider = 5;
|
||||
m_sQueueSample.m_bReverbFlag = TRUE;
|
||||
m_sQueueSample.m_MaxDistance = CollisionSoundIntensity;
|
||||
m_sQueueSample.m_bStatic = FALSE;
|
||||
m_sQueueSample.m_nFramesToPlay = 5;
|
||||
m_sQueueSample.m_bReverb = TRUE;
|
||||
SET_SOUND_REFLECTION(FALSE);
|
||||
AddSampleToRequestedQueue();
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@ cAudioManager AudioManager;
|
||||
cAudioManager::cAudioManager()
|
||||
{
|
||||
m_bIsInitialised = FALSE;
|
||||
m_bReverb = TRUE;
|
||||
m_bIsSurround = TRUE;
|
||||
m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT;
|
||||
m_nTimeSpent = TIME_SPENT;
|
||||
m_nActiveSamples = NUM_CHANNELS_GENERIC;
|
||||
@ -40,7 +40,7 @@ cAudioManager::cAudioManager()
|
||||
}
|
||||
m_nAudioEntitiesTotal = 0;
|
||||
m_FrameCounter = 0;
|
||||
m_bFifthFrameFlag = FALSE;
|
||||
m_bReduceReleasingPriority = FALSE;
|
||||
m_bTimerJustReset = FALSE;
|
||||
m_nTimer = 0;
|
||||
}
|
||||
@ -473,7 +473,7 @@ cAudioManager::ServiceSoundEffects()
|
||||
#ifdef FIX_BUGS
|
||||
if(CTimer::GetLogicalFramesPassed() != 0)
|
||||
#endif
|
||||
m_bFifthFrameFlag = (m_FrameCounter++ % 5) == 0;
|
||||
m_bReduceReleasingPriority = (m_FrameCounter++ % 5) == 0;
|
||||
if (m_nUserPause && !m_nPreviousUserPause) {
|
||||
for (int32 i = 0; i < NUM_CHANNELS; i++)
|
||||
SampleManager.StopChannel(i);
|
||||
@ -523,14 +523,14 @@ cAudioManager::FL(float f)
|
||||
}
|
||||
|
||||
uint8
|
||||
cAudioManager::ComputeVolume(uint8 emittingVolume, float soundIntensity, float distance)
|
||||
cAudioManager::ComputeVolume(uint8 emittingVolume, float maxDistance, float distance)
|
||||
{
|
||||
float newSoundIntensity;
|
||||
if (soundIntensity <= 0.0f)
|
||||
float minDistance;
|
||||
if (maxDistance <= 0.0f)
|
||||
return 0;
|
||||
newSoundIntensity = soundIntensity / 5.0f;
|
||||
if (newSoundIntensity <= distance)
|
||||
emittingVolume = sq((soundIntensity - newSoundIntensity - (distance - newSoundIntensity)) / (soundIntensity - newSoundIntensity)) * emittingVolume;
|
||||
minDistance = maxDistance / 5.0f;
|
||||
if (minDistance <= distance)
|
||||
emittingVolume = sq((maxDistance - minDistance - (distance - minDistance)) / (maxDistance - minDistance)) * emittingVolume;
|
||||
return emittingVolume;
|
||||
}
|
||||
|
||||
@ -605,39 +605,47 @@ cAudioManager::InterrogateAudioEntities()
|
||||
void
|
||||
cAudioManager::AddSampleToRequestedQueue()
|
||||
{
|
||||
uint32 calculatedVolume;
|
||||
uint32 finalPriority;
|
||||
uint8 sampleIndex;
|
||||
#ifdef AUDIO_REFLECTIONS
|
||||
bool8 bReflections;
|
||||
#endif
|
||||
|
||||
if (m_sQueueSample.m_nSampleIndex < TOTAL_AUDIO_SAMPLES) {
|
||||
calculatedVolume = m_sQueueSample.m_nReleasingVolumeModificator * (MAX_VOLUME - m_sQueueSample.m_nVolume);
|
||||
finalPriority = m_sQueueSample.m_nPriority * (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)
|
||||
if (m_asSamples[m_nActiveSampleQueue][sampleIndex].m_nFinalPriority <= finalPriority)
|
||||
return;
|
||||
} else {
|
||||
++m_SampleRequestQueuesStatus[m_nActiveSampleQueue];
|
||||
}
|
||||
m_sQueueSample.m_nCalculatedVolume = calculatedVolume;
|
||||
m_sQueueSample.m_bLoopEnded = FALSE;
|
||||
#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) {
|
||||
m_sQueueSample.m_bRequireReflection = FALSE;
|
||||
m_sQueueSample.m_nLoopsRemaining = 0;
|
||||
m_sQueueSample.m_bReflections = FALSE;
|
||||
m_sQueueSample.m_nReflectionDelay = 0;
|
||||
}
|
||||
if (m_bDynamicAcousticModelingStatus && m_sQueueSample.m_nLoopCount > 0) {
|
||||
bReflections = m_sQueueSample.m_bRequireReflection;
|
||||
bReflections = m_sQueueSample.m_bReflections;
|
||||
} else {
|
||||
bReflections = FALSE;
|
||||
m_sQueueSample.m_nLoopsRemaining = 0;
|
||||
m_sQueueSample.m_nReflectionDelay = 0;
|
||||
}
|
||||
m_sQueueSample.m_bRequireReflection = FALSE;
|
||||
m_sQueueSample.m_bReflections = FALSE;
|
||||
|
||||
if (!m_bDynamicAcousticModelingStatus)
|
||||
m_sQueueSample.m_bReverbFlag = FALSE;
|
||||
m_sQueueSample.m_bReverb = FALSE;
|
||||
#endif
|
||||
|
||||
m_asSamples[m_nActiveSampleQueue][sampleIndex] = m_sQueueSample;
|
||||
@ -656,8 +664,8 @@ cAudioManager::AddDetailsToRequestedOrderList(uint8 sample)
|
||||
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)
|
||||
if (m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]].m_nFinalPriority >
|
||||
m_asSamples[m_nActiveSampleQueue][sample].m_nFinalPriority)
|
||||
break;
|
||||
}
|
||||
if (i < sample) {
|
||||
@ -677,12 +685,12 @@ cAudioManager::AddReflectionsToRequestedQueue()
|
||||
|
||||
for (uint32 i = 0; i < ARRAY_SIZE(m_afReflectionsDistances); i++) {
|
||||
reflectionDistance = m_afReflectionsDistances[i];
|
||||
if (reflectionDistance > 0.0f && reflectionDistance < 100.f && reflectionDistance < m_sQueueSample.m_SoundIntensity) {
|
||||
m_sQueueSample.m_nLoopsRemaining = (reflectionDistance * 500.f / 1029.f);
|
||||
if (m_sQueueSample.m_nLoopsRemaining > 5) {
|
||||
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_fDistance = m_afReflectionsDistances[i];
|
||||
SET_EMITTING_VOLUME(emittingVolume);
|
||||
m_sQueueSample.m_nVolume = ComputeVolume(emittingVolume, m_sQueueSample.m_SoundIntensity, m_sQueueSample.m_fDistance);
|
||||
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;
|
||||
if (m_sQueueSample.m_nLoopCount > 0) {
|
||||
@ -692,7 +700,7 @@ cAudioManager::AddReflectionsToRequestedQueue()
|
||||
else
|
||||
m_sQueueSample.m_nFrequency += noise;
|
||||
}
|
||||
m_sQueueSample.m_nReleasingVolumeModificator += 20;
|
||||
m_sQueueSample.m_nPriority += 20;
|
||||
m_sQueueSample.m_vecPos = m_avecReflectionsPos[i];
|
||||
AddSampleToRequestedQueue();
|
||||
}
|
||||
@ -766,7 +774,7 @@ cAudioManager::AddReleasingSounds()
|
||||
|
||||
for (int32 i = 0; i < m_SampleRequestQueuesStatus[queue]; i++) {
|
||||
tSound &sample = m_asSamples[queue][m_abSampleQueueIndexTable[queue][i]];
|
||||
if (sample.m_bLoopEnded)
|
||||
if (sample.m_bIsPlayingFinished)
|
||||
continue;
|
||||
|
||||
toProcess[i] = FALSE;
|
||||
@ -779,32 +787,44 @@ cAudioManager::AddReleasingSounds()
|
||||
}
|
||||
if (!toProcess[i]) {
|
||||
#ifdef AUDIO_REFLECTIONS
|
||||
if (sample.m_nCounter <= 255 || sample.m_nLoopsRemaining == 0) // check if not reflection
|
||||
if (sample.m_nCounter <= 255 || sample.m_nReflectionDelay == 0) // check if not delayed reflection
|
||||
#endif
|
||||
{
|
||||
if (sample.m_nReleasingVolumeDivider == 0)
|
||||
if (sample.m_nFramesToPlay == 0)
|
||||
continue;
|
||||
if (sample.m_nLoopCount == 0) {
|
||||
if (sample.m_nVolumeChange == -1) {
|
||||
sample.m_nVolumeChange = sample.m_nVolume / sample.m_nReleasingVolumeDivider;
|
||||
#if defined(FIX_BUGS) && defined(EXTERNAL_3D_SOUND)
|
||||
sample.m_nVolumeChange = sample.m_nEmittingVolume / sample.m_nFramesToPlay;
|
||||
#else
|
||||
sample.m_nVolumeChange = sample.m_nVolume / sample.m_nFramesToPlay;
|
||||
#endif
|
||||
if (sample.m_nVolumeChange <= 0)
|
||||
sample.m_nVolumeChange = 1;
|
||||
}
|
||||
#if defined(FIX_BUGS) && defined(EXTERNAL_3D_SOUND)
|
||||
if (sample.m_nEmittingVolume <= sample.m_nVolumeChange) {
|
||||
#else
|
||||
if (sample.m_nVolume <= sample.m_nVolumeChange) {
|
||||
sample.m_nReleasingVolumeDivider = 0;
|
||||
#endif
|
||||
sample.m_nFramesToPlay = 0;
|
||||
continue;
|
||||
}
|
||||
#if defined(FIX_BUGS) && defined(EXTERNAL_3D_SOUND)
|
||||
sample.m_nEmittingVolume -= sample.m_nVolumeChange;
|
||||
#else
|
||||
sample.m_nVolume -= sample.m_nVolumeChange;
|
||||
#endif
|
||||
}
|
||||
#ifdef FIX_BUGS
|
||||
if(CTimer::GetLogicalFramesPassed() != 0)
|
||||
#endif
|
||||
--sample.m_nReleasingVolumeDivider;
|
||||
if (m_bFifthFrameFlag) {
|
||||
if (sample.m_nReleasingVolumeModificator < 20)
|
||||
++sample.m_nReleasingVolumeModificator;
|
||||
--sample.m_nFramesToPlay;
|
||||
if (m_bReduceReleasingPriority) {
|
||||
if (sample.m_nPriority < 20)
|
||||
++sample.m_nPriority;
|
||||
}
|
||||
sample.m_bReleasingSoundFlag = 0;
|
||||
sample.m_bStatic = FALSE;
|
||||
}
|
||||
memcpy(&m_sQueueSample, &sample, sizeof(tSound));
|
||||
AddSampleToRequestedQueue();
|
||||
@ -834,8 +854,8 @@ cAudioManager::ProcessActiveQueues()
|
||||
CVector position;
|
||||
|
||||
for (int32 i = 0; i < m_nActiveSamples; i++) {
|
||||
m_asSamples[m_nActiveSampleQueue][i].m_bIsProcessed = FALSE;
|
||||
m_asActiveSamples[i].m_bIsProcessed = FALSE;
|
||||
m_asSamples[m_nActiveSampleQueue][i].m_bIsBeingPlayed = FALSE;
|
||||
m_asActiveSamples[i].m_bIsBeingPlayed = FALSE;
|
||||
}
|
||||
|
||||
for (int32 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) {
|
||||
@ -845,23 +865,30 @@ cAudioManager::ProcessActiveQueues()
|
||||
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) {
|
||||
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)) {
|
||||
sample.m_bLoopEnded = TRUE;
|
||||
m_asActiveSamples[j].m_bLoopEnded = TRUE;
|
||||
#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;
|
||||
}
|
||||
}
|
||||
sample.m_bIsProcessed = TRUE;
|
||||
m_asActiveSamples[j].m_bIsProcessed = TRUE;
|
||||
sample.m_bIsBeingPlayed = TRUE;
|
||||
m_asActiveSamples[j].m_bIsBeingPlayed = TRUE;
|
||||
sample.m_nVolumeChange = -1;
|
||||
if (!sample.m_bReleasingSoundFlag) {
|
||||
if (!sample.m_bStatic) {
|
||||
if (sample.m_bIs2D) {
|
||||
#ifdef EXTERNAL_3D_SOUND
|
||||
emittingVol = m_bDoubleVolume ? 2 * Min(63, sample.m_nEmittingVolume) : sample.m_nEmittingVolume;
|
||||
@ -872,7 +899,7 @@ cAudioManager::ProcessActiveQueues()
|
||||
#ifdef EXTERNAL_3D_SOUND
|
||||
SampleManager.SetChannelEmittingVolume(j, emittingVol);
|
||||
#else
|
||||
SampleManager.SetChannelPan(j, sample.m_nOffset);
|
||||
SampleManager.SetChannelPan(j, sample.m_nPan);
|
||||
SampleManager.SetChannelVolume(j, sample.m_nVolume);
|
||||
#endif
|
||||
} else {
|
||||
@ -902,23 +929,23 @@ cAudioManager::ProcessActiveQueues()
|
||||
TranslateEntity(&sample.m_vecPos, &position);
|
||||
#ifdef EXTERNAL_3D_SOUND
|
||||
SampleManager.SetChannel3DPosition(j, position.x, position.y, position.z);
|
||||
SampleManager.SetChannel3DDistances(j, sample.m_SoundIntensity, 0.25f * sample.m_SoundIntensity);
|
||||
SampleManager.SetChannel3DDistances(j, sample.m_MaxDistance, 0.25f * sample.m_MaxDistance);
|
||||
#else
|
||||
sample.m_nOffset = ComputePan(sample.m_fDistance, &position);
|
||||
SampleManager.SetChannelPan(j, sample.m_nOffset);
|
||||
sample.m_nPan = ComputePan(sample.m_fDistance, &position);
|
||||
SampleManager.SetChannelPan(j, sample.m_nPan);
|
||||
#endif
|
||||
}
|
||||
SampleManager.SetChannelReverbFlag(j, sample.m_bReverbFlag);
|
||||
SampleManager.SetChannelReverbFlag(j, sample.m_bReverb);
|
||||
break;
|
||||
}
|
||||
sample.m_bIsProcessed = FALSE;
|
||||
m_asActiveSamples[j].m_bIsProcessed = FALSE;
|
||||
sample.m_bIsBeingPlayed = FALSE;
|
||||
m_asActiveSamples[j].m_bIsBeingPlayed = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int32 i = 0; i < m_nActiveSamples; i++) {
|
||||
if (m_asActiveSamples[i].m_nSampleIndex != NO_SAMPLE && !m_asActiveSamples[i].m_bIsProcessed) {
|
||||
if (m_asActiveSamples[i].m_nSampleIndex != NO_SAMPLE && !m_asActiveSamples[i].m_bIsBeingPlayed) {
|
||||
SampleManager.StopChannel(i);
|
||||
m_asActiveSamples[i].m_nSampleIndex = NO_SAMPLE;
|
||||
m_asActiveSamples[i].m_nEntityIndex = AEHANDLE_NONE;
|
||||
@ -926,28 +953,28 @@ cAudioManager::ProcessActiveQueues()
|
||||
}
|
||||
for (uint8 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) {
|
||||
tSound &sample = m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]];
|
||||
if (!sample.m_bIsProcessed && !sample.m_bLoopEnded && m_asAudioEntities[sample.m_nEntityIndex].m_bIsUsed && sample.m_nSampleIndex < NO_SAMPLE) {
|
||||
if (!sample.m_bIsBeingPlayed && !sample.m_bIsPlayingFinished && m_asAudioEntities[sample.m_nEntityIndex].m_bIsUsed && sample.m_nSampleIndex < NO_SAMPLE) {
|
||||
#ifdef AUDIO_REFLECTIONS
|
||||
if (sample.m_nCounter > 255 && sample.m_nLoopCount > 0 && sample.m_nLoopsRemaining > 0) { // check if reflection
|
||||
sample.m_nLoopsRemaining--;
|
||||
sample.m_nReleasingVolumeDivider = 1;
|
||||
if (sample.m_nCounter > 255 && sample.m_nLoopCount > 0 && sample.m_nReflectionDelay > 0) { // check if reflection
|
||||
sample.m_nReflectionDelay--;
|
||||
sample.m_nFramesToPlay = 1;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
for (uint8 j = 0; j < m_nActiveSamples; j++) {
|
||||
if (!m_asActiveSamples[j].m_bIsProcessed) {
|
||||
if (!m_asActiveSamples[j].m_bIsBeingPlayed) {
|
||||
if (sample.m_nLoopCount > 0) {
|
||||
samplesPerFrame = sample.m_nFrequency / m_nTimeSpent;
|
||||
samplesToPlay = sample.m_nLoopCount * SampleManager.GetSampleLength(sample.m_nSampleIndex);
|
||||
if (samplesPerFrame == 0)
|
||||
continue;
|
||||
sample.m_nReleasingVolumeDivider = samplesToPlay / samplesPerFrame + 1;
|
||||
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);
|
||||
#ifndef EXTERNAL_3D_SOUND
|
||||
m_asActiveSamples[j].m_nOffset = ComputePan(m_asActiveSamples[j].m_fDistance, &position);
|
||||
m_asActiveSamples[j].m_nPan = ComputePan(m_asActiveSamples[j].m_fDistance, &position);
|
||||
#endif
|
||||
}
|
||||
#ifdef EXTERNAL_3D_SOUND
|
||||
@ -966,16 +993,16 @@ cAudioManager::ProcessActiveQueues()
|
||||
SampleManager.SetChannelEmittingVolume(j, emittingVol);
|
||||
#else
|
||||
SampleManager.SetChannelVolume(j, emittingVol);
|
||||
SampleManager.SetChannelPan(j, m_asActiveSamples[j].m_nOffset);
|
||||
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.SetChannelLoopCount(j, m_asActiveSamples[j].m_nLoopCount);
|
||||
#endif
|
||||
SampleManager.SetChannelReverbFlag(j, m_asActiveSamples[j].m_bReverbFlag);
|
||||
SampleManager.SetChannelReverbFlag(j, m_asActiveSamples[j].m_bReverb);
|
||||
#ifdef EXTERNAL_3D_SOUND
|
||||
if (m_asActiveSamples[j].m_bIs2D) {
|
||||
uint8 offset = m_asActiveSamples[j].m_nOffset;
|
||||
uint8 offset = m_asActiveSamples[j].m_nPan;
|
||||
if (offset == 63)
|
||||
x = 0.f;
|
||||
else if (offset >= 63)
|
||||
@ -985,19 +1012,19 @@ cAudioManager::ProcessActiveQueues()
|
||||
usedX = x;
|
||||
usedY = 0.0f;
|
||||
usedZ = 0.0f;
|
||||
m_asActiveSamples[j].m_SoundIntensity = 100000.0f;
|
||||
m_asActiveSamples[j].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_SoundIntensity, 0.25f * m_asActiveSamples[j].m_SoundIntensity);
|
||||
SampleManager.SetChannel3DDistances(j, m_asActiveSamples[j].m_MaxDistance, 0.25f * m_asActiveSamples[j].m_MaxDistance);
|
||||
#endif
|
||||
SampleManager.StartChannel(j);
|
||||
}
|
||||
m_asActiveSamples[j].m_bIsProcessed = TRUE;
|
||||
sample.m_bIsProcessed = TRUE;
|
||||
m_asActiveSamples[j].m_bIsBeingPlayed = TRUE;
|
||||
sample.m_bIsBeingPlayed = TRUE;
|
||||
sample.m_nVolumeChange = -1;
|
||||
break;
|
||||
}
|
||||
@ -1025,35 +1052,35 @@ cAudioManager::ClearActiveSamples()
|
||||
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_nPriority = 5;
|
||||
m_asActiveSamples[i].m_nFrequency = 0;
|
||||
m_asActiveSamples[i].m_nVolume = 0;
|
||||
#ifdef EXTERNAL_3D_SOUND
|
||||
m_asActiveSamples[i].m_nEmittingVolume = 0;
|
||||
#endif
|
||||
m_asActiveSamples[i].m_fDistance = 0.0f;
|
||||
m_asActiveSamples[i].m_bIsProcessed = FALSE;
|
||||
m_asActiveSamples[i].m_bLoopEnded = FALSE;
|
||||
m_asActiveSamples[i].m_bIsBeingPlayed = FALSE;
|
||||
m_asActiveSamples[i].m_bIsPlayingFinished = FALSE;
|
||||
m_asActiveSamples[i].m_nLoopCount = 1;
|
||||
#ifndef GTA_PS2
|
||||
m_asActiveSamples[i].m_nLoopStart = 0;
|
||||
m_asActiveSamples[i].m_nLoopEnd = -1;
|
||||
#endif
|
||||
m_asActiveSamples[i].m_fSpeedMultiplier = 0.0f;
|
||||
m_asActiveSamples[i].m_SoundIntensity = 200.0f;
|
||||
m_asActiveSamples[i].m_nOffset = 63;
|
||||
m_asActiveSamples[i].m_bReleasingSoundFlag = FALSE;
|
||||
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_nCalculatedVolume = 0;
|
||||
m_asActiveSamples[i].m_nReleasingVolumeDivider = 0;
|
||||
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);
|
||||
m_asActiveSamples[i].m_bReverbFlag = FALSE;
|
||||
m_asActiveSamples[i].m_bReverb = FALSE;
|
||||
#ifdef AUDIO_REFLECTIONS
|
||||
m_asActiveSamples[i].m_nLoopsRemaining = 0;
|
||||
m_asActiveSamples[i].m_bRequireReflection = FALSE;
|
||||
m_asActiveSamples[i].m_nReflectionDelay = 0;
|
||||
m_asActiveSamples[i].m_bReflections = FALSE;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -1081,7 +1108,7 @@ cAudioManager::AdjustSamplesVolume()
|
||||
tSound *pSample = &m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]];
|
||||
|
||||
if (!pSample->m_bIs2D)
|
||||
pSample->m_nEmittingVolume = ComputeEmittingVolume(pSample->m_nEmittingVolume, pSample->m_SoundIntensity, pSample->m_fDistance);
|
||||
pSample->m_nEmittingVolume = ComputeEmittingVolume(pSample->m_nEmittingVolume, pSample->m_MaxDistance, pSample->m_fDistance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,49 +7,59 @@
|
||||
class tSound
|
||||
{
|
||||
public:
|
||||
int32 m_nEntityIndex;
|
||||
int32 m_nEntityIndex; // audio entity index
|
||||
#if GTA_VERSION >= GTA3_PC_10
|
||||
uint32 m_nCounter;
|
||||
uint32 m_nCounter; // I'm not sure what this is but it looks like a virtual counter to determine the same sound in queue
|
||||
// Values higher than 255 are used by reflections
|
||||
#else
|
||||
uint8 m_nCounter;
|
||||
#endif
|
||||
uint32 m_nSampleIndex;
|
||||
uint8 m_nBankIndex;
|
||||
bool8 m_bIs2D;
|
||||
uint32 m_nReleasingVolumeModificator;
|
||||
uint32 m_nFrequency;
|
||||
uint8 m_nVolume;
|
||||
float m_fDistance;
|
||||
uint32 m_nLoopCount;
|
||||
uint32 m_nSampleIndex; // An index of sample from AudioSamples.h
|
||||
uint8 m_nBankIndex; // A sound bank index. IDK what's the point of it here since samples are hardcoded anyway
|
||||
bool8 m_bIs2D; // If TRUE then sound is played in 2D space (such as frontend or police radio)
|
||||
uint32 m_nPriority; // The multiplier for the sound priority (see m_nFinalPriority below). Lesser value means higher priority
|
||||
uint32 m_nFrequency; // Sound frequency, plain and simple
|
||||
uint8 m_nVolume; // Sound volume (0..127), only used as an actual volume without EXTERNAL_3D_SOUND (see m_nEmittingVolume)
|
||||
float m_fDistance; // Distance to camera (useless if m_bIs2D == TRUE)
|
||||
uint32 m_nLoopCount; // 0 - always loop, 1 - don't loop, other values never seen
|
||||
#ifndef GTA_PS2
|
||||
// Loop offsets
|
||||
uint32 m_nLoopStart;
|
||||
int32 m_nLoopEnd;
|
||||
#endif
|
||||
#ifdef EXTERNAL_3D_SOUND
|
||||
uint8 m_nEmittingVolume;
|
||||
uint8 m_nEmittingVolume; // The volume in 3D space, provided to 3D audio engine
|
||||
#endif
|
||||
float m_fSpeedMultiplier;
|
||||
float m_fSpeedMultiplier; // Used for doppler effect. 0.0f - unaffected by doppler
|
||||
#if GTA_VERSION >= GTA3_PC_10
|
||||
float m_SoundIntensity;
|
||||
float m_MaxDistance; // The maximum distance at which sound could be heard. Minimum distance = MaxDistance / 5 or MaxDistance / 4 in case of emitting volume (useless if m_bIs2D == TRUE)
|
||||
#else
|
||||
uint32 m_SoundIntensity;
|
||||
uint32 m_MaxDistance;
|
||||
#endif
|
||||
bool8 m_bReleasingSoundFlag;
|
||||
CVector m_vecPos;
|
||||
bool8 m_bReverbFlag;
|
||||
bool8 m_bStatic; // If TRUE then sound parameters cannot be changed during playback (frequency, position, etc.)
|
||||
CVector m_vecPos; // Position of sound in 3D space. Unused if m_bIs2D == TRUE
|
||||
bool8 m_bReverb; // Toggles reverb effect
|
||||
#ifdef AUDIO_REFLECTIONS
|
||||
uint8 m_nLoopsRemaining;
|
||||
bool8 m_bRequireReflection; // Used for oneshots
|
||||
uint8 m_nReflectionDelay; // Number of frames before reflection could be played. This is calculated internally by AudioManager and shouldn't be set by queued sample
|
||||
bool8 m_bReflections; // Add sound reflections
|
||||
#endif
|
||||
uint8 m_nOffset;
|
||||
uint32 m_nReleasingVolumeDivider;
|
||||
bool8 m_bIsProcessed;
|
||||
bool8 m_bLoopEnded;
|
||||
uint8 m_nPan; // Sound panning (0-127). Controls the volume of the playback coming from left and right speaker. Calculated internally unless m_bIs2D==TRUE.
|
||||
// 0 = L 100% R 0%
|
||||
// 63 = L 100% R 100%
|
||||
// 127 = L 0% R 100%
|
||||
uint32 m_nFramesToPlay; // Number of frames the sound would be played (if it stops being queued).
|
||||
// This one is being set by queued sample for looping sounds, otherwise calculated inside AudioManager
|
||||
|
||||
// all fields below are internal to AudioManager calculations and aren't set by queued sample
|
||||
bool8 m_bIsBeingPlayed; // Set to TRUE when the sound was added or changed on current frame to avoid it being overwritten
|
||||
bool8 m_bIsPlayingFinished; // Not sure about the name. Set to TRUE when sampman channel becomes free
|
||||
#if GTA_VERSION < GTA3_PC_10
|
||||
int32 unk; // only on PS2, seems unused
|
||||
int32 unk; // Only on PS2, used by static non-looped sounds (AFAIK)
|
||||
// Looks like it's keeping a number of frames left to play with the purpose of setting m_bIsPlayingFinished=TRUE once value reaches 0
|
||||
// Default value is -3 for whatever reason
|
||||
#endif
|
||||
uint32 m_nCalculatedVolume;
|
||||
int8 m_nVolumeChange;
|
||||
uint32 m_nFinalPriority; // Actual value used to compare priority, calculated using volume and m_nPriority. Lesser value means higher priority
|
||||
int8 m_nVolumeChange; // How much m_nVolume should reduce per each frame. Has no effect with EXTERNAL_3D_SOUND
|
||||
};
|
||||
|
||||
VALIDATE_SIZE(tSound, 92);
|
||||
@ -208,8 +218,8 @@ class cAudioManager
|
||||
{
|
||||
public:
|
||||
bool8 m_bIsInitialised;
|
||||
bool8 m_bReverb; // unused
|
||||
bool8 m_bFifthFrameFlag;
|
||||
bool8 m_bIsSurround; // unused until VC
|
||||
bool8 m_bReduceReleasingPriority;
|
||||
uint8 m_nActiveSamples;
|
||||
bool8 m_bDoubleVolume; // unused
|
||||
#if GTA_VERSION >= GTA3_PC_10
|
||||
@ -288,7 +298,7 @@ public:
|
||||
|
||||
void ServiceSoundEffects();
|
||||
uint32 FL(float f); // not used
|
||||
uint8 ComputeVolume(uint8 emittingVolume, float soundIntensity, float distance);
|
||||
uint8 ComputeVolume(uint8 emittingVolume, float maxDistance, float distance);
|
||||
void TranslateEntity(Const CVector *v1, CVector *v2);
|
||||
int32 ComputePan(float, CVector *);
|
||||
uint32 ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, float speedMultiplier); // inlined on PS2
|
||||
@ -309,7 +319,7 @@ public:
|
||||
|
||||
#ifdef EXTERNAL_3D_SOUND // actually must have been && AUDIO_MSS as well
|
||||
void AdjustSamplesVolume();
|
||||
uint8 ComputeEmittingVolume(uint8 emittingVolume, float intensity, float dist);
|
||||
uint8 ComputeEmittingVolume(uint8 emittingVolume, float maxDistance, float dist);
|
||||
#endif
|
||||
|
||||
// audio logic
|
||||
@ -553,7 +563,7 @@ public:
|
||||
#define SET_EMITTING_VOLUME(vol)
|
||||
#endif
|
||||
#ifdef AUDIO_REFLECTIONS
|
||||
#define SET_SOUND_REFLECTION(b) m_sQueueSample.m_bRequireReflection = b
|
||||
#define SET_SOUND_REFLECTION(b) m_sQueueSample.m_bReflections = b
|
||||
#else
|
||||
#define SET_SOUND_REFLECTION(b)
|
||||
#endif
|
||||
|
@ -129,16 +129,16 @@ cAudioManager::DoPoliceRadioCrackle()
|
||||
m_sQueueSample.m_nSampleIndex = SFX_POLICE_RADIO_CRACKLE;
|
||||
m_sQueueSample.m_nBankIndex = SFX_BANK_0;
|
||||
m_sQueueSample.m_bIs2D = TRUE;
|
||||
m_sQueueSample.m_nReleasingVolumeModificator = 10;
|
||||
m_sQueueSample.m_nPriority = 10;
|
||||
m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_POLICE_RADIO_CRACKLE);
|
||||
m_sQueueSample.m_nVolume = m_anRandomTable[2] % 20 + 15;
|
||||
m_sQueueSample.m_nLoopCount = 0;
|
||||
SET_EMITTING_VOLUME(m_sQueueSample.m_nVolume);
|
||||
SET_LOOP_OFFSETS(SFX_POLICE_RADIO_CRACKLE)
|
||||
m_sQueueSample.m_bReleasingSoundFlag = FALSE;
|
||||
m_sQueueSample.m_bReverbFlag = FALSE;
|
||||
m_sQueueSample.m_nOffset = 63;
|
||||
m_sQueueSample.m_nReleasingVolumeDivider = 3;
|
||||
m_sQueueSample.m_bStatic = FALSE;
|
||||
m_sQueueSample.m_bReverb = FALSE;
|
||||
m_sQueueSample.m_nPan = 63;
|
||||
m_sQueueSample.m_nFramesToPlay = 3;
|
||||
SET_SOUND_REFLECTION(FALSE);
|
||||
AddSampleToRequestedQueue();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user