[Scummvm-cvs-logs] SF.net SVN: scummvm: [29648] scummvm/trunk/engines/lure/sound.cpp

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Tue Nov 27 11:09:43 CET 2007


Revision: 29648
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29648&view=rev
Author:   dreammaster
Date:     2007-11-27 02:09:42 -0800 (Tue, 27 Nov 2007)

Log Message:
-----------
- Changed sound creation to automatically reset volume so that introduction sound sequences play correctly
- Cleaned up my channel sharing code to allow for either cropping the number of channels used or use the same channel multiple times. Ideally, though, I need to find out if the MidiParser can be set to use less than 8 channels

Modified Paths:
--------------
    scummvm/trunk/engines/lure/sound.cpp

Modified: scummvm/trunk/engines/lure/sound.cpp
===================================================================
--- scummvm/trunk/engines/lure/sound.cpp	2007-11-27 10:02:53 UTC (rev 29647)
+++ scummvm/trunk/engines/lure/sound.cpp	2007-11-27 10:09:42 UTC (rev 29648)
@@ -35,6 +35,8 @@
 
 namespace Lure {
 
+//#define SOUND_CROP_CHANNELS
+
 SoundManager::SoundManager() {
 	_soundMutex = g_system->createMutex();
 
@@ -183,7 +185,7 @@
 		return;
 
 	SoundDescResource &rec = soundDescs()[soundIndex];
-	int numChannels = (rec.numChannels >> 2) & 3;
+	int numChannels = 2; //(rec.numChannels >> 2) & 3;
 
 	int channelCtr = 0;
 	while (channelCtr <= (NUM_CHANNELS_OUTER - numChannels)) {
@@ -221,12 +223,8 @@
 	newEntry->volume = rec.volume;
 	_activeSounds.push_back(newEntry);
 
-	// TODO: Figure a better way of sharing channels between multiple parsers - currently
-	// each parser seems to use 8 channels of a maximum 16 available, but here I'm 
-	// overlapping channels 4 - 7 (3rd & 4th parser) across the other two
-	byte innerChannel = (channelCtr < 4) ? ((channelCtr / 2) * 8) :
-		(4 + (channelCtr / 2) * 8);
-
+	// Map each two channels to four of the 16 available channels
+	byte innerChannel = (channelCtr / 2) * 4;
 	musicInterface_Play(rec.soundNumber, innerChannel);
 	setVolume(rec.soundNumber, rec.volume);	
 }
@@ -377,7 +375,7 @@
 			MidiMusic *music = *i;
 			if (music->getVolume() > 0) {
 				inProgress = true;
-				music->setVolume(music->getVolume() > 4 ? (music->getVolume() - 10) : 0);
+				music->setVolume(music->getVolume() >= 10 ? (music->getVolume() - 10) : 0);
 			}
 		}
 
@@ -427,6 +425,7 @@
 	g_system->lockMutex(_soundMutex);
 	MidiMusic *sound = new MidiMusic(_driver, _channelsInner, channelNumber, soundNumber, 
 		soundStart, dataSize);
+	sound->setVolume(DEFAULT_VOLUME);
 	_playingSounds.push_back(sound);		
 	g_system->unlockMutex(_soundMutex);
 }
@@ -574,15 +573,10 @@
 	_channels = channels;
 	_soundNumber = soundNum;
 	_channelNumber = channelNum;
-	
-	_numChannels = 8;
-	while ((_numChannels > 0) && ((_channelNumber + _numChannels > NUM_CHANNELS_INNER) ||
-			(_channels[_channelNumber + _numChannels - 1].midiChannel == NULL)))
-		--_numChannels;
-	if (_numChannels == 0)
-		error("Unable to set any channels for MidiMusic object");
 
-	_volume = _channels[channelNum].volume;
+	_numChannels = 4;
+	_volume = 0xff;
+	setVolume(DEFAULT_VOLUME);
 
 	_passThrough = false;
 
@@ -640,9 +634,11 @@
 
 	_volume = volume;
 
-	for (int i = 0; i < _numChannels; ++i) 
-		_channels[_channelNumber + i].midiChannel->volume(
-			_channels[_channelNumber + i].volume * _volume / 255);
+	for (int i = 0; i < _numChannels; ++i) {
+		if (_channels[_channelNumber + i].midiChannel != NULL)
+			_channels[_channelNumber + i].midiChannel->volume(
+				_channels[_channelNumber + i].volume * _volume / 255);
+	}
 }
 
 void MidiMusic::playMusic() {
@@ -669,7 +665,13 @@
 		return;
 	}
 
+#ifdef SOUND_CROP_CHANNELS
+	if ((b & 0xF) >= _numChannels) return;
 	byte channel = _channelNumber + (byte)(b & 0x0F);
+#else
+	byte channel = _channelNumber + ((byte)(b & 0x0F) % _numChannels);
+#endif
+
 	if ((channel >= NUM_CHANNELS_INNER) || (_channels[channel].midiChannel == NULL))
 		return;
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list