[Scummvm-cvs-logs] CVS: scummvm/sound flac.cpp,1.3,1.4 mixer.cpp,1.174,1.175 mixer.h,1.87,1.88 mp3.cpp,1.14,1.15 vorbis.cpp,1.18,1.19

Max Horn fingolfin at users.sourceforge.net
Sun Dec 26 16:28:02 CET 2004


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17934/sound

Modified Files:
	flac.cpp mixer.cpp mixer.h mp3.cpp vorbis.cpp 
Log Message:
Added 'sound types' to the mixer - for now, only plain (for the premixer), SFX and music; volume is now controlled based on the sound type

Index: flac.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/flac.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- flac.cpp	28 Jun 2004 22:35:21 -0000	1.3
+++ flac.cpp	27 Dec 2004 00:26:59 -0000	1.4
@@ -783,7 +783,7 @@
 			flac->setLastSample(0);
 
 		if (flac->seekAbsolute(static_cast<FLAC__uint64>(startFrame) * (info.sample_rate / 75))) {
-			mixer->playInputStream(handle, flac, true);
+			mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, flac);
 			return;
 		}
 		// startSample is beyond the existing Samples

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.174
retrieving revision 1.175
diff -u -d -r1.174 -r1.175
--- mixer.cpp	28 Nov 2004 23:02:26 -0000	1.174
+++ mixer.cpp	27 Dec 2004 00:26:59 -0000	1.175
@@ -41,11 +41,12 @@
  * Channels used by the sound mixer.
  */
 class Channel {
+public:
+	const SoundMixer::SoundType	_type;
 private:
 	SoundMixer *_mixer;
 	PlayingSoundHandle *_handle;
 	bool _autofreeStream;
-	const bool _isMusic;
 	bool _permanent;
 	byte _volume;
 	int8 _balance;
@@ -61,8 +62,8 @@
 
 public:
 
-	Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, int id = -1);
-	Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input, bool autofreeStream, bool isMusic, bool reverseStereo = false, int id = -1, bool permanent = false);
+	Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id = -1);
+	Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, bool autofreeStream, bool reverseStereo = false, int id = -1, bool permanent = false);
 	virtual ~Channel();
 
 	void mix(int16 *data, uint len);
@@ -73,9 +74,6 @@
 	bool isFinished() const {
 		return _input->endOfStream();
 	}
-	bool isMusicChannel() const {
-		return _isMusic;
-	}
 	void pause(bool paused) {
 		_paused = paused;
 	}
@@ -107,8 +105,8 @@
 	_premixChannel = 0;
 	int i = 0;
 
-	_globalVolume = 0;
-	_musicVolume = 0;
+	for (i = 0; i < ARRAYSIZE(_volumeForSoundType); i++)
+		_volumeForSoundType[i] = 256;
 
 	_paused = false;
 	
@@ -148,7 +146,7 @@
 		return;
 
 	// Create the channel
-	_premixChannel = new Channel(this, 0, stream, false, true);
+	_premixChannel = new Channel(this, 0, kPlainAudioDataType, stream, false);
 }
 
 void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
@@ -172,7 +170,7 @@
 }
 
 void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags,
-			int id, byte volume, int8 balance, uint32 loopStart, uint32 loopEnd) {
+			int id, byte volume, int8 balance, uint32 loopStart, uint32 loopEnd, SoundType type) {
 	Common::StackLock lock(_mutex);
 
 	// Prevent duplicate sounds
@@ -199,13 +197,13 @@
 	}
 
 	// Create the channel
-	Channel *chan = new Channel(this, handle, input, true, false, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id);
+	Channel *chan = new Channel(this, handle, type, input, true, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id);
 	chan->setVolume(volume);
 	chan->setBalance(balance);
 	insertChannel(handle, chan);
 }
 
-void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic,
+void SoundMixer::playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input,
 			int id, byte volume, int8 balance, bool autofreeStream, bool permanent) {
 	Common::StackLock lock(_mutex);
 
@@ -225,7 +223,7 @@
 	}
 
 	// Create the channel
-	Channel *chan = new Channel(this, handle, input, autofreeStream, isMusic, false, id, permanent);
+	Channel *chan = new Channel(this, handle, type, input, autofreeStream, false, id, permanent);
 	chan->setVolume(volume);
 	chan->setBalance(balance);
 	insertChannel(handle, chan);
@@ -396,16 +394,17 @@
 	return false;
 }
 
-bool SoundMixer::hasActiveSFXChannel() {
-	// FIXME/TODO: We need to distinguish between SFX and music channels
+bool SoundMixer::hasActiveChannelOfType(SoundType type) {
 	Common::StackLock lock(_mutex);
 	for (int i = 0; i != NUM_CHANNELS; i++)
-		if (_channels[i] && !_channels[i]->isMusicChannel())
+		if (_channels[i] && !_channels[i]->_type == type)
 			return true;
 	return false;
 }
 
-void SoundMixer::setVolume(int volume) {
+void SoundMixer::setVolumeForSoundType(SoundType type, int volume) {
+	assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType));
+
 	// Check range
 	if (volume > 256)
 		volume = 256;
@@ -415,17 +414,13 @@
 	// TODO: Maybe we should do logarithmic (not linear) volume
 	// scaling? See also Player_V2::setMasterVolume
 
-	_globalVolume = volume;
+	_volumeForSoundType[type] = volume;
 }
 
-void SoundMixer::setMusicVolume(int volume) {
-	// Check range
-	if (volume > 256)
-		volume = 256;
-	else if (volume < 0)
-		volume = 0;
-
-	_musicVolume = volume;
+int SoundMixer::getVolumeForSoundType(SoundType type) const {
+	assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType));
+	
+	return _volumeForSoundType[type];
 }
 
 
@@ -434,16 +429,16 @@
 #pragma mark -
 
 
-Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, int id)
-	: _mixer(mixer), _handle(handle), _autofreeStream(true), _isMusic(isMusic),
+Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id)
+	: _type(type), _mixer(mixer), _handle(handle), _autofreeStream(true),
 	  _volume(255), _balance(0), _paused(false), _id(id), _samplesConsumed(0),
 	  _samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(0) {
 	assert(mixer);
 }
 
-Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioStream *input,
-				bool autofreeStream, bool isMusic, bool reverseStereo, int id, bool permanent)
-	: _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream), _isMusic(isMusic),
+Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input,
+				bool autofreeStream, bool reverseStereo, int id, bool permanent)
+	: _type(type), _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream),
 	  _volume(255), _balance(0), _paused(false), _id(id), _samplesConsumed(0),
 	  _samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(input), _permanent(permanent) {
 	assert(mixer);
@@ -481,7 +476,7 @@
 		// volume is in the range 0 - 256.
 		// Hence, the vol_l/vol_r values will be in that range, too
 		
-		int vol = (isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume()) * _volume;
+		int vol = _mixer->getVolumeForSoundType(_type) * _volume;
 		st_volume_t vol_l, vol_r;
 
 		if (_balance == 0) {

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- mixer.h	28 Nov 2004 23:24:32 -0000	1.87
+++ mixer.h	27 Dec 2004 00:26:59 -0000	1.88
@@ -68,6 +68,14 @@
 		/** loop the audio */
 		FLAG_LOOP = 1 << 6
 	};
+	
+	enum SoundType {
+		kPlainAudioDataType = 0,
+
+		kMusicAudioDataType = 1,
+		kSFXAudioDataType = 2
+		// kSpeechAudioDataType = 3	  TODO: Add this type later...
+	};
 
 private:
 	enum {
@@ -81,8 +89,7 @@
 
 	uint _outputRate;
 
-	int _globalVolume;
-	int _musicVolume;
+	int _volumeForSoundType[4];
 
 	bool _paused;
 	
@@ -123,14 +130,16 @@
 	 * (using the makeLinearInputStream factory function), which is then
 	 * passed on to playInputStream.
 	 */
-	void playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags,
+	void playRaw(PlayingSoundHandle *handle,
+				void *sound, uint32 size, uint rate, byte flags,
 				int id = -1, byte volume = 255, int8 balance = 0,
-				uint32 loopStart = 0, uint32 loopEnd = 0);
+				uint32 loopStart = 0, uint32 loopEnd = 0,
+				SoundType type = kSFXAudioDataType);
 
 	/**
 	 * Start playing the given audio input stream.
 	 */
-	void playInputStream(PlayingSoundHandle *handle, AudioStream *input, bool isMusic,
+	void playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input,
 				int id = -1, byte volume = 255, int8 balance = 0,
 				bool autofreeStream = true, bool permanent = false);
 
@@ -223,39 +232,28 @@
 	uint32 getSoundElapsedTime(PlayingSoundHandle handle);
 
 	/**
-	 * Check whether any SFX channel is active.
+	 * Check whether any channel of the given sound type is active.
+	 * For example, this can be used to check whether any SFX sound
+	 * is currently playing, by checking for type kSFXAudioDataType.
 	 *
-	 * @return true if any SFX (= non-music) channels are active.
+	 * @param  type the sound type to look for
+	 * @return true if any channels of the specified type are active.
 	 */
-	bool hasActiveSFXChannel();
+	bool hasActiveChannelOfType(SoundType type);
 
 	/**
-	 * Set the global volume.
+	 * Set the volume for the given sound type.
 	 *
 	 * @param volume the new global volume, 0-256
 	 */
-	void setVolume(int volume);
+	void setVolumeForSoundType(SoundType type, int volume);
 
 	/**
 	 * Query the global volume.
 	 *
 	 * @return the global music volume, 0-256
 	 */
-	int getVolume() const { return _globalVolume; }
-
-	/**
-	 * Set the music volume.
-	 *
-	 * @param volume the new music volume, 0-256
-	 */
-	void setMusicVolume(int volume);
-
-	/**
-	 * Query the music volume.
-	 *
-	 * @return the current music volume, 0-256
-	 */
-	int getMusicVolume() const { return _musicVolume; }
+	int getVolumeForSoundType(SoundType type) const;
 
 	/**
 	 * Query the system's audio output sample rate. This returns

Index: mp3.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mp3.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mp3.cpp	27 Nov 2004 13:54:08 -0000	1.14
+++ mp3.cpp	27 Dec 2004 00:26:59 -0000	1.15
@@ -380,7 +380,7 @@
 
 	// Play it
 	AudioStream *input = new MP3InputStream(_file, durationTime);
-	mixer->playInputStream(handle, input, true);
+	mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, input);
 }
 
 MP3TrackInfo::~MP3TrackInfo() {

Index: vorbis.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/vorbis.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- vorbis.cpp	27 Nov 2004 13:54:08 -0000	1.18
+++ vorbis.cpp	27 Dec 2004 00:26:59 -0000	1.19
@@ -178,7 +178,7 @@
 #endif
 
 	AudioStream *input = makeVorbisStream(&_ov_file, duration * ov_info(&_ov_file, -1)->rate / 75);
-	mixer->playInputStream(handle, input, true);
+	mixer->playInputStream(SoundMixer::kMusicAudioDataType, handle, input);
 }
 
 DigitalTrackInfo *getVorbisTrack(int track) {





More information about the Scummvm-git-logs mailing list