Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(audio): drop stopped delayed loops, dry unit replies, duck fixes
Olcay Seygan73139143a454
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 36c6a2c3c..75f1d10c5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,7 +13,7 @@ found and fixed — EA's own, not port damage.**- Sound takes time to cross the battlefield now. An explosion at the edge of the screen is heard about a quarter of a second after it is seen, one at the far end of a long view half a second after, at the speed of sound on the scale the units are drawn at. The wait never runs past a second, and unit replies, the interface, music, speech and every sound a mission script waits on still play the moment they are asked for.- Distance takes the top off a sound as air does. Fighting near the middle of the screen keeps its crack, a battle across the map arrives as a dull rumble, and a nuke on the far side is mostly low thunder. The muffling EA gave sixteen explosions for when they go off out of view used to be only a drop in volume; it is a real muffling now, so those blasts are no quieter off screen than on it, only duller.- Jets, helicopters and the Nuke Cannon's shell rise in pitch as they come in and drop as they pass, by how fast they move towards you. A Raptor run is two semitones up and down; an Aurora at full speed twice that.-- Every map has an echo of its own, worked out from how much of it is built over. A city map rings for nearly two seconds and throws a slap back off the buildings, open desert gives a faint short tail, and snow deadens whatever the map has. Far sounds carry more of it than near ones.+- Every map has an echo of its own, worked out from how much of it is built over. A city map rings for nearly two seconds and throws a slap back off the buildings, open desert gives a faint short tail, and snow deadens whatever the map has. Far sounds carry more of it than near ones. Unit replies take none of this, no muffling, no pitch bend and no echo: a tank answering from across the map sounds like a radio in your ear, as it always has.- A nuke, a Particle Cannon sweep, a Daisy Cutter, a MOAB or a Nuke Cannon shell that lands within earshot pushes the rest of the battle down for a couple of seconds, by how close it is, and lets it back up.- macOS and Linux hear the same, and so does the sound the game records for a video, in step with the picture frame for frame. A mod can retune any of it, or switch a part off, from its audio settings.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h b/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.hindex f1fcd0b1b..5b7853fee 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h@@ -63,6 +63,7 @@ public:Bool m_usePendingEvent;Bool m_requiresCheckForSample;Bool m_requestStop; ///< stopped while still waiting: play the sound once, without its loops+ Bool m_nextLoop; ///< a later pass startNextLoop handed back, of a sound that already started//// The pool hands out raw memory, and allocateAudioRequest only ever set m_usePendingEvent.@@ -75,7 +76,8 @@ public:m_handleToInteractOn(0),m_usePendingEvent(FALSE),m_requiresCheckForSample(FALSE),- m_requestStop(FALSE)+ m_requestStop(FALSE),+ m_nextLoop(FALSE){ }/** A play request owns the event it is carrying until something takes it - the destructor freesdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.hindex da7baf1b1..637ca7ca3 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h@@ -293,7 +293,7 @@ class MilesAudioManager : public AudioManagervoid initSamplePools( void );void processRequest( AudioRequest *req );- void playAudioEvent( AudioEventRTS *event, Bool requestStop );+ void playAudioEvent( AudioEventRTS *event, Bool requestStop, Bool nextLoop );void stopAudioEvent( AudioHandle handle );void pauseAudioEvent( AudioHandle handle );diff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cppindex c6c2c02b2..c3f0e9f85 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp@@ -778,7 +778,7 @@ void MilesAudioManager::pauseAmbient( Bool shouldPause )}//--------------------------------------------------------------------------------------------------void MilesAudioManager::playAudioEvent( AudioEventRTS *event, Bool requestStop )+void MilesAudioManager::playAudioEvent( AudioEventRTS *event, Bool requestStop, Bool nextLoop ){#ifdef INTENSIVE_AUDIO_DEBUGDEBUG_LOG(("MILES (%d) - Processing play request: %d (%s)", TheGameLogic->getFrame(), event->getPlayingHandle(), event->getEventName().str()));@@ -942,7 +942,7 @@ void MilesAudioManager::playAudioEvent( AudioEventRTS *event, Bool requestStop )if (sample3D) {audio->m_file = playSample3D(event, sample3D);m_sound->notifyOf3DSampleStart();- if (audio->m_file) {+ if (audio->m_file && !nextLoop) {duckForBlast(event, sample3D);}}@@ -1081,15 +1081,17 @@ void MilesAudioManager::stopAudioEvent( AudioHandle handle )//// A sound between loops that have a delay is not on any playing list: startNextLoop handed its// event back to the request list. Stopping it there is the only way to stop it at all, or the- // loop outlives the thing that asked for it. A sound effect still plays the one pass it was- // waiting for, the same as one caught mid-play below.+ // loop outlives the thing that asked for it. A one-shot sound effect still plays the one pass+ // it was waiting for, the same as one caught mid-play below; a loop is dropped, as one playing+ // below ends its pass, which matters since the distance delay holds nearly every world loop here.//std::list<AudioRequest*>::iterator ait;for ( ait = m_audioRequests.begin(); ait != m_audioRequests.end(); ++ait ) {AudioRequest *req = (*ait);if (req && req->m_usePendingEvent && req->m_pendingEvent&& req->m_pendingEvent->getPlayingHandle() == handle) {- if (audioIsType(req->m_pendingEvent, AT_SoundEffect)) {+ if (audioIsType(req->m_pendingEvent, AT_SoundEffect)+ && !(req->m_pendingEvent->getAudioEventInfo()->m_control & AC_LOOP)) {req->m_requestStop = true;} else {req->deleteInstance();@@ -2885,9 +2887,11 @@ void MilesAudioManager::adjustRequest( AudioRequest *req )return;}- // Logic time, not a frame's worth a pass: at 120 fps that ran every delay twice as fast as the- // picture, and a sound held back by its distance has to land with what is seen.- req->m_pendingEvent->decrementDelay(m_clockElapsedMs);+ // A world sound counts logic time, not a frame's worth a pass: at 120 fps that ran every delay+ // twice as fast as the picture, and a sound held back by its distance has to land with what is+ // seen. Everything else keeps a frame a pass, so the pause menu's sounds still play while the+ // logic clock stands.+ req->m_pendingEvent->decrementDelay(req->m_pendingEvent->isPositionalAudio() ? m_clockElapsedMs : MSEC_PER_LOGICFRAME_REAL);req->m_requiresCheckForSample = true;}@@ -2917,7 +2921,15 @@ void MilesAudioManager::advanceAudioClock( void )void MilesAudioManager::trackVelocity( PlayingAudio *playing, const Coord3D *pos ){if (m_clockElapsedMs <= 0.0f)+ {+ // a pass between two logic frames keeps the velocity; a paused game stands still, pitch too+ if (playing->m_tracked && TheGameLogic->isGamePaused())+ {+ playing->m_velocity.zero();+ AIL_set_3D_velocity_vector( playing->m_3DSample, 0.0f, 0.0f, 0.0f );+ }return;+ }if (playing->m_tracked){@@ -3255,6 +3267,7 @@ Bool MilesAudioManager::startNextLoop( PlayingAudio *looping )AudioRequest *req = allocateAudioRequest(true);req->m_pendingEvent = looping->m_audioEventRTS;req->m_requiresCheckForSample = true;+ req->m_nextLoop = true;appendAudioRequest(req);return true;}@@ -3318,6 +3331,8 @@ void *MilesAudioManager::playSample3D( AudioEventRTS *event, H3DSAMPLE sample3Dvoid *fileBuffer = loadFileForRead(event);if (fileBuffer) {AIL_set_3D_sample_file(sample3D, fileBuffer);+ // a unit's reply is the radio in the commander's ear: no air, no doppler, no room+ AIL_ex_set_3D_sample_dry(sample3D, BitTest(event->getAudioEventInfo()->m_type, ST_VOICE));// Prep any sort of filtering, etc, hereAIL_register_3D_EOS_callback(sample3D, set3DSampleCompleted);@@ -3442,7 +3457,8 @@ void MilesAudioManager::processRequest( AudioRequest *req )// hand the event over: from here it belongs to the playing list, or to playAudioEvent// to free if it cannot be playedconst Bool requestStop = req->m_requestStop;- playAudioEvent(req->releasePendingEvent(), requestStop);+ const Bool nextLoop = req->m_nextLoop;+ playAudioEvent(req->releasePendingEvent(), requestStop, nextLoop);break;}case AR_Pause:diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.h b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.hindex b1dcc43aa..025185c26 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.h@@ -299,10 +299,15 @@ void AILCALL AIL_ex_set_3D_linear_falloff(S32 linear);** AIL_ex_duck: everything but the trigger, and any earlier trigger still sounding, dips to gain and* comes back over seconds, AIL_ex_duck_gain's shape. miniaudio counts that time in frames mixed, so- * a -wav run ducks on the picture's clock; XAudio2 counts it on the wall clock it plays on. */+ * a -wav run ducks on the picture's clock; XAudio2 counts it on the wall clock it plays on. The+ * movies' voice (mss_ex_pcm.h) is never ducked.+ *+ * AIL_ex_set_3D_sample_dry: a 3D sample that takes no air, no doppler and no room, only its distance+ * gain, pan and occlusion; a unit's reply stays clean. Set on each play; a fresh handle is wet. */void AILCALL AIL_ex_set_3D_air(F32 speed_of_sound, F32 absorption_distance);void AILCALL AIL_ex_set_reverb(F32 wet, F32 decay, F32 damping, F32 echo);void AILCALL AIL_ex_duck(H3DSAMPLE trigger, F32 gain, F32 seconds);+void AILCALL AIL_ex_set_3D_sample_dry(H3DSAMPLE handle, S32 dry);/* ---- file format helpers ---------------------------------------------- */S32 AILCALL AIL_WAV_info(const void *data, AILSOUNDINFO *info);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_backend_names.h b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_backend_names.hindex e04d6de0d..9bec6b300 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_backend_names.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/mss_backend_names.h@@ -86,6 +86,7 @@#define AIL_ex_set_3D_air MSS_BACKEND_NAME(AIL_ex_set_3D_air)#define AIL_ex_set_reverb MSS_BACKEND_NAME(AIL_ex_set_reverb)#define AIL_ex_duck MSS_BACKEND_NAME(AIL_ex_duck)+#define AIL_ex_set_3D_sample_dry MSS_BACKEND_NAME(AIL_ex_set_3D_sample_dry)#define AIL_WAV_info MSS_BACKEND_NAME(AIL_WAV_info)#define AIL_decompress_ADPCM MSS_BACKEND_NAME(AIL_decompress_ADPCM)#define AIL_mem_free_lock MSS_BACKEND_NAME(AIL_mem_free_lock)diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miles_dispatch.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miles_dispatch.cppindex 0d2142631..114fd7d64 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miles_dispatch.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miles_dispatch.cpp@@ -84,6 +84,7 @@MSS_API(void, AIL_ex_set_3D_air, (F32 speed_of_sound, F32 absorption_distance), (speed_of_sound, absorption_distance)) \MSS_API(void, AIL_ex_set_reverb, (F32 wet, F32 decay, F32 damping, F32 echo), (wet, decay, damping, echo)) \MSS_API(void, AIL_ex_duck, (H3DSAMPLE trigger, F32 gain, F32 seconds), (trigger, gain, seconds)) \+ MSS_API(void, AIL_ex_set_3D_sample_dry, (H3DSAMPLE handle, S32 dry), (handle, dry)) \MSS_API(S32, AIL_WAV_info, (const void *data, AILSOUNDINFO *info), (data, info)) \MSS_API(S32, AIL_decompress_ADPCM, (const AILSOUNDINFO *info, void **outdata, U32 *outsize), (info, outdata, outsize)) \MSS_API(void, AIL_mem_free_lock, (void *ptr), (ptr))diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cppindex 05103802a..e1a50311a 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/miniaudio/miles_miniaudio.cpp@@ -300,6 +300,8 @@ unsigned int decodeAdpcm(const WaveImage &wave, std::vector<short> *out)// XAudio2 source voice with an output matrix did.// ---------------------------------------------------------------------------------------------+const float LOW_PASS_DENORMAL_GUARD = 1e-18f; // a filter left ringing on silence decays into the denormals+struct VoiceMix{VoiceMix() : resamplerReady(false), channels(0), gainLeft(0.0f), gainRight(0.0f), lowPass(1.0f), lowPassState(0.0f),@@ -407,7 +409,7 @@ bool mixVoice(VoiceMix *mix, SourceRead read, void *source, float *output, unsigfor (unsigned channel = 0; channel < mix->channels; ++channel) {sum += resampled[frame * mix->channels + channel];}- mix->lowPassState += mix->lowPass * (sum - mix->lowPassState);+ mix->lowPassState += mix->lowPass * (sum - mix->lowPassState) + LOW_PASS_DENORMAL_GUARD;sum = mix->lowPassState;output[(done + frame) * OUTPUT_CHANNELS + 0] += left * sum;output[(done + frame) * OUTPUT_CHANNELS + 1] += right * sum;@@ -452,12 +454,13 @@ struct Sample// What the mix sees, under mixLock. `running` is the voice started, `queued` its one buffer// still in it, `cursor` the next source frame. `unducked`: it started a duck, which leaves it- // alone until the duck is over.+ // alone until the duck is over or the sample stops.bool running;bool queued;unsigned int cursor;bool sourceDry;bool unducked;+ bool dry; // AIL_ex_set_3D_sample_dryVoiceMix mix;};@@ -771,6 +774,12 @@ Spatial computeSpatial(const Sample &sample)Spatial spatial;spatial.volume = clampUnit(sample.volume) * attenuation;spatial.pan = pan;+ if (sample.dry) {+ spatial.cutoff = AIL_ex_3D_cutoff(distance, 0.0f, sample.occlusion);+ spatial.send = 0.0f;+ spatial.doppler = 1.0f;+ return spatial;+ }spatial.cutoff = AIL_ex_3D_cutoff(distance, g_absorptionDistance.load(), sample.occlusion);spatial.send = AIL_ex_3D_send(clampUnit(sample.volume), attenuation, g_roomSend.load());spatial.doppler = AIL_ex_doppler_ratio(dx, dy, dz, sample.velocityX, sample.velocityY, sample.velocityZ, g_speedOfSound.load());@@ -1276,8 +1285,9 @@ void dataCallback(ma_device *, void *output, const void *, ma_uint32 frameCount)for (size_t i = 0; i < g_engine.pcmVoices.size(); ++i) {PcmVoice *voice = g_engine.pcmVoices[i];// Dry is only until the owner queues more, so it is asked afresh each pass, as a stream's is.+ // A movie is not ducked, as XAudio2's movie voice is not: -wav has to sound like the game.voice->sourceDry = false;- mixVoice(&voice->mix, readPcmSource, voice, out, frameCount, &voice->sourceDry, duck, NULL);+ mixVoice(&voice->mix, readPcmSource, voice, out, frameCount, &voice->sourceDry, 1.0f, NULL);}if (g_engine.room.ready) {processRoom(&g_engine.room, room, out, frameCount);@@ -1691,6 +1701,7 @@ HSAMPLE AILCALL AIL_allocate_sample_handle(HDIGDRIVER dig)sample->cursor = 0;sample->sourceDry = false;sample->unducked = false;+ sample->dry = false;std::lock_guard<std::recursive_mutex> guard(g_engine.lock);std::lock_guard<std::mutex> mixGuard(g_engine.mixLock);@@ -1940,6 +1951,9 @@ void AILCALL AIL_start_3D_sample(H3DSAMPLE handle)void AILCALL AIL_stop_3D_sample(H3DSAMPLE handle){AIL_stop_sample((HSAMPLE)handle);+ // the manager stops every handle it takes back, and the next sound on it ducks like the rest+ std::lock_guard<std::mutex> mixGuard(g_engine.mixLock);+ ((Sample *)handle)->unducked = false;}void AILCALL AIL_resume_3D_sample(H3DSAMPLE handle)@@ -2017,6 +2031,13 @@ void AILCALL AIL_ex_duck(H3DSAMPLE trigger, F32 gain, F32 seconds)g_engine.duckSeconds = seconds;}+void AILCALL AIL_ex_set_3D_sample_dry(H3DSAMPLE handle, S32 dry)+{+ std::lock_guard<std::recursive_mutex> guard(g_engine.lock);+ ((Sample *)handle)->dry = dry != 0;+ refreshSampleOutput((Sample *)handle);+}+void AILCALL AIL_set_3D_sample_occlusion(H3DSAMPLE handle, F32 occlusion){Sample *sample = (Sample *)handle;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cppindex 49d6c1f46..62c96e91a 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cpp@@ -29,6 +29,7 @@#include <stdio.h>#include <stdlib.h>#include <string.h>+#include <atomic>#include <deque>#include <vector>@@ -296,7 +297,8 @@ struct Samplefloat minDistance, maxDistance;float occlusion;float velocityX, velocityY, velocityZ; // units a second, AIL_set_3D_velocity_vector- bool unducked; // started a duck, so the duck leaves it alone until it is over+ bool unducked; // started a duck, so the duck leaves it alone until it is over or the sample stops+ bool dry; // AIL_ex_set_3D_sample_dry};struct StreamBuffer@@ -363,9 +365,10 @@ struct EngineEngine g_engine;S32 g_linearFalloff; // AIL_ex_set_3D_linear_falloff-float g_speedOfSound; // AIL_ex_set_3D_air-float g_absorptionDistance;-float g_roomSend; // AIL_ex_set_reverb's wet+// written by the game's thread with no lock, read by the service thread under it+std::atomic<float> g_speedOfSound(0.0f); // AIL_ex_set_3D_air+std::atomic<float> g_absorptionDistance(0.0f);+std::atomic<float> g_roomSend(0.0f); // AIL_ex_set_reverb's wet// AIL_ex_duck, under the lock. duckNow is the gain the service thread worked out last.struct Duck@@ -466,9 +469,15 @@ Spatial computeSpatial(const Sample &sample)Spatial spatial;spatial.volume = clampUnit(sample.volume) * attenuation;spatial.pan = pan;- spatial.cutoff = AIL_ex_3D_cutoff(distance, g_absorptionDistance, sample.occlusion);- spatial.send = AIL_ex_3D_send(clampUnit(sample.volume), attenuation, g_roomSend);- spatial.doppler = AIL_ex_doppler_ratio(dx, dy, dz, sample.velocityX, sample.velocityY, sample.velocityZ, g_speedOfSound);+ if (sample.dry) {+ spatial.cutoff = AIL_ex_3D_cutoff(distance, 0.0f, sample.occlusion);+ spatial.send = 0.0f;+ spatial.doppler = 1.0f;+ return spatial;+ }+ spatial.cutoff = AIL_ex_3D_cutoff(distance, g_absorptionDistance.load(), sample.occlusion);+ spatial.send = AIL_ex_3D_send(clampUnit(sample.volume), attenuation, g_roomSend.load());+ spatial.doppler = AIL_ex_doppler_ratio(dx, dy, dz, sample.velocityX, sample.velocityY, sample.velocityZ, g_speedOfSound.load());return spatial;}@@ -1623,6 +1632,10 @@ void AILCALL AIL_start_3D_sample(H3DSAMPLE handle)void AILCALL AIL_stop_3D_sample(H3DSAMPLE handle){AIL_stop_sample((HSAMPLE)handle);+ // the manager stops every handle it takes back, and the next sound on it ducks like the rest+ EnterCriticalSection(&g_engine.lock);+ ((Sample *)handle)->unducked = false;+ LeaveCriticalSection(&g_engine.lock);}void AILCALL AIL_resume_3D_sample(H3DSAMPLE handle)@@ -1682,13 +1695,13 @@ void AILCALL AIL_ex_set_3D_linear_falloff(S32 linear)void AILCALL AIL_ex_set_3D_air(F32 speed_of_sound, F32 absorption_distance){// No lock, as AIL_ex_set_3D_linear_falloff- g_speedOfSound = speed_of_sound;- g_absorptionDistance = absorption_distance;+ g_speedOfSound.store(speed_of_sound);+ g_absorptionDistance.store(absorption_distance);}void AILCALL AIL_ex_set_reverb(F32 wet, F32 decay, F32 damping, F32 echo){- g_roomSend = wet;+ g_roomSend.store(wet);if (g_engine.room == NULL) {return;}@@ -1723,6 +1736,13 @@ void AILCALL AIL_ex_duck(H3DSAMPLE trigger, F32 gain, F32 seconds)LeaveCriticalSection(&g_engine.lock);}+void AILCALL AIL_ex_set_3D_sample_dry(H3DSAMPLE handle, S32 dry)+{+ EnterCriticalSection(&g_engine.lock);+ ((Sample *)handle)->dry = dry != 0;+ LeaveCriticalSection(&g_engine.lock);+}+void AILCALL AIL_set_3D_sample_occlusion(H3DSAMPLE handle, F32 occlusion){Sample *sample = (Sample *)handle;@@ -1882,7 +1902,7 @@ void AILCALL AIL_start_stream(HSTREAM handle)stream->playing = true;stream->paused = false;stream->exhausted = false;- stream->voice->SetVolume(clampUnit(stream->volume));+ stream->voice->SetVolume(clampUnit(stream->volume) * g_duck.duckNow);applyPan(stream->voice, stream->voiceFormat.nChannels, stream->pan);stream->voice->Start(0);LeaveCriticalSection(&g_engine.lock);@@ -1931,7 +1951,8 @@ void AILCALL AIL_set_stream_volume_pan(HSTREAM handle, F32 volume, F32 pan)stream->volume = volume;stream->pan = pan;if (stream->voice != NULL) {- stream->voice->SetVolume(clampUnit(volume));+ // a fade writes this every pass, so it carries the duck the service thread last set+ stream->voice->SetVolume(clampUnit(volume) * g_duck.duckNow);applyPan(stream->voice, stream->voiceFormat.nChannels, pan);}LeaveCriticalSection(&g_engine.lock);diff --git a/GeneralsMD/Code/Tests/test_miles_effects.cpp b/GeneralsMD/Code/Tests/test_miles_effects.cppindex f200e3dfc..cc22128a6 100644--- a/GeneralsMD/Code/Tests/test_miles_effects.cpp+++ b/GeneralsMD/Code/Tests/test_miles_effects.cpp@@ -258,6 +258,34 @@ TEST(the_room_rings_on_after_the_sound_has_stopped)CHECK(rms(echoCapture, 0.095, 0.12) > 0.002);}+TEST(a_dry_sample_takes_no_air_and_no_room)+{+ startAudio();+ // A unit's reply: 1600 out with air at 400 keeps its 8 kHz, and a room at half send adds no tail.+ AIL_ex_set_3D_air(0.0f, 400.0f);+ AIL_ex_set_reverb(0.5f, 1.5f, 0.3f, 0.0f);+ std::vector<unsigned char> bright = makeTone(8000.0, 500);+ std::vector<H3DSAMPLE> farReply(1, place(bright, -1600.0f, 0.0f, 1.0f));+ AIL_ex_set_3D_sample_dry(farReply[0], 1);+ const double farLevel = rms(listen(farReply, 0.6), 0.1, 0.4) / (10.0 / 1600.0);+ std::vector<H3DSAMPLE> nearReply(1, place(bright, -20.0f, 0.0f, 1.0f));+ AIL_ex_set_3D_sample_dry(nearReply[0], 1);+ const double nearLevel = rms(listen(nearReply, 0.6), 0.1, 0.4) / (10.0 / 20.0);+ runSeconds(4.0);+ std::vector<unsigned char> blip = makeTone(440.0, 100);+ std::vector<H3DSAMPLE> reply(1, place(blip, -20.0f, 0.0f, 1.0f));+ AIL_ex_set_3D_sample_dry(reply[0], 1);+ const Capture replyCapture = listen(reply, 1.0);+ AIL_ex_set_3D_air(0.0f, 0.0f);+ AIL_ex_set_reverb(0.0f, 1.0f, 0.0f, 0.0f);+ runSeconds(3.0);++ CHECK(nearLevel > 0.05);+ CHECK(fabs(farLevel / nearLevel - 1.0) < 0.05);+ CHECK(rms(replyCapture, 0.0, 0.1) > 0.02);+ CHECK(rms(replyCapture, 0.3, 0.6) < 0.0002);+}+TEST(a_duck_dips_the_rest_and_spares_the_blast){startAudio();