[Scummvm-git-logs] scummvm master -> e11744e2f0a83cdd293789baee64876ac83af560

aquadran aquadran at gmail.com
Sun Feb 14 10:31:01 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e11744e2f0 ICB: Fixed SFX audio and sound tunings


Commit: e11744e2f0a83cdd293789baee64876ac83af560
    https://github.com/scummvm/scummvm/commit/e11744e2f0a83cdd293789baee64876ac83af560
Author: Paweł Kołodziejski (aquadran at users.sourceforge.net)
Date: 2021-02-14T11:30:56+01:00

Commit Message:
ICB: Fixed SFX audio and sound tunings

Changed paths:
    engines/icb/fn_movie_pc.cpp
    engines/icb/p4_pc.cpp
    engines/icb/sound/direct_sound.cpp
    engines/icb/sound/fx_manager.cpp
    engines/icb/sound/fx_manager.h
    engines/icb/sound/music_manager.cpp
    engines/icb/sound/sound_common.cpp
    engines/icb/sound/speech_manager.cpp


diff --git a/engines/icb/fn_movie_pc.cpp b/engines/icb/fn_movie_pc.cpp
index 0193336a71..cb9a062ff7 100644
--- a/engines/icb/fn_movie_pc.cpp
+++ b/engines/icb/fn_movie_pc.cpp
@@ -73,6 +73,7 @@ mcodeFunctionReturnCodes _game_session::fn_play_movie(int32 &, int32 *params) {
 void Init_play_movie(const char *param0, bool8 param1) {
 	// Stop all sounds occuring
 	PauseSounds();
+	g_TimerOn = FALSE8;
 
 	const cstr moviename = (const cstr)param0;
 
diff --git a/engines/icb/p4_pc.cpp b/engines/icb/p4_pc.cpp
index ffbec63d82..7e1630306d 100644
--- a/engines/icb/p4_pc.cpp
+++ b/engines/icb/p4_pc.cpp
@@ -414,14 +414,6 @@ bool mainLoopIteration() {
 			mousey = event.mouse.y;
 			break;
 
-		// TODO: Fix sound
-		/*case SDL_USEREVENT:
-			if (g_TimerOn) {
-				UpdateSounds10Hz();
-				Poll_Sound_Engine();
-			}
-			break;*/
-
 		case Common::EVENT_QUIT:
 			Zdebug("\nap closed");
 			Zdebug("Be Vigilant!\n");
diff --git a/engines/icb/sound/direct_sound.cpp b/engines/icb/sound/direct_sound.cpp
index ac985cc599..3568570b09 100644
--- a/engines/icb/sound/direct_sound.cpp
+++ b/engines/icb/sound/direct_sound.cpp
@@ -25,18 +25,18 @@
  *
  */
 
-#if defined (SDL_BACKEND)
-#include <SDL.h>
-#endif
-
 #include "engines/icb/sound/direct_sound.h"
 #include "engines/icb/sound/music_manager.h"
 #include "engines/icb/sound/speech_manager.h"
 #include "engines/icb/sound/fx_manager.h"
+#include "engines/icb/sound.h"
 #include "engines/icb/icb.h"
 
 #include "audio/mixer.h"
 
+#include "common/system.h"
+#include "common/timer.h"
+
 namespace ICB {
 
 MusicManager *g_theMusicManager = NULL;
@@ -44,33 +44,18 @@ SpeechManager *g_theSpeechManager = NULL;
 FxManager *g_theFxManager = NULL;
 bool8 g_TimerOn = TRUE8;
 
-#if defined (SDL_BACKEND)
-SDL_TimerID g_timer_id = 0;
-
-Uint32 SoundEngineTimer(Uint32 interval, void *) {
-	SDL_Event event;
-	SDL_UserEvent ue;
-
-	ue.type = SDL_USEREVENT;
-	ue.code = 0;
-	ue.data1 = NULL;
-	ue.data2 = NULL;
+Common::TimerManager::TimerProc g_timer_id;
 
-	event.type = SDL_USEREVENT;
-	event.user = ue;
-
-	SDL_PushEvent(&event);
-
-	return interval;
+void SoundEngineTimer(void *ignored) {
+	if (g_TimerOn) {
+		UpdateSounds10Hz();
+		Poll_Sound_Engine();
+	}
 }
-#endif
 
 bool8 Init_Sound_Engine() {
-	// DO THIS FIRST INCASE REST OF INIT FAILS
 	// Create a timer to poll the sound engine at 100 millisecond intervals
-#if defined (SDL_BACKEND)
-	g_timer_id = SDL_AddTimer(100, SoundEngineTimer, NULL);
-#endif
+	g_system->getTimerManager()->installTimerProc(SoundEngineTimer, 100 * 1000, nullptr, "SoundEngineTimer");
 
 	// Initalize the other sections (ie music, fx and speech)
 	g_theMusicManager = new MusicManager();
@@ -81,10 +66,8 @@ bool8 Init_Sound_Engine() {
 }
 
 bool8 Close_Sound_Engine() {
-#if defined (SDL_BACKEND)
 	// Kill the sound engine timer
-	SDL_RemoveTimer(g_timer_id);
-#endif
+	g_system->getTimerManager()->removeTimerProc(g_timer_id);
 
 	// Destroy the fx manager
 	if (g_theFxManager) {
diff --git a/engines/icb/sound/fx_manager.cpp b/engines/icb/sound/fx_manager.cpp
index 9af97eedce..fa2f8297c9 100644
--- a/engines/icb/sound/fx_manager.cpp
+++ b/engines/icb/sound/fx_manager.cpp
@@ -74,23 +74,18 @@ bool8 FxManager::Poll() {
 		switch (m_effects[id].flags) {
 		// If it's playing check it hasn't finished
 		case Effect::PLAYING:
-#ifdef ENABLE_OPENAL // TODO:
 			// Apply current settings
-			alSourcef(m_effects[id].alStream.source, AL_GAIN, ((float)m_effects[id].volume) / 128.f);
-			// FIXME: correct pan value
-			alSource3f(m_effects[id].alStream.source, AL_POSITION, ((float)m_effects[id].pan) / 128.f, 0, 0);
-			frequency = (m_effects[id].pitch * stub.cycle_speed) / 100;
-			// FIXME correct pitch control
-			//				m_effects[id].buffer->SetFrequency( frequency ) ;
-			alSourcef(m_effects[id].alStream.source, AL_PITCH, 1.0f);
-
-			ALint state;
-			alGetSourcei(m_effects[id].alStream.source, AL_SOURCE_STATE, &state);
-			if (state != AL_PLAYING && state != AL_LOOPING && state != AL_PAUSED) {
-				// Finished playing so ready to go again
-				m_effects[id].flags = Effect::READY;
+			if (g_icb->_mixer->isSoundHandleActive(m_effects[id]._handle)) {
+				float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
+				g_icb->_mixer->setChannelVolume(m_effects[id]._handle, m_effects[id].volume * volumeConversion);
+				g_icb->_mixer->setChannelBalance(m_effects[id]._handle, m_effects[id].pan);
+
+				frequency = (m_effects[id].pitch * stub.cycle_speed) / 100;
+				// FIXME correct pitch control
+				//m_effects[id].buffer->SetFrequency( frequency ) ;
+				//alSourcef(m_effects[id].alStream.source, AL_PITCH, 1.0f);
 			}
-#endif
+
 			if (!g_icb->_mixer->isSoundHandleActive(m_effects[id]._handle)) {
 				// Finished playing so ready to go again
 				m_effects[id].flags = Effect::READY;
@@ -105,35 +100,21 @@ bool8 FxManager::Poll() {
 				break;
 
 		// It's waiting to play
-		case Effect::QUEUED:
+		case Effect::QUEUED: {
 
 			// Apply current settings
-			// TODO: Fix gain
-			// alSourcef(m_effects[id].alStream.source, AL_GAIN, ((float)m_effects[id].volume) / 128.f);
-			// FIXME: correct pan value
-			// alSource3f(m_effects[id].alStream.source, AL_POSITION, ((float)m_effects[id].pan) / 128.f, 0, 0);
 			frequency = (m_effects[id].pitch * stub.cycle_speed) / 100;
 			// FIXME corrent pitch control
-			//				m_effects[id].buffer->SetFrequency( frequency ) ;
-			//			alSourcef(m_effects[id].alStream.source, AL_PITCH, 1.0f);
+			//m_effects[id].buffer->SetFrequency( frequency ) ;
+			//alSourcef(m_effects[id].alStream.source, AL_PITCH, 1.0f);
 
 			// So play it
-			warning("TODO: Sound FX: Gain, Pan, Pitch, Loop");
-			// TODO: Loop-handling
-			/*
-			                        if (m_effects[id].looped != 0)
-			                                alSourcei(m_effects[id].alStream.source, AL_LOOPING, AL_TRUE);
-			                        else
-			                                alSourcei(m_effects[id].alStream.source, AL_LOOPING, AL_FALSE);
-			*/
-			if (g_icb->_mixer->isSoundHandleActive(m_effects[id]._handle)) {
-				warning("Already active");
-			}
-			g_icb->_mixer->playStream(Audio::Mixer::kSFXSoundType, &m_effects[id]._handle, m_effects[id]._stream, -1, Audio::Mixer::kMaxChannelVolume, 0,
-			                          DisposeAfterUse::NO);
-
+			float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
+			g_icb->_mixer->playStream(Audio::Mixer::kSFXSoundType, &m_effects[id]._handle,
+			                          makeLoopingAudioStream(m_effects[id]._stream, (m_effects[id].looped != 0) ? 0 : 1),
+			                          -1, m_effects[id].pan * volumeConversion, m_effects[id].pan, DisposeAfterUse::NO);
 			m_effects[id].flags = Effect::PLAYING;
-
+			}
 			break;
 		default:
 			break;
@@ -294,7 +275,7 @@ int FxManager::GetDefaultRateByName(const char * /*name*/, uint32 byteOffsetInCl
 	return (header.samplesPerSec);
 }
 
-bool8 FxManager::Load(int id, const char * /*name*/, uint32 byteOffsetInCluster) { // TODO: Verify that we are not leaking
+bool8 FxManager::Load(int id, const char * /*name*/, uint32 byteOffsetInCluster) {
 	_wavHeader header;
 	uint32 length;
 	int lengthInCycles;
@@ -321,8 +302,6 @@ bool8 FxManager::Load(int id, const char * /*name*/, uint32 byteOffsetInCluster)
 	m_effects[id].rate = header.samplesPerSec;
 	m_effects[id]._stream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
 
-	// FIXME: (header.samplesPerSec * stub.cycle_speed)/100;
-	// length of sample is (length of file)/2 samples (16-bit), = 500*length of file / sample rate
 	if (m_effects[id].rate != 0)
 		m_effects[id].length = 500 * length / m_effects[id].rate;
 	else
diff --git a/engines/icb/sound/fx_manager.h b/engines/icb/sound/fx_manager.h
index c802cb334f..3957269570 100644
--- a/engines/icb/sound/fx_manager.h
+++ b/engines/icb/sound/fx_manager.h
@@ -53,7 +53,7 @@ typedef struct Effect {
 	int rate;      // Original buffer sample rate
 	FxFlags flags; // Status of sample
 	int length;    // Length of sample in millisecs at base rate...
-	Audio::RewindableAudioStream *_stream;
+	Audio::SeekableAudioStream *_stream;
 	Audio::SoundHandle _handle;
 } Effect;
 
diff --git a/engines/icb/sound/music_manager.cpp b/engines/icb/sound/music_manager.cpp
index b188136faf..b8f296b914 100644
--- a/engines/icb/sound/music_manager.cpp
+++ b/engines/icb/sound/music_manager.cpp
@@ -51,18 +51,12 @@ MusicManager::MusicManager() {
 
 	m_fading = 0;
 	m_adjustFadeVol = 0;
-#ifdef ENABLE_OPENAL
-	alGenBuffers(1, &alStream.buffer);
-	alGenSources(1, &alStream.source);
-#endif
+
+	_audioStream = NULL;
 }
 
 MusicManager::~MusicManager() {
 	KillBuffer();
-#ifdef ENABLE_OPENAL
-	alDeleteSources(1, &alStream.source);
-	alDeleteBuffers(1, &alStream.buffer);
-#endif
 }
 
 bool8 MusicManager::UpdateMusic() {
@@ -77,11 +71,8 @@ bool8 MusicManager::UpdateMusic() {
 		if (m_adjustFadeVol != 0) {
 			// Have we faded down
 			if (m_fading == 0) {
-#ifdef ENABLE_OPENAL
-				// Stop playback and reset cursor to start
-				alSourceStop(alStream.source);
-				alSourceRewind(alStream.source);
-#endif
+				if (g_icb->_mixer->isSoundHandleActive(_handle))
+					g_icb->_mixer->stopHandle(_handle);
 				m_adjustFadeVol = 0;
 			} else {
 				AdjustVolume(m_adjustFadeVol * -1);
@@ -137,6 +128,7 @@ bool8 MusicManager::LoadMusic(const char *clusterName, uint32 byteOffsetToWav, i
 }
 
 bool8 MusicManager::StartMusic(const char *clusterName, uint32 byteOffsetToWav, int32 vol) {
+	warning("MusicManager::StartMusic");
 	if (LoadMusic(clusterName, byteOffsetToWav, vol) == TRUE8) {
 		// Regular playback
 		m_adjustFadeVol = 0;
@@ -156,8 +148,9 @@ bool8 MusicManager::PlayMusic() {
 	m_adjustFadeVol = 0;
 
 	// Play the sound buffer
-	g_icb->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_handle, _audioStream);
-	// Autofreed for now
+	float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
+	g_icb->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_handle, _audioStream,
+	                          -1, m_musicVol * volumeConversion, 0, DisposeAfterUse::YES);
 
 	return TRUE8;
 }
@@ -186,7 +179,8 @@ void MusicManager::SetMusicPausedStatus(bool8 p) {
 			return;
 
 		// Stop playback leaving cursors alone
-		g_icb->_mixer->pauseHandle(_handle, true);
+		if (g_icb->_mixer->isSoundHandleActive(_handle))
+			g_icb->_mixer->pauseHandle(_handle, true);
 
 		m_paused = TRUE8;
 	} else {
@@ -194,7 +188,8 @@ void MusicManager::SetMusicPausedStatus(bool8 p) {
 			m_paused = FALSE8;
 
 			// Play from where we left off
-			g_icb->_mixer->pauseHandle(_handle, false);
+			if (g_icb->_mixer->isSoundHandleActive(_handle))
+				g_icb->_mixer->pauseHandle(_handle, false);
 		}
 	}
 }
@@ -210,9 +205,8 @@ bool8 MusicManager::IsPlaying() {
 	if (noSoundEngine)
 		return FALSE8;
 
-	if (g_icb->_mixer->isSoundHandleActive(_handle)) {
+	if (g_icb->_mixer->isSoundHandleActive(_handle))
 		return TRUE8;
-	}
 
 	return FALSE8;
 }
@@ -220,28 +214,35 @@ bool8 MusicManager::IsPlaying() {
 void MusicManager::SetVolume(int volume) {
 	// Store and set correct volume
 	m_musicVol = volume;
-#ifdef ENABLE_OPENAL
-	alSourcef(alStream.source, AL_GAIN, ((float)volume) / 128.f);
-#endif
+
+	if (g_icb->_mixer->isSoundHandleActive(_handle)) {
+		float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
+		g_icb->_mixer->setChannelVolume(_handle, volume * volumeConversion);
+	}
 }
 
 void MusicManager::AdjustVolume(int amount) {
-	// FIXME: proper calculations
-#ifdef ENABLE_OPENAL
-	alSourcef(alStream.source, AL_GAIN, ((float)amount) / 128.f);
-#endif
+	int musicVol = m_musicVol;
+	musicVol += amount;
+	if (musicVol > 127)
+		musicVol = 127;
+	if (musicVol < 0)
+		musicVol = 0;
+	m_musicVol = musicVol;
+	if (g_icb->_mixer->isSoundHandleActive(_handle)) {
+		float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
+		g_icb->_mixer->setChannelVolume(_handle, musicVol * volumeConversion);
+	}
 }
 
 bool8 MusicManager::OpenMusic(Common::SeekableReadStream *stream) {
 	_wavHeader header;
 
 	if (openWav(stream, header, m_wavDataSize, m_wavByteOffsetInCluster, m_lengthInCycles) == FALSE8) {
+		delete stream;
 		return FALSE8;
 	}
 	_audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
-#ifdef ENABLE_OPENAL
-	// FIXME: (header.samplesPerSec * stub.cycle_speed)/100;
-#endif
 	return TRUE8;
 }
 
@@ -249,9 +250,8 @@ void MusicManager::KillBuffer() {
 	if (noSoundEngine)
 		return;
 
-	if (g_icb->_mixer->isSoundHandleActive(_handle)) {
+	if (g_icb->_mixer->isSoundHandleActive(_handle))
 		g_icb->_mixer->stopHandle(_handle);
-	}
 
 	m_identifier = 0;
 }
diff --git a/engines/icb/sound/sound_common.cpp b/engines/icb/sound/sound_common.cpp
index 9474e46d2e..16a8a76aac 100644
--- a/engines/icb/sound/sound_common.cpp
+++ b/engines/icb/sound/sound_common.cpp
@@ -38,7 +38,6 @@ namespace ICB {
 bool8 openWav(Common::SeekableReadStream *stream, _wavHeader &header, uint32 &length, uint32 &byteOffsetInCluster, int &lengthInCycles) {
 
 	int pos = stream->pos();
-	// TODO: fopen must happen before
 	int bytesRead;
 	char buff[1024];
 	bool bMore = true;
@@ -48,7 +47,7 @@ bool8 openWav(Common::SeekableReadStream *stream, _wavHeader &header, uint32 &le
 		return FALSE8;
 
 	if (header.formatTag != 1) {
-		warning("DirectSound only supports PCM uncompressed wav files");
+		warning("Only supports PCM uncompressed wav files");
 		return FALSE8;
 	}
 
diff --git a/engines/icb/sound/speech_manager.cpp b/engines/icb/sound/speech_manager.cpp
index e52109a531..0b29ca32f4 100644
--- a/engines/icb/sound/speech_manager.cpp
+++ b/engines/icb/sound/speech_manager.cpp
@@ -48,8 +48,9 @@ SpeechManager::SpeechManager() {
 
 	m_paused = FALSE8;
 	m_lengthInCycles = 0;
-	_audioStream = NULL;
 	m_speechVol = 0;
+
+	_audioStream = NULL;
 }
 
 SpeechManager::~SpeechManager() { KillBuffer(); }
@@ -91,10 +92,9 @@ bool8 SpeechManager::StartSpeech(const char *fileName, uint32 byteOffsetToWav, i
 		return FALSE8;
 	}
 
-	// Record & Set the volume
-	SetVolume(vol);
-
-	g_icb->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_handle, _audioStream);
+	float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
+	g_icb->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_handle, _audioStream,
+	                          -1, vol * volumeConversion, 0, DisposeAfterUse::YES);
 
 	return TRUE8;
 }
@@ -126,7 +126,9 @@ void SpeechManager::PauseSpeech() {
 	if (m_paused || !IsPlaying())
 		return;
 
-	g_icb->_mixer->pauseHandle(_handle, true);
+	if (g_icb->_mixer->isSoundHandleActive(_handle))
+		g_icb->_mixer->pauseHandle(_handle, true);
+
 	m_paused = TRUE8;
 }
 
@@ -136,7 +138,9 @@ void SpeechManager::ResumeSpeech() {
 
 	if (m_paused) {
 		m_paused = FALSE8;
-		g_icb->_mixer->pauseHandle(_handle, false);
+		if (g_icb->_mixer->isSoundHandleActive(_handle)) {
+			g_icb->_mixer->pauseHandle(_handle, false);
+		}
 	}
 }
 
@@ -148,8 +152,10 @@ void SpeechManager::SetSpeechVolume(int volume) {
 }
 
 void SpeechManager::SetVolume(int volume) {
-	float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
-	g_icb->_mixer->setChannelVolume(_handle, volume * volumeConversion);
+	if (g_icb->_mixer->isSoundHandleActive(_handle)) {
+		float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
+		g_icb->_mixer->setChannelVolume(_handle, volume * volumeConversion);
+	}
 }
 
 bool8 SpeechManager::OpenSpeech(Common::SeekableReadStream *stream) {
@@ -157,6 +163,7 @@ bool8 SpeechManager::OpenSpeech(Common::SeekableReadStream *stream) {
 
 	// Get the length etc.
 	if (openWav(stream, header, m_wavDataSize, m_wavByteOffsetInCluster, m_lengthInCycles) != TRUE8) {
+		delete stream;
 		return FALSE8;
 	}
 




More information about the Scummvm-git-logs mailing list