diff options
Diffstat (limited to 'src/audio/AudioManager.cpp')
-rw-r--r-- | src/audio/AudioManager.cpp | 360 |
1 files changed, 227 insertions, 133 deletions
diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index 868f1b65..d441b750 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -20,7 +20,7 @@ const int allChannels = channels + 2; cAudioManager::cAudioManager() { m_bIsInitialised = false; - field_1 = 1; + m_bReverb = true; m_fSpeedOfSound = 6.86f; m_nTimeSpent = 50; m_nActiveSamples = NUM_SOUNDS_SAMPLES_SLOTS; @@ -169,11 +169,11 @@ cAudioManager::SetEntityStatus(int32 id, uint8 status) 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) { @@ -217,6 +217,12 @@ cAudioManager::PlayOneShot(int32 index, uint16 sound, float vol) } void +cAudioManager::SetMP3BoostVolume(uint8 volume) const +{ + SampleManager.SetMP3BoostVolume(volume); +} + +void cAudioManager::SetEffectsMasterVolume(uint8 volume) const { SampleManager.SetEffectsMasterVolume(volume); @@ -263,11 +269,13 @@ cAudioManager::ResetTimers(uint32 time) m_nActiveSampleQueue = 0; } ClearActiveSamples(); - ClearMissionAudio(); + ClearMissionAudio(0); + ClearMissionAudio(1); SampleManager.StopChannel(policeChannel); SampleManager.SetEffectsFadeVolume(0); SampleManager.SetMusicFadeVolume(0); MusicManager.ResetMusicAfterReload(); + m_bIsPlayerShutUp = false; #ifdef AUDIO_OAL SampleManager.Service(); #endif @@ -286,7 +294,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); @@ -341,6 +349,15 @@ cAudioManager::GetCurrent3DProviderIndex() const } int8 +cAudioManager::AutoDetect3DProviders() const +{ + if (m_bIsInitialised) + return SampleManager.AutoDetect3DProviders(); + + return -1; +} + +int8 cAudioManager::SetCurrent3DProvider(uint8 which) { if (!m_bIsInitialised) @@ -409,9 +426,7 @@ cAudioManager::CheckForAnAudioFileOnCD() const uint8 cAudioManager::GetCDAudioDriveLetter() const { - if (m_bIsInitialised) - return SampleManager.GetCDAudioDriveLetter(); - + if(m_bIsInitialised) return SampleManager.GetCDAudioDriveLetter(); return 0; } @@ -442,7 +457,7 @@ cAudioManager::ServiceSoundEffects() ClearActiveSamples(); } m_nActiveSampleQueue = m_nActiveSampleQueue == 1 ? 0 : 1; - ProcessReverb(); + if(m_bReverb) ProcessReverb(); ProcessSpecial(); ClearRequestedQueue(); InterrogateAudioEntities(); @@ -471,12 +486,18 @@ uint8 cAudioManager::ComputeVolume(uint8 emittingVolume, float soundIntensity, float distance) const { float newSoundIntensity; + float newEmittingVolume; + if (soundIntensity <= 0.0f) return 0; + newSoundIntensity = soundIntensity / 5.0f; - if (newSoundIntensity <= distance) - emittingVolume = sq((soundIntensity - newSoundIntensity - (distance - newSoundIntensity)) / (soundIntensity - newSoundIntensity)) * emittingVolume; - return emittingVolume; + if (newSoundIntensity > distance) + return emittingVolume; + + newEmittingVolume = emittingVolume * SQR((soundIntensity - newSoundIntensity - (distance - newSoundIntensity)) + / (soundIntensity - newSoundIntensity)); + return Min(127u, newEmittingVolume); } void @@ -488,17 +509,16 @@ cAudioManager::TranslateEntity(Const CVector *in, CVector *out) const int32 cAudioManager::ComputePan(float dist, CVector *vec) { - 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(vec->x / (dist / 64.f))); + 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)))); if (vec->x > 0.f) return Max(20, 63 - PanTable[index]); return Min(107, PanTable[index] + 63); } -int32 +uint32 cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, float speedMultiplier) const { uint32 newFreq = oldFreq; @@ -507,11 +527,7 @@ cAudioManager::ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, if (dist != 0.0f) { float speedOfSource = (dist / m_nTimeSpent) * speedMultiplier; if (m_fSpeedOfSound > Abs(speedOfSource)) { - if (speedOfSource < 0.0f) { - speedOfSource = Max(speedOfSource, -1.5f); - } else { - speedOfSource = Min(speedOfSource, 1.5f); - } + speedOfSource = clamp2(speedOfSource, 0.0f, 1.5f); newFreq = (oldFreq * m_fSpeedOfSound) / (speedOfSource + m_fSpeedOfSound); } } @@ -611,26 +627,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 = (m_sQueueSample.m_nVolume / 2) + (m_sQueueSample.m_nVolume / 16); + } + m_sQueueSample.m_fSoundIntensity = m_sQueueSample.m_fSoundIntensity / 2.f; + + int halfOldFreq = oldFreq >> 1; for (uint32 i = 0; i < ARRAY_SIZE(m_afReflectionsDistances); i++) { + 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) { - m_sQueueSample.m_nLoopsRemaining = (reflectionDistance * 500.f / 1029.f); - if (m_sQueueSample.m_nLoopsRemaining > 5) { + 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); + 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) { - 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_nReleasingVolumeModificator += 20; m_sQueueSample.m_vecPos = m_avecReflectionsPos[i]; @@ -639,50 +681,84 @@ cAudioManager::AddReflectionsToRequestedQueue() } } } + m_sQueueSample.m_vecPos = oldPos; + m_sQueueSample.m_fDistance = oldDist; } void cAudioManager::UpdateReflections() { - const CVector &camPos = TheCamera.GetPosition(); + CVector camPos = TheCamera.GetPosition(); CColPoint colpoint; CEntity *ent; if (m_FrameCounter % 8 == 0) { m_avecReflectionsPos[0] = camPos; - m_avecReflectionsPos[0].y += 50.f; + 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] = 50.0f; + m_afReflectionsDistances[0] = 100.0f; + } else if ((m_FrameCounter + 1) % 8 == 0) { m_avecReflectionsPos[1] = camPos; - m_avecReflectionsPos[1].y -= 50.0f; + 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] = 50.0f; + m_afReflectionsDistances[1] = 100.0f; + } else if ((m_FrameCounter + 2) % 8 == 0) { m_avecReflectionsPos[2] = camPos; - m_avecReflectionsPos[2].x -= 50.0f; + 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] = 50.0f; + m_afReflectionsDistances[2] = 100.0f; + } else if ((m_FrameCounter + 3) % 8 == 0) { m_avecReflectionsPos[3] = camPos; - m_avecReflectionsPos[3].x += 50.0f; + 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] = 50.0f; + m_afReflectionsDistances[3] = 100.0f; + } else if ((m_FrameCounter + 4) % 8 == 0) { + camPos.y += 1.0f; m_avecReflectionsPos[4] = camPos; - m_avecReflectionsPos[4].z += 50.0f; + 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] = 50.0f; + 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; } } @@ -727,7 +803,7 @@ cAudioManager::AddReleasingSounds() if (sample.m_nReleasingVolumeModificator < 20) ++sample.m_nReleasingVolumeModificator; } - sample.m_bReleasingSoundFlag = 0; + sample.m_bReleasingSoundFlag = false; } memcpy(&m_sQueueSample, &sample, sizeof(tSound)); AddSampleToRequestedQueue(); @@ -738,39 +814,41 @@ cAudioManager::AddReleasingSounds() void cAudioManager::ProcessActiveQueues() { - bool flag; - float position2; - float position1; - - uint32 v28; - uint32 v29; - - float x; - float usedX; - float usedY; - float usedZ; - - uint8 vol; - uint8 emittingVol; CVector position; + uint32 freqDivided; + uint32 loopCount; + uint8 emittingVol; + uint8 vol; + uint8 offset; + float x; + bool flag; + bool missionState; for (int32 i = 0; i < m_nActiveSamples; i++) { m_asSamples[m_nActiveSampleQueue][i].m_bIsProcessed = false; m_asActiveSamples[i].m_bIsProcessed = false; } - - for (int32 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; ++i) { - tSound &sample = m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]]; + for (int32 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) { + tSound& sample = m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]]; 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) { + 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) { if (sample.m_nLoopCount) { + if (m_FrameCounter & 1) { - flag = !!(j & 1); + if (!(j & 1)) { + flag = false; + } else { + flag = true; + } + } else if (j & 1) { + flag = false; } else { - flag = !(j & 1); + flag = true; } + if (flag && !SampleManager.GetChannelUsedFlag(j)) { sample.m_bLoopEnded = true; m_asActiveSamples[j].m_bLoopEnded = true; @@ -778,6 +856,8 @@ cAudioManager::ProcessActiveQueues() m_asActiveSamples[j].m_nEntityIndex = AEHANDLE_NONE; continue; } + if (!sample.m_nReleasingVolumeDivider) + sample.m_nReleasingVolumeDivider = 1; } sample.m_bIsProcessed = true; m_asActiveSamples[j].m_bIsProcessed = true; @@ -793,37 +873,39 @@ cAudioManager::ProcessActiveQueues() SampleManager.SetChannelEmittingVolume(j, emittingVol); } else { m_asActiveSamples[j].m_fDistance = sample.m_fDistance; - position2 = sample.m_fDistance; - position1 = m_asActiveSamples[j].m_fDistance; - sample.m_nFrequency = ComputeDopplerEffectedFrequency(sample.m_nFrequency, position1, position2, sample.m_fSpeedMultiplier); + sample.m_nFrequency = ComputeDopplerEffectedFrequency( + sample.m_nFrequency, + m_asActiveSamples[j].m_fDistance, + sample.m_fDistance, + sample.m_fSpeedMultiplier); + if (sample.m_nFrequency != m_asActiveSamples[j].m_nFrequency) { - int32 freq; - if (sample.m_nFrequency <= m_asActiveSamples[j].m_nFrequency) { -#ifdef FIX_BUGS - freq = Max((int32)sample.m_nFrequency, (int32)m_asActiveSamples[j].m_nFrequency - 6000); -#else - freq = Max((int32)sample.m_nFrequency, int32(m_asActiveSamples[j].m_nFrequency - 6000)); -#endif - } else { - freq = Min(sample.m_nFrequency, m_asActiveSamples[j].m_nFrequency + 6000); - } - m_asActiveSamples[j].m_nFrequency = freq; - SampleManager.SetChannelFrequency(j, freq); + 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); } - if (sample.m_nEmittingVolume != m_asActiveSamples[j].m_nEmittingVolume) { - if (sample.m_nEmittingVolume <= m_asActiveSamples[j].m_nEmittingVolume) { - vol = Max(m_asActiveSamples[j].m_nEmittingVolume - 10, sample.m_nEmittingVolume); - } else { - vol = Min(m_asActiveSamples[j].m_nEmittingVolume + 10, sample.m_nEmittingVolume); - } + vol = clamp2((int8)sample.m_nEmittingVolume, (int8)m_asActiveSamples[j].m_nEmittingVolume, 10); - uint8 emittingVol; if (field_4) { emittingVol = 2 * Min(63, vol); } else { emittingVol = vol; } + + missionState = false; + for (int32 k = 0; k < ARRAY_SIZE(m_sMissionAudio.m_bIsMobile); k++) { + if (m_sMissionAudio.m_bIsMobile[k]) { + missionState = true; + break; + } + } + if (missionState) { + emittingVol = (emittingVol * field_5538) / 127; + } else { + if (field_5538 < 127) + emittingVol = (emittingVol * field_5538) / 127; + } + SampleManager.SetChannelEmittingVolume(j, emittingVol); m_asActiveSamples[j].m_nEmittingVolume = vol; } @@ -832,10 +914,11 @@ cAudioManager::ProcessActiveQueues() SampleManager.SetChannel3DDistances(j, sample.m_fSoundIntensity, 0.25f * sample.m_fSoundIntensity); } SampleManager.SetChannelReverbFlag(j, sample.m_bReverbFlag); - break; + break; //continue for i } sample.m_bIsProcessed = false; m_asActiveSamples[j].m_bIsProcessed = false; + //continue for j } } } @@ -847,59 +930,69 @@ cAudioManager::ProcessActiveQueues() m_asActiveSamples[i].m_nEntityIndex = AEHANDLE_NONE; } } - 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) { + 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_nCounter > 255 && sample.m_nLoopCount && sample.m_nLoopsRemaining) { - --sample.m_nLoopsRemaining; + sample.m_nLoopsRemaining--; sample.m_nReleasingVolumeDivider = 1; } else { - for (uint8 j = 0; j < m_nActiveSamples; ++j) { - if (!m_asActiveSamples[j].m_bIsProcessed) { - if (sample.m_nLoopCount) { - v28 = sample.m_nFrequency / m_nTimeSpent; - v29 = sample.m_nLoopCount * SampleManager.GetSampleLength(sample.m_nSampleIndex); - if (v28 == 0) + for (uint8 j = 0; j < m_nActiveSamples; j++) { + uint8 k = (j + field_6) % m_nActiveSamples; + if (!m_asActiveSamples[k].m_bIsProcessed) { + if (sample.m_nLoopCount != 0) { + freqDivided = sample.m_nFrequency / m_nTimeSpent; + loopCount = sample.m_nLoopCount * SampleManager.GetSampleLength(sample.m_nSampleIndex); + if (freqDivided == 0) continue; - sample.m_nReleasingVolumeDivider = v29 / v28 + 1; + sample.m_nReleasingVolumeDivider = loopCount / freqDivided + 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); if (field_4) { - emittingVol = 2 * Min(63, m_asActiveSamples[j].m_nEmittingVolume); + emittingVol = 2 * Min(63, m_asActiveSamples[k].m_nEmittingVolume); } else { - emittingVol = m_asActiveSamples[j].m_nEmittingVolume; + emittingVol = m_asActiveSamples[k].m_nEmittingVolume; } - if (SampleManager.InitialiseChannel(j, m_asActiveSamples[j].m_nSampleIndex, m_asActiveSamples[j].m_nBankIndex)) { - SampleManager.SetChannelFrequency(j, m_asActiveSamples[j].m_nFrequency); - SampleManager.SetChannelEmittingVolume(j, emittingVol); - SampleManager.SetChannelLoopPoints(j, m_asActiveSamples[j].m_nLoopStart, m_asActiveSamples[j].m_nLoopEnd); - SampleManager.SetChannelLoopCount(j, m_asActiveSamples[j].m_nLoopCount); - SampleManager.SetChannelReverbFlag(j, m_asActiveSamples[j].m_bReverbFlag); - if (m_asActiveSamples[j].m_bIs2D) { - uint8 offset = m_asActiveSamples[j].m_nOffset; + 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; + for (int32 l = 0; l < ARRAY_SIZE(m_sMissionAudio.m_bIsMobile); l++) { + if (m_sMissionAudio.m_bIsMobile[l]) { + isMobile = true; + break; + } + } + if (!isMobile || m_asActiveSamples[k].m_bIs2D) { + if (field_5538 < 127) + emittingVol *= field_5538 / 127; + vol = emittingVol; + } else { + vol = (emittingVol * field_5538 / 127); + } + SampleManager.SetChannelEmittingVolume(k, vol); + 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); + if (m_asActiveSamples[k].m_bIs2D) { + offset = m_asActiveSamples[k].m_nOffset; if (offset == 63) { - x = 0.f; + x = 0.0f; } else if (offset >= 63) { - x = (offset - 63) * 1000.f / 63; + x = (offset - 63) * 1000.0f / 63; } else { - x = -(63 - offset) * 1000.f / 63; + x = -(63 - offset) * 1000.0f / 63; //same like line below } - usedX = x; - usedY = 0.f; - usedZ = 0.f; - m_asActiveSamples[j].m_fSoundIntensity = 100000.0f; - } else { - usedX = position.x; - usedY = position.y; - usedZ = position.z; + position = CVector(x, 0.0f, 0.0f); + m_asActiveSamples[k].m_fSoundIntensity = 100000.0f; } - SampleManager.SetChannel3DPosition(j, usedX, usedY, usedZ); - SampleManager.SetChannel3DDistances(j, m_asActiveSamples[j].m_fSoundIntensity, 0.25f * m_asActiveSamples[j].m_fSoundIntensity); - SampleManager.StartChannel(j); + 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); } - m_asActiveSamples[j].m_bIsProcessed = true; + m_asActiveSamples[k].m_bIsProcessed = true; sample.m_bIsProcessed = true; sample.m_nVolumeChange = -1; break; @@ -908,6 +1001,7 @@ cAudioManager::ProcessActiveQueues() } } } + field_6 %= m_nActiveSamples; } void @@ -922,7 +1016,7 @@ cAudioManager::ClearRequestedQueue() void cAudioManager::ClearActiveSamples() { - for (int32 i = 0; i < m_nActiveSamples; i++) { + 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; @@ -945,7 +1039,7 @@ cAudioManager::ClearActiveSamples() m_asActiveSamples[i].m_nCalculatedVolume = 0; m_asActiveSamples[i].m_nReleasingVolumeDivider = 0; m_asActiveSamples[i].m_nVolumeChange = -1; - m_asActiveSamples[i].m_vecPos = {0.0f, 0.0f, 0.0f}; + 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; @@ -981,4 +1075,4 @@ cAudioManager::ComputeEmittingVolume(uint8 emittingVolume, float intensity, floa return (quatIntensity - (dist - diffIntensity)) * (float)emittingVolume / quatIntensity; return emittingVolume; } -#endif
\ No newline at end of file +#endif |