From e54b540bd43cc15168c89b0fe011eb523c74d119 Mon Sep 17 00:00:00 2001 From: Roman Masanin <36927roma@gmail.com> Date: Fri, 2 Oct 2020 00:11:51 +0300 Subject: [PATCH] final processActiveQueues --- src/audio/AudioManager.cpp | 129 ++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 67 deletions(-) diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index 9d822bd4..1da80352 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -750,49 +750,42 @@ cAudioManager::AddReleasingSounds() void cAudioManager::ProcessActiveQueues() { - char flag; // al - int emittingVol_1; // ecx - bool missionState; // al - uint32 freqDivided; // ebp - uint32 loopCount; // eax - uint8 emittingVol_3; // dl - unsigned int volume; // eax - uint8 offset; // dl - float x; // st4 - unsigned int emittingVol; // [esp+14h] [ebp-78h] - int emittingVolCmp; // [esp+28h] [ebp-64h] - int emittingVol_2; // [esp+28h] [ebp-64h] - int activeVolume_1; // [esp+40h] [ebp-4Ch] - CVector position; // [esp+70h] [ebp-1Ch] - CVector usedPosition; + 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++) { //?? + 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++) {//?? + 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) { //!! + sample.m_nSampleIndex == m_asActiveSamples[j].m_nSampleIndex) { + if (sample.m_nLoopCount) { - if (field_5554 & 1) { //!! - if (!(j & 1)) { //!! - flag = 0; + if (field_5554 & 1) { + if (!(j & 1)) { + flag = false; } else { - flag = 1; + flag = true; } - } else if (j & 1) { //!! - flag = 0; + } else if (j & 1) { + flag = false; } else { - flag = 1; + flag = true; } - if (flag && !SampleManager.GetChannelUsedFlag(j)) { //!! + if (flag && !SampleManager.GetChannelUsedFlag(j)) { sample.m_bLoopEnded = true; m_asActiveSamples[j].m_bLoopEnded = true; m_asActiveSamples[j].m_nSampleIndex = NO_SAMPLE; @@ -805,9 +798,9 @@ cAudioManager::ProcessActiveQueues() sample.m_bIsProcessed = true; m_asActiveSamples[j].m_bIsProcessed = true; sample.m_nVolumeChange = -1; - if (!sample.m_bReleasingSoundFlag) { //!! - if (sample.m_bIs2D) { //!! - if (field_4) { //!! + if (!sample.m_bReleasingSoundFlag) { + if (sample.m_bIs2D) { + if (field_4) { emittingVol = 2 * Min(63, sample.m_nEmittingVolume); } else { emittingVol = sample.m_nEmittingVolume; @@ -822,35 +815,35 @@ cAudioManager::ProcessActiveQueues() sample.m_fDistance, sample.m_fSpeedMultiplier); - if (sample.m_nFrequency != m_asActiveSamples[j].m_nFrequency) { //!! + if (sample.m_nFrequency != m_asActiveSamples[j].m_nFrequency) { 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) { //!! - activeVolume_1 = clamp2((int8)sample.m_nEmittingVolume, (int8)m_asActiveSamples[j].m_nEmittingVolume, 10); + if (sample.m_nEmittingVolume != m_asActiveSamples[j].m_nEmittingVolume) { + vol = clamp2((int8)sample.m_nEmittingVolume, (int8)m_asActiveSamples[j].m_nEmittingVolume, 10); - if (field_4) { //!! - emittingVol_1 = 2 * Min(63, activeVolume_1); + if (field_4) { + emittingVol = 2 * Min(63, vol); } else { - emittingVol_1 = activeVolume_1; + emittingVol = vol; } missionState = false; - for (int32 k = 0; k < ARRAY_SIZE(m_sMissionAudio.m_bIsMobile); k++) { //!! + for (int32 k = 0; k < ARRAY_SIZE(m_sMissionAudio.m_bIsMobile); k++) { if (m_sMissionAudio.m_bIsMobile[k]) { missionState = true; break; } } - if (missionState) { //!! - emittingVol_1 = (emittingVol_1 * field_5538) / 127; + if (missionState) { + emittingVol = (emittingVol * field_5538) / 127; } else { if (field_5538 < 127) - emittingVol_1 = (emittingVol_1 * field_5538) / 127; + emittingVol = (emittingVol * field_5538) / 127; } - SampleManager.SetChannelEmittingVolume(j, emittingVol_1); - m_asActiveSamples[j].m_nEmittingVolume = activeVolume_1; + SampleManager.SetChannelEmittingVolume(j, emittingVol); + m_asActiveSamples[j].m_nEmittingVolume = vol; } TranslateEntity(&sample.m_vecPos, &position); SampleManager.SetChannel3DPosition(j, position.x, position.y, position.z); @@ -866,67 +859,67 @@ cAudioManager::ProcessActiveQueues() } } } - for (int32 i = 0; i < m_nActiveSamples; i++) { //!! + 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; } } - for (uint8 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) { //?? + 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) { //!! + 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_nReleasingVolumeDivider = 1; } else { - for (uint8 j = 0; j < m_nActiveSamples; j++) { //?? + 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) { //!! + 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) //!! + if (freqDivided == 0) continue; sample.m_nReleasingVolumeDivider = loopCount / freqDivided + 1; } memcpy(&m_asActiveSamples[k], &sample, sizeof(tSound)); - if (!m_asActiveSamples[k].m_bIs2D) //!! + if (!m_asActiveSamples[k].m_bIs2D) TranslateEntity(&m_asActiveSamples[k].m_vecPos, &position); - if (field_4) { //!! - emittingVol_2 = 2 * Min(63, m_asActiveSamples[k].m_nEmittingVolume); + if (field_4) { + emittingVol = 2 * Min(63, m_asActiveSamples[k].m_nEmittingVolume); } else { - emittingVol_2 = m_asActiveSamples[k].m_nEmittingVolume; + emittingVol = m_asActiveSamples[k].m_nEmittingVolume; } 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]) { //!! + 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_2 *= field_5538 / 127; - volume = emittingVol_2; + if (!isMobile || m_asActiveSamples[k].m_bIs2D) { + if (field_5538 < 127) + emittingVol *= field_5538 / 127; + vol = emittingVol; } else { - volume = (emittingVol_2 * field_5538 / 127); + vol = (emittingVol * field_5538 / 127); } - SampleManager.SetChannelEmittingVolume(k, volume); + 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) { //!! + if (m_asActiveSamples[k].m_bIs2D) { offset = m_asActiveSamples[k].m_nOffset; - if (offset == 63) { //!! + if (offset == 63) { x = 0.0f; - } else if (offset >= 63) { //!! + } 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 } position = CVector(x, 0.0f, 0.0f); m_asActiveSamples[k].m_fSoundIntensity = 100000.0f; @@ -944,7 +937,9 @@ cAudioManager::ProcessActiveQueues() } } } + field_6 %= m_nActiveSamples; } + void cAudioManager::ClearRequestedQueue() {