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(milesaudio): let a stopped sound finish, give movies the voice volume
Olcay Seygan22f1f7120419
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e29301841..b05ab2b47 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -979,6 +979,8 @@ found and fixed — EA's own, not port damage.**## Sound, video, and getting it to start at all- Audio is real, through the audio library the retail game ships with.+- A death cry plays to the end. So does "construction complete", and the tail of a gun. Telling a sound to stop used to cut it off that frame, where the 2003 game let it finish and only kept it from repeating; our own fix for the audio thread broke that, and it is put back. A looping sound caught in the pause between two plays can be stopped too, instead of carrying on after whatever made it is gone.+- Movies follow the voice volume slider. The volume was handed to the video before it was ready to take it, so every movie played at full level, and moving the slider while one was playing changed nothing.- A sound at the edge of its range can fade out instead of stopping dead. The volume curve neveractually reaches zero, so a sound you are walking away from was cut off mid-note at the maximumrange. `RangeVolumeFade = Yes` in `AudioSettings.ini` uses a fade that reaches zero exactly wherediff --git a/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h b/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.hindex 734a6d3b0..75919db2e 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h@@ -61,6 +61,7 @@ public:Bool m_usePendingEvent;Bool m_requiresCheckForSample;+ Bool m_requestStop; ///< stopped while still waiting: play the sound once, without its loops//// The pool hands out raw memory, and allocateAudioRequest only ever set m_usePendingEvent.@@ -72,7 +73,8 @@ public:m_pendingEvent(NULL),m_handleToInteractOn(0),m_usePendingEvent(FALSE),- m_requiresCheckForSample(FALSE)+ m_requiresCheckForSample(FALSE),+ m_requestStop(FALSE){ }/** A play request owns the event it is carrying until something takes it - the destructor freesdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/VideoPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameClient/VideoPlayer.hindex 9b3849490..90ed6d97b 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/VideoPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/VideoPlayer.h@@ -254,6 +254,8 @@ class VideoPlayerInterface : public SubsystemInterfacevirtual const FieldParse *getFieldParse( void ) const = 0; ///< Return the field parse infovirtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid ) = 0; ///< Notify the video player that they can now ask for an audio handle, or they need to give theirs up.++ virtual void setVolume( Real volume ) = 0; ///< Push a new speech volume to the audio of every open movie};@@ -302,6 +304,7 @@ class VideoPlayer : public VideoPlayerInterfacevirtual const FieldParse *getFieldParse( void ) const { return m_videoFieldParseTable; } ///< Return the field parse infovirtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid ) { }+ virtual void setVolume( Real volume ) { }// Implementation specificvoid remove( VideoStream *stream ); ///< remove stream from active listdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.hindex 3fdda150a..b5fc37ea6 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h@@ -72,7 +72,7 @@ struct PlayingAudiovolatile PlayingStatus m_status; // This member is adjusted by another running thread.AudioEventRTS *m_audioEventRTS;void *m_file; // The file that was opened to play this- Bool m_requestStop;+ Bool m_requestStop; ///< let the sound finish, but start no further loop of itBool m_cleanupAudioEventRTS;/// Asked to fade out. Moving from the playing list to the fading list writes two lists, so it/// happens in processPlayingList holding both locks rather than wherever the fade is asked for.@@ -91,6 +91,10 @@ struct PlayingAudiom_stream(0),m_framesFaded(0){ }++ /// An entry past PS_Playing is waiting for the sweep that frees it: its Miles handle may already+ /// be back in the pool, so it must not be counted, touched or picked as a victim.+ Bool isPlaying() const { return m_status == PS_Playing; }};struct ProviderInfo@@ -265,7 +269,7 @@ class MilesAudioManager : public AudioManagervoid initSamplePools( void );void processRequest( AudioRequest *req );- void playAudioEvent( AudioEventRTS *event );+ void playAudioEvent( AudioEventRTS *event, Bool requestStop );void stopAudioEvent( AudioHandle handle );void pauseAudioEvent( AudioHandle handle );diff --git a/GeneralsMD/Code/GameEngineDevice/Include/VideoDevice/Bink/BinkVideoPlayer.h b/GeneralsMD/Code/GameEngineDevice/Include/VideoDevice/Bink/BinkVideoPlayer.hindex 351ad3f03..148b52320 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/VideoDevice/Bink/BinkVideoPlayer.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/VideoDevice/Bink/BinkVideoPlayer.h@@ -131,7 +131,12 @@ class BinkVideoPlayer : public VideoPlayervirtual VideoStreamInterface* load( AsciiString movieTitle ); ///< Load video file in to memory for playbackvirtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid );+ virtual void setVolume( Real volume );virtual void initializeBinkWithMiles( void );++ private:++ static Int movieAudioVolume( Real volume );};diff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cppindex 6da009510..3736e1b2d 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp@@ -571,7 +571,7 @@ void MilesAudioManager::pauseAudio( AudioAffect which )if (BitTest(which, AudioAffect_Sound)) {for (it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it) {playing = *it;- if (playing) {+ if (playing && playing->isPlaying()) {AIL_stop_sample(playing->m_sample);}}@@ -580,7 +580,7 @@ void MilesAudioManager::pauseAudio( AudioAffect which )if (BitTest(which, AudioAffect_Sound3D)) {for (it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it) {playing = *it;- if (playing) {+ if (playing && playing->isPlaying()) {AIL_stop_3D_sample(playing->m_3DSample);}}@@ -589,7 +589,7 @@ void MilesAudioManager::pauseAudio( AudioAffect which )if (BitTest(which, AudioAffect_Speech | AudioAffect_Music)) {for (it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it) {playing = *it;- if (playing) {+ if (playing && playing->isPlaying()) {if (audioIsType(playing->m_audioEventRTS, AT_Music)) {if (!BitTest(which, AudioAffect_Music)) {continue;@@ -632,7 +632,7 @@ void MilesAudioManager::resumeAudio( AudioAffect which )if (BitTest(which, AudioAffect_Sound)) {for (it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it) {playing = *it;- if (playing) {+ if (playing && playing->isPlaying()) {AIL_resume_sample(playing->m_sample);}}@@ -641,7 +641,7 @@ void MilesAudioManager::resumeAudio( AudioAffect which )if (BitTest(which, AudioAffect_Sound3D)) {for (it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it) {playing = *it;- if (playing) {+ if (playing && playing->isPlaying()) {AIL_resume_3D_sample(playing->m_3DSample);}}@@ -650,7 +650,7 @@ void MilesAudioManager::resumeAudio( AudioAffect which )if (BitTest(which, AudioAffect_Speech | AudioAffect_Music)) {for (it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it) {playing = *it;- if (playing) {+ if (playing && playing->isPlaying()) {if (audioIsType(playing->m_audioEventRTS, AT_Music)) {if (!BitTest(which, AudioAffect_Music)) {continue;@@ -673,7 +673,7 @@ void MilesAudioManager::pauseAmbient( Bool shouldPause )}//--------------------------------------------------------------------------------------------------void MilesAudioManager::playAudioEvent( AudioEventRTS *event )+void MilesAudioManager::playAudioEvent( AudioEventRTS *event, Bool requestStop ){#ifdef INTENSIVE_AUDIO_DEBUGDEBUG_LOG(("MILES (%d) - Processing play request: %d (%s)", TheGameLogic->getFrame(), event->getPlayingHandle(), event->getEventName().str()));@@ -695,6 +695,7 @@ void MilesAudioManager::playAudioEvent( AudioEventRTS *event )AsciiString fileToPlay = event->getFilename();PlayingAudio *audio = allocatePlayingAudio();+ audio->m_requestStop = requestStop;switch(info->m_soundType){case AT_Music:@@ -956,6 +957,27 @@ 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.+ //+ 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)) {+ req->m_requestStop = true;+ } else {+ req->deleteInstance();+ m_audioRequests.erase(ait);+ }+ return;+ }+ }+for ( it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it ) {PlayingAudio *audio = (*it);if (!audio) {@@ -978,8 +1000,10 @@ void MilesAudioManager::stopAudioEvent( AudioHandle handle )}if (audio->m_audioEventRTS->getPlayingHandle() == handle) {- // Ask it to stop; the next processPlayingList sweep does the Miles side and the free.- InterlockedCompareExchange( (volatile long *)&audio->m_status, PS_Stopping, PS_Playing );+ // EA's stop for a sound effect: let this pass finish and start no further loop. Moving+ // it straight to PS_Stopping cut death cries, build-complete barks and weapon tails off+ // the frame they were asked to stop.+ audio->m_requestStop = true;break;}}@@ -994,8 +1018,7 @@ void MilesAudioManager::stopAudioEvent( AudioHandle handle )#ifdef INTENSIVE_AUDIO_DEBUGDEBUG_LOG((" (%s)\n", audio->m_audioEventRTS->getEventName()));#endif- // Ask it to stop; the next processPlayingList sweep does the Miles side and the free.- InterlockedCompareExchange( (volatile long *)&audio->m_status, PS_Stopping, PS_Playing );+ audio->m_requestStop = true;break;}}@@ -1585,21 +1608,21 @@ Bool MilesAudioManager::isCurrentlyPlaying( AudioHandle handle )for (it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it) {playing = *it;- if (playing && playing->m_audioEventRTS->getPlayingHandle() == handle) {+ if (playing && playing->isPlaying() && playing->m_audioEventRTS->getPlayingHandle() == handle) {return true;}}for (it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it) {playing = *it;- if (playing && playing->m_audioEventRTS->getPlayingHandle() == handle) {+ if (playing && playing->isPlaying() && playing->m_audioEventRTS->getPlayingHandle() == handle) {return true;}}for (it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it) {playing = *it;- if (playing && playing->m_audioEventRTS->getPlayingHandle() == handle) {+ if (playing && playing->isPlaying() && playing->m_audioEventRTS->getPlayingHandle() == handle) {return true;}}@@ -1946,7 +1969,7 @@ Bool MilesAudioManager::doesViolateLimit( AudioEventRTS *event ) constif (!event->isPositionalAudio()) {// 2-Dfor ( it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it ) {- if ((*it)->m_audioEventRTS->getEventName() == event->getEventName()) {+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getEventName() == event->getEventName()) {if (totalCount == 0) {// This is the oldest audio of this type playing.event->setHandleToKill((*it)->m_audioEventRTS->getPlayingHandle());@@ -1957,7 +1980,7 @@ Bool MilesAudioManager::doesViolateLimit( AudioEventRTS *event ) const} else {// 3-Dfor ( it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it ) {- if ((*it)->m_audioEventRTS->getEventName() == event->getEventName()) {+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getEventName() == event->getEventName()) {if (totalCount == 0) {// This is the oldest audio of this type playing.event->setHandleToKill((*it)->m_audioEventRTS->getPlayingHandle());@@ -2022,14 +2045,14 @@ Bool MilesAudioManager::isPlayingAlready( AudioEventRTS *event ) constif (!event->isPositionalAudio()) {// 2-Dfor ( it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it ) {- if ((*it)->m_audioEventRTS->getEventName() == event->getEventName()) {+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getEventName() == event->getEventName()) {return true;}}} else {// 3-Dfor ( it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it ) {- if ((*it)->m_audioEventRTS->getEventName() == event->getEventName()) {+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getEventName() == event->getEventName()) {return true;}}@@ -2048,14 +2071,14 @@ Bool MilesAudioManager::isObjectPlayingVoice( UnsignedInt objID ) conststd::list<PlayingAudio *>::const_iterator it;// 2-Dfor ( it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it ) {- if ((*it)->m_audioEventRTS->getObjectID() == objID && (*it)->m_audioEventRTS->getAudioEventInfo()->m_type & ST_VOICE) {+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getObjectID() == objID && (*it)->m_audioEventRTS->getAudioEventInfo()->m_type & ST_VOICE) {return true;}}// 3-Dfor ( it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it ) {- if ((*it)->m_audioEventRTS->getObjectID() == objID && (*it)->m_audioEventRTS->getAudioEventInfo()->m_type & ST_VOICE) {+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getObjectID() == objID && (*it)->m_audioEventRTS->getAudioEventInfo()->m_type & ST_VOICE) {return true;}}@@ -2074,48 +2097,25 @@ AudioEventRTS* MilesAudioManager::findLowestPrioritySound( AudioEventRTS *eventreturn NULL;}AudioEventRTS *lowestPriorityEvent = NULL;- AudioPriority lowestPriority;+ AudioPriority lowestPriority = priority;+ const std::list<PlayingAudio *> &playingList = event->isPositionalAudio() ? m_playing3DSounds : m_playingSounds;std::list<PlayingAudio *>::const_iterator it;- if( event->isPositionalAudio() )+ for( it = playingList.begin(); it != playingList.end(); ++it ){- //3D- for( it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it )+ if( !(*it)->isPlaying() ){- AudioEventRTS *itEvent = (*it)->m_audioEventRTS;- AudioPriority itPriority = itEvent->getAudioEventInfo()->m_priority;- if( itPriority < priority )- {- if( !lowestPriorityEvent || lowestPriority > itPriority )- {- lowestPriorityEvent = itEvent;- lowestPriority = itPriority;- if( lowestPriority == AP_LOWEST )- {- return lowestPriorityEvent;- }- }- }+ continue;}- }- else- {- //2D- for( it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it )+ AudioEventRTS *itEvent = (*it)->m_audioEventRTS;+ AudioPriority itPriority = itEvent->getAudioEventInfo()->m_priority;+ if( itPriority < lowestPriority ){- AudioEventRTS *itEvent = (*it)->m_audioEventRTS;- AudioPriority itPriority = itEvent->getAudioEventInfo()->m_priority;- if( itPriority < priority )+ lowestPriorityEvent = itEvent;+ lowestPriority = itPriority;+ if( lowestPriority == AP_LOWEST ){- if( !lowestPriorityEvent || lowestPriority > itPriority )- {- lowestPriorityEvent = itEvent;- lowestPriority = itPriority;- if( lowestPriority == AP_LOWEST )- {- return lowestPriorityEvent;- }- }+ return lowestPriorityEvent;}}}@@ -2138,7 +2138,7 @@ Bool MilesAudioManager::isPlayingLowerPriority( AudioEventRTS *event ) constif (!event->isPositionalAudio()) {// 2-Dfor ( it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it ) {- if ((*it)->m_audioEventRTS->getAudioEventInfo()->m_priority < priority) {+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getAudioEventInfo()->m_priority < priority) {//event->setHandleToKill((*it)->m_audioEventRTS->getPlayingHandle());return true;}@@ -2146,7 +2146,7 @@ Bool MilesAudioManager::isPlayingLowerPriority( AudioEventRTS *event ) const} else {// 3-Dfor ( it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it ) {- if ((*it)->m_audioEventRTS->getAudioEventInfo()->m_priority < priority) {+ if ((*it)->isPlaying() && (*it)->m_audioEventRTS->getAudioEventInfo()->m_priority < priority) {//event->setHandleToKill((*it)->m_audioEventRTS->getPlayingHandle());return true;}@@ -2175,7 +2175,7 @@ Bool MilesAudioManager::killLowestPrioritySoundImmediately( AudioEventRTS *eventcontinue;}- if( playing->m_audioEventRTS && playing->m_audioEventRTS == lowestPriorityEvent )+ if( playing->isPlaying() && playing->m_audioEventRTS == lowestPriorityEvent ){//Release this 3D sound channel immediately because we are going to play another sound in it's place.stopPlayingAudio( playing );@@ -2186,19 +2186,19 @@ Bool MilesAudioManager::killLowestPrioritySoundImmediately( AudioEventRTS *event}else{- for( it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it )+ for( it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it ){PlayingAudio *playing = (*it);- if( !playing )+ if( !playing ){continue;}- if( playing->m_audioEventRTS && playing->m_audioEventRTS == lowestPriorityEvent )+ if( playing->isPlaying() && playing->m_audioEventRTS == lowestPriorityEvent ){- //Release this 3D sound channel immediately because we are going to play another sound in it's place.+ //Release this 2D sound channel immediately because we are going to play another sound in it's place.stopPlayingAudio( playing );- releasePlayingAudioInListIfStopped( m_playing3DSounds, m_playing3DSoundsCS );+ releasePlayingAudioInListIfStopped( m_playingSounds, m_playingSoundsCS );return TRUE;}}@@ -2217,7 +2217,7 @@ void MilesAudioManager::adjustVolumeOfPlayingAudio(AsciiString eventName, Real nPlayingAudio *playing = NULL;for (it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it) {playing = *it;- if (playing && playing->m_audioEventRTS->getEventName() == eventName) {+ if (playing && playing->isPlaying() && playing->m_audioEventRTS->getEventName() == eventName) {// Adjust itplaying->m_audioEventRTS->setVolume(newVolume);Real desiredVolume = playing->m_audioEventRTS->getVolume() * playing->m_audioEventRTS->getVolumeShift();@@ -2228,7 +2228,7 @@ void MilesAudioManager::adjustVolumeOfPlayingAudio(AsciiString eventName, Real nfor (it = m_playing3DSounds.begin(); it != m_playing3DSounds.end(); ++it) {playing = *it;- if (playing && playing->m_audioEventRTS->getEventName() == eventName) {+ if (playing && playing->isPlaying() && playing->m_audioEventRTS->getEventName() == eventName) {// Adjust itplaying->m_audioEventRTS->setVolume(newVolume);Real desiredVolume = playing->m_audioEventRTS->getVolume() * playing->m_audioEventRTS->getVolumeShift();@@ -2238,7 +2238,7 @@ void MilesAudioManager::adjustVolumeOfPlayingAudio(AsciiString eventName, Real nfor (it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it) {playing = *it;- if (playing && playing->m_audioEventRTS->getEventName() == eventName) {+ if (playing && playing->isPlaying() && playing->m_audioEventRTS->getEventName() == eventName) {// Adjust itplaying->m_audioEventRTS->setVolume(newVolume);Real desiredVolume = playing->m_audioEventRTS->getVolume() * playing->m_audioEventRTS->getVolumeShift();@@ -2465,6 +2465,7 @@ void MilesAudioManager::processPlayingList( void )if (m_volumeHasChanged) {m_volumeHasChanged = false;+ TheVideoPlayer->setVolume(getVolume(AudioAffect_Speech));}//@@ -2856,7 +2857,7 @@ Bool MilesAudioManager::startNextLoop( PlayingAudio *looping )closeFile(looping->m_file);looping->m_file = NULL;- if (looping->m_status != PS_Playing) {+ if (!looping->isPlaying() || looping->m_requestStop) {return false;}@@ -3055,7 +3056,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 played- playAudioEvent(req->releasePendingEvent());+ const Bool requestStop = req->m_requestStop;+ playAudioEvent(req->releasePendingEvent(), requestStop);break;}case AR_Pause:diff --git a/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cppindex 50ff0fab5..23f711877 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/VideoDevice/Bink/BinkVideoPlayer.cpp@@ -202,18 +202,41 @@ VideoStreamInterface* BinkVideoPlayer::createStream( HBINK handle )stream->m_player = this;m_firstStream = stream;- // never let volume go to 0, as Bink will interpret that as "play at full volume".- Int mod = (Int) ((TheAudio->getVolume(AudioAffect_Speech) * 0.8f) * 100) + 1;- Int volume = (32768*mod)/100;- DEBUG_LOG(("BinkVideoPlayer::createStream() - About to set volume (%g -> %d -> %d\n",- TheAudio->getVolume(AudioAffect_Speech), mod, volume));- BinkSetVolume( stream->m_handle,0, volume);- DEBUG_LOG(("BinkVideoPlayer::createStream() - set volume\n"));+ // Bink drops a volume set before its first BinkWait, so without this every movie played at+ // full level whatever the speech slider said.+ BinkWait( stream->m_handle );+ BinkSetVolume( stream->m_handle, 0, movieAudioVolume( TheAudio->getVolume(AudioAffect_Speech) ) );}return stream;}+//============================================================================+// BinkVideoPlayer::movieAudioVolume+//============================================================================++Int BinkVideoPlayer::movieAudioVolume( Real volume )+{+ // never let volume go to 0, as Bink will interpret that as "play at full volume".+ Int mod = (Int) ((volume * 0.8f) * 100) + 1;+ return (32768*mod)/100;+}++//============================================================================+// BinkVideoPlayer::setVolume+//============================================================================++void BinkVideoPlayer::setVolume( Real volume )+{+ // Movie audio goes out through Bink, not through the Miles mixer, so a slider change made while+ // a movie is open has to be handed to each stream.+ Int binkVolume = movieAudioVolume( volume );+ for ( VideoStreamInterface* stream = firstStream(); stream != NULL; stream = stream->next() )+ {+ BinkSetVolume( static_cast<BinkVideoStream*>( stream )->m_handle, 0, binkVolume );+ }+}+//============================================================================// BinkVideoPlayer::open//============================================================================