[Scummvm-cvs-logs] scummvm master -> b7dcf5f6c1f560d668d3857012e98a91bcf881d4

csnover csnover at users.noreply.github.com
Fri Jul 1 19:44:23 CEST 2016


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

Summary:
e8552cf96c SCI32: Fix audio fading
b7dcf5f6c1 SCI32: Use better audio fading algorithm


Commit: e8552cf96c91094bd69d7ca5859008a0f18f7957
    https://github.com/scummvm/scummvm/commit/e8552cf96c91094bd69d7ca5859008a0f18f7957
Author: Colin Snover (github.com at zetafleet.com)
Date: 2016-07-01T12:42:39-05:00

Commit Message:
SCI32: Fix audio fading

Changed paths:
    engines/sci/sound/soundcmd.cpp



diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp
index c5d8dda..c3c159d 100644
--- a/engines/sci/sound/soundcmd.cpp
+++ b/engines/sci/sound/soundcmd.cpp
@@ -411,7 +411,7 @@ reg_t SoundCommandParser::kDoSoundFade(int argc, reg_t *argv, reg_t acc) {
 
 #ifdef ENABLE_SCI32
 	if (_soundVersion >= SCI_VERSION_2_1_EARLY && musicSlot->isSample) {
-		g_sci->_audio32->fadeChannel(ResourceId(kResourceTypeAudio, musicSlot->resourceId), musicSlot->soundObj, argv[2].toSint16(), argv[3].toSint16(), argv[4].toSint16(), (bool)argv[5].toSint16());
+		g_sci->_audio32->fadeChannel(ResourceId(kResourceTypeAudio, musicSlot->resourceId), musicSlot->soundObj, argv[1].toSint16(), argv[2].toSint16(), argv[3].toSint16(), argc > 4 ? (bool)argv[4].toSint16() : false);
 		return acc;
 	}
 #endif


Commit: b7dcf5f6c1f560d668d3857012e98a91bcf881d4
    https://github.com/scummvm/scummvm/commit/b7dcf5f6c1f560d668d3857012e98a91bcf881d4
Author: Colin Snover (github.com at zetafleet.com)
Date: 2016-07-01T12:43:39-05:00

Commit Message:
SCI32: Use better audio fading algorithm

Using the one from SCI2.1mid makes fades very slow because SDL has
a larger audio buffer than SSCI DOS. This new algorithm is based on
wall time so will always fade at the correct speed, although the
larger buffers will have a coarser granularity so the fades may
not be as smooth as in the original engine. If anyone cares, the
fade volume could be mixed into individual samples in `readBuffer`
instead of applying just once per complete buffer. SSCI did not
do this, however, so this implementation should be pretty accurate.

Changed paths:
    engines/sci/sound/audio32.cpp
    engines/sci/sound/audio32.h



diff --git a/engines/sci/sound/audio32.cpp b/engines/sci/sound/audio32.cpp
index ced88a3..4689d13 100644
--- a/engines/sci/sound/audio32.cpp
+++ b/engines/sci/sound/audio32.cpp
@@ -305,7 +305,7 @@ int Audio32::readBuffer(Audio::st_sample_t *buffer, const int numSamples) {
 
 		// Channel finished fading and had the
 		// stopChannelOnFade flag set, so no longer exists
-		if (channel.fadeStepsRemaining && processFade(channelIndex)) {
+		if (channel.fadeStartTick && processFade(channelIndex)) {
 			--channelIndex;
 			continue;
 		}
@@ -602,8 +602,7 @@ uint16 Audio32::play(int16 channelIndex, const ResourceId resourceId, const bool
 	channel.loop = loop;
 	channel.robot = false;
 	channel.vmd = false;
-	channel.lastFadeTick = 0;
-	channel.fadeStepsRemaining = 0;
+	channel.fadeStartTick = 0;
 	channel.soundNode = soundNode;
 	channel.volume = volume < 0 || volume > kMaxVolume ? (int)kMaxVolume : volume;
 	// TODO: SCI3 introduces stereo audio
@@ -927,12 +926,12 @@ bool Audio32::fadeChannel(const int16 channelIndex, const int16 targetVolume, co
 		return false;
 	}
 
-	if (steps) {
-		channel.fadeVolume = targetVolume;
-		channel.fadeSpeed = speed;
-		channel.fadeStepsRemaining = steps;
+	if (steps && speed) {
+		channel.fadeStartTick = g_sci->getTickCount();
+		channel.fadeStartVolume = channel.volume;
+		channel.fadeTargetVolume = targetVolume;
+		channel.fadeDuration = speed * steps;
 		channel.stopChannelOnFade = stopAfterFade;
-		channel.lastFadeTick = g_sci->getTickCount();
 	} else {
 		setVolume(channelIndex, targetVolume);
 	}
@@ -944,28 +943,28 @@ bool Audio32::processFade(const int16 channelIndex) {
 	Common::StackLock lock(_mutex);
 	AudioChannel &channel = getChannel(channelIndex);
 
-	uint32 now = g_sci->getTickCount();
-
-	if (channel.lastFadeTick + channel.fadeSpeed <= now) {
-		--channel.fadeStepsRemaining;
-
-		if (!channel.fadeStepsRemaining) {
+	if (channel.fadeStartTick) {
+		const uint32 fadeElapsed = g_sci->getTickCount() - channel.fadeStartTick;
+		if (fadeElapsed > channel.fadeDuration) {
+			channel.fadeStartTick = 0;
 			if (channel.stopChannelOnFade) {
 				stop(channelIndex);
 				return true;
 			} else {
-				setVolume(channelIndex, channel.fadeVolume);
-			}
-		} else {
-			int volume = channel.volume - (channel.volume - channel.fadeVolume) / (channel.fadeStepsRemaining + 1);
-
-			if (volume == channel.fadeVolume) {
-				channel.fadeStepsRemaining = 1;
+				setVolume(channelIndex, channel.fadeTargetVolume);
 			}
+			return false;
+		}
 
-			setVolume(channelIndex, volume);
-			channel.lastFadeTick = now;
+		int volume;
+		if (channel.fadeStartVolume > channel.fadeTargetVolume) {
+			volume = channel.fadeStartVolume - fadeElapsed * (channel.fadeStartVolume - channel.fadeTargetVolume) / channel.fadeDuration;
+		} else {
+			volume = channel.fadeStartVolume + fadeElapsed * (channel.fadeTargetVolume - channel.fadeStartVolume) / channel.fadeDuration;
 		}
+
+		setVolume(channelIndex, volume);
+		return false;
 	}
 
 	return false;
diff --git a/engines/sci/sound/audio32.h b/engines/sci/sound/audio32.h
index 416b81d..42211eb89 100644
--- a/engines/sci/sound/audio32.h
+++ b/engines/sci/sound/audio32.h
@@ -90,27 +90,25 @@ struct AudioChannel {
 	bool loop;
 
 	/**
-	 * The time the last fade iteration occurred.
+	 * The time, in ticks, that the channel fade began.
+	 * If 0, the channel is not being faded.
 	 */
-	uint32 lastFadeTick;
+	uint32 fadeStartTick;
 
 	/**
-	 * The target volume of the fade.
+	 * The start volume of a fade.
 	 */
-	int fadeVolume;
+	int fadeStartVolume;
 
 	/**
-	 * The number of ticks that should elapse between
-	 * each change of volume.
+	 * The total length of the fade, in ticks.
 	 */
-	int fadeSpeed;
+	uint32 fadeDuration;
 
 	/**
-	 * The number of iterations the fade should take to
-	 * complete. If this value is 0, it indicates that the
-	 * channel is not fading.
+	 * The end volume of a fade.
 	 */
-	int fadeStepsRemaining;
+	uint32 fadeTargetVolume;
 
 	/**
 	 * Whether or not the channel should be stopped and






More information about the Scummvm-git-logs mailing list