[Scummvm-cvs-logs] CVS: scummvm/sword2/driver d_sound.cpp,1.94,1.95 d_sound.h,1.38,1.39 driver96.h,1.67,1.68

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Sat Jan 3 03:25:10 CET 2004


Update of /cvsroot/scummvm/scummvm/sword2/driver
In directory sc8-pr-cvs1:/tmp/cvs-serv20292/driver

Modified Files:
	d_sound.cpp d_sound.h driver96.h 
Log Message:
Made the music code more like the one in BS1, i.e. the fade time is longer
and it now fades both up and down.

Plenty of cleanups, simplifications and just moving code around to group it
in what I hope is a more logical fashion.

Fixed a long-standing bug where spot effects would eventually use up all
available sound effect handles. (I may have introduced this when I removed
the expiration of sound effects from FxServer().)


Index: d_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_sound.cpp,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -d -r1.94 -r1.95
--- d_sound.cpp	1 Jan 2004 15:15:47 -0000	1.94
+++ d_sound.cpp	3 Jan 2004 11:24:39 -0000	1.95
@@ -39,9 +39,6 @@
 
 namespace Sword2 {
 
-// Fade-out takes half a second. This may need some tuning.
-#define FADE_SAMPLES 11025
-
 static File fpMus;
 
 // Decompression macros
@@ -49,12 +46,142 @@
 #define GetCompressedSign(n)       (((n) >> 3) & 1)
[...1573 lines suppressed...]
 }
 
 /**
- * @return the music's mute state, true if mute, false if not mute
+ * This function clears all of the sound effects which are currently open or
+ * playing, irrespective of type.
  */
 
-bool Sound::isMusicMute(void) {
-	return _musicMuted;
+void Sound::clearAllFx(void) {
+	if (!_soundOn)
+		return;
+
+	for (int i = 0; i < MAXFX; i++)
+		if (_fx[i]._id && _fx[i]._id != -1 && _fx[i]._id != -2)
+			stopFxHandle(i);
 }
 
 } // End of namespace Sword2

Index: d_sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_sound.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- d_sound.h	31 Dec 2003 14:05:53 -0000	1.38
+++ d_sound.h	3 Jan 2004 11:24:39 -0000	1.39
@@ -46,7 +46,6 @@
 
 class MusicHandle : public AudioInputStream {
 public:
-	uint32 _id;
 	bool _firstTime;
 	bool _streaming;
 	bool _paused;
@@ -57,26 +56,22 @@
 	int32 _fileEnd;
 	uint16 _lastSample;
 
-	bool isStereo()	const	{ return false; }
-	int getRate() const	{ return 22050; }
-
-	virtual int readBuffer(int16 *buffer, const int numSamples) {
-		int samples;
-		for (samples = 0; samples < numSamples && !endOfData(); samples++) {
-			*buffer++ = read();
-		}
-		return samples;
-	}
+	bool isStereo(void) const	{ return false; }
+	int getRate(void) const		{ return 22050; }
 
-	int16 read();
-	bool endOfData() const;
+	void fadeDown(void);
+	void fadeUp(void);
+	int32 play(const char *filename, uint32 musicId, bool looping);
+	void stop(void);
+	virtual int readBuffer(int16 *buffer, const int numSamples);
+	int16 read(void);
+	bool endOfData(void) const;
 	// This stream never 'ends'
-	bool endOfStream() const { return false; }
+	bool endOfStream(void) const { return false; }
 
-	MusicHandle() : _firstTime(false),
-			_streaming(false), _paused(false), _looping(false),
-			_fading(0), _fileStart(0), _filePos(0), _fileEnd(0),
-			_lastSample(0) {}
+	MusicHandle() : _firstTime(false), _streaming(false), _paused(false),
+			_looping(false), _fading(0), _fileStart(0),
+			_filePos(0), _fileEnd(0), _lastSample(0) {}
 };
 
 class Sound {
@@ -84,75 +79,80 @@
 	Sword2Engine *_vm;
 
 	OSystem::MutexRef _mutex;
-	RateConverter *_converter;
 
 	int32 _panTable[33];
+	bool _soundOn;
 
-	FxHandle _fx[MAXFX];
+	static int32 _musicVolTable[17];
 	MusicHandle _music[MAXMUS + 1];
+	char *savedMusicFilename;
+	RateConverter *_converter;
+	bool _musicMuted;
+	uint8 _musicVol;
 
-	bool _soundOn;
+	void updateCompSampleStreaming(int16 *data, uint len);
+	int32 dipMusic(void);
+
+	PlayingSoundHandle _soundHandleSpeech;
 	bool _speechStatus;
 	bool _speechPaused;
-	bool _fxPaused;
-	bool _musicMuted;
 	bool _speechMuted;
-	bool _fxMuted;
-	uint8 _musicVol;
 	uint8 _speechVol;
-	uint8 _fxVol;
 
-	PlayingSoundHandle _soundHandleSpeech;
+	FxHandle _fx[MAXFX];
+	bool _fxPaused;
+	bool _fxMuted;
+	uint8 _fxVol;
 
 	int32 getFxIndex(int32 id);
-	int32 dipMusic();
-
-	void updateCompSampleStreaming(int16 *data, uint len);
-
-	char *savedMusicFilename;
+	void stopFxHandle(int i);
 
 public:
 	Sound(Sword2Engine *vm);
 	~Sound();
+
 	void fxServer(int16 *data, uint len);
-	int32 playCompSpeech(const char *filename, uint32 speechid, uint8 vol, int8 pan);
-	uint32 preFetchCompSpeech(const char *filename, uint32 speechid, uint16 **buf);
-	int32 amISpeaking();
-	int32 stopSpeech(void);
-	int32 getSpeechStatus(void);
-	void pauseSpeech(void);
-	void unpauseSpeech(void);
-	int32 openFx(int32 id, uint8 *data);
-	int32 playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type);
-	int32 closeFx(int32 id);
-	void clearAllFx(void);
-	void pauseFx(void);
-	void pauseFxForSequence(void);
-	void unpauseFx(void);
+	void buildPanTable(bool reverse);
+
+	void muteMusic(bool mute);
+	bool isMusicMute(void);
+	void setMusicVolume(uint8 vol);
+	uint8 getMusicVolume(void);
 	void pauseMusic(void);
 	void unpauseMusic(void);
-	int32 streamCompMusic(const char *filename, uint32 musicId, bool looping);
-	void saveMusicState();
-	void restoreMusicState();
+	void stopMusic(void);
+	void saveMusicState(void);
+	void restoreMusicState(void);
 	void playLeadOut(uint8 *leadOut);
-	int32 musicTimeRemaining();
-	void buildPanTable(bool reverse);
-	uint8 getFxVolume(void);
-	uint8 getSpeechVolume(void);
-	uint8 getMusicVolume(void);
-	bool isMusicMute(void);
-	bool isFxMute(void);
+	int32 streamCompMusic(const char *filename, uint32 musicId, bool looping);
+	int32 musicTimeRemaining(void);
+
+	void muteSpeech(bool mute);
 	bool isSpeechMute(void);
-	void stopMusic(void);
-	void setFxVolume(uint8 vol);
 	void setSpeechVolume(uint8 vol);
-	void setMusicVolume(uint8 vol);
-	void muteMusic(bool mute);
+	uint8 getSpeechVolume(void);
+	void pauseSpeech(void);
+	void unpauseSpeech(void);
+	int32 stopSpeech(void);
+	int32 getSpeechStatus(void);
+	int32 amISpeaking(void);
+	uint32 preFetchCompSpeech(const char *filename, uint32 speechid, uint16 **buf);
+	int32 playCompSpeech(const char *filename, uint32 speechid, uint8 vol, int8 pan);
+
 	void muteFx(bool mute);
-	void muteSpeech(bool mute);
-	int32 isFxOpen(int32 id);
+	bool isFxMute(void);
+	uint8 getFxVolume(void);
+	void setFxVolume(uint8 vol);
 	int32 setFxIdVolumePan(int32 id, uint8 vol, int8 pan);
 	int32 setFxIdVolume(int32 id, uint8 vol);
+	void pauseFx(void);
+	void pauseFxForSequence(void);
+	void unpauseFx(void);
+	bool isFxPlaying(int32 id);
+	int32 openFx(int32 id, uint8 *data);
+	int32 closeFx(int32 id);
+	int32 playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type);
+	void clearAllFx(void);
 };
 
 } // End of namespace Sword2

Index: driver96.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/driver96.h,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- driver96.h	28 Dec 2003 15:08:11 -0000	1.67
+++ driver96.h	3 Jan 2004 11:24:39 -0000	1.68
@@ -218,26 +218,6 @@
 	uint8 *colourTable;	// pointer to 16-byte colour table, only applicable to 16-col compression type
 };
 
-// This is the format of a .WAV file.  Somewhere after this header is the
-// string 'DATA' followed by an int32 size which is the size of the data.
-// Following the size of the data is the data itself.
-
-struct WavHeader {
-	uint32 riff;
-	uint32 fileLength;
-	uint32 wavID;
-	uint32 format;
-	uint32 formatLen;
-	uint16 formatTag;
-	uint16 channels;
-	uint16 samplesPerSec;
-	uint16 avgBytesPerSec;
-	uint16 blockAlign;
-	uint16 unknown1;
-	uint16 unknown2;
-	uint16 bitsPerSample;
-};
-
 // This is the structure which is passed to the sequence player. It includes
 // the smack to play, and any text lines which are to be displayed over the top
 // of the sequence.





More information about the Scummvm-git-logs mailing list