[Scummvm-cvs-logs] CVS: scummvm/gob goblin.cpp,1.15,1.16 inter.cpp,1.17,1.18 sound.cpp,1.9,1.10 sound.h,1.6,1.7 util.cpp,1.13,1.14

Eugene Sandulenko sev at users.sourceforge.net
Fri May 6 09:01:03 CEST 2005


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

Modified Files:
	goblin.cpp inter.cpp sound.cpp sound.h util.cpp 
Log Message:
Patch #1196638 'GOB: Simple "beeper"'. Thanks eriktorbjorn.


Index: goblin.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/goblin.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- goblin.cpp	5 May 2005 11:11:49 -0000	1.15
+++ goblin.cpp	6 May 2005 15:59:32 -0000	1.16
@@ -1562,9 +1562,7 @@
 	if (gobDesc->state >= 0 && gobDesc->state < 10 &&
 	    gobDesc->stateMach == gobDesc->realStateMach &&
 	    (gobDesc->curFrame == 3 || gobDesc->curFrame == 6)) {
-		snd_speakerOn(10 * util_getRandom(3) + 50);
-		util_delay(5);
-		snd_speakerOff();
+		snd_speakerOn(10 * util_getRandom(3) + 50, 5);
 	}
 
 	if (gob_currentGoblin == 0

Index: inter.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/inter.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- inter.cpp	16 Apr 2005 23:31:02 -0000	1.17
+++ inter.cpp	6 May 2005 15:59:33 -0000	1.18
@@ -1314,7 +1314,7 @@
 				break;
 
 			case 2:
-				snd_speakerOn(parse_parseValExpr());
+				snd_speakerOn(parse_parseValExpr(), -1);
 				break;
 
 			case 3:

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/sound.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- sound.cpp	1 May 2005 10:15:30 -0000	1.9
+++ sound.cpp	6 May 2005 15:59:33 -0000	1.10
@@ -19,11 +19,73 @@
  * $Header$
  *
  */
+
+#include "sound/audiostream.h"
+
 #include "gob/gob.h"
 #include "gob/global.h"
 #include "gob/sound.h"
+
 namespace Gob {
 
+// TODO: This is a very primitive square wave generator. The only thing is
+//       has in common with the PC speaker is that it sounds terrible.
+
+class SquareWaveStream : public AudioStream {
+private:
+	uint _rate;
+	bool _beepForever;
+	uint32 _periodLength;
+	uint32 _periodSamples;
+	uint32 _remainingSamples;
+	int16 _sampleValue;
+
+public:
+	SquareWaveStream() {}
+	~SquareWaveStream() {}
+
+	void playNote(int freq, int32 ms);
+
+	int readBuffer(int16 *buffer, const int numSamples);
+
+	bool endOfData() const	{ return _remainingSamples == 0; }
+	bool isStereo() const	{ return false; }
+	int getRate() const	{ return _rate; }
+};
+
+void SquareWaveStream::playNote(int freq, int32 ms) {
+	_rate = _vm->_mixer->getOutputRate();
+	_periodLength = _rate / (2 * freq);
+	_periodSamples = 0;
+	_sampleValue = 6000;
+	if (ms == -1) {
+		_remainingSamples = 1;
+		_beepForever = true;
+	} else {
+		_remainingSamples = (_rate * ms) / 1000;
+		_beepForever = false;
+	}
+}
+
+int SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) {
+	int samples = 0;
+
+	while (samples < numSamples && _remainingSamples > 0) {
+		*buffer++ = _sampleValue;
+		if (_periodSamples++ > _periodLength) {
+			_periodSamples = 0;
+			_sampleValue = -_sampleValue;
+		}
+		samples++;
+		if (!_beepForever)
+			_remainingSamples--;
+	}
+
+	return samples;
+}
+
+SquareWaveStream speakerStream;
+SoundHandle speakerHandle;
 Snd_SoundDesc *snd_loopingSounds[5]; // Should be enough
 
 void snd_initSound(void) {
@@ -48,8 +110,18 @@
 int16 snd_checkAdlib(void) {return 0;}
 int16 snd_checkBlaster(void) {return 0;}
 void snd_setBlasterPort(int16 port) {return;}
-void snd_speakerOn(int16 frequency) {return;}
-void snd_speakerOff(void) {return;}
+
+void snd_speakerOn(int16 frequency, int32 length) {
+	speakerStream.playNote(frequency, length);
+	if (!_vm->_mixer->isSoundHandleActive(speakerHandle)) {
+		_vm->_mixer->playInputStream(SoundMixer::kSFXSoundType, &speakerHandle, &speakerStream, -1, 255, 0, false);
+	}
+}
+
+void snd_speakerOff(void) {
+	_vm->_mixer->stopHandle(speakerHandle);
+}
+
 void snd_stopSound(int16 arg){return;}
 void snd_setResetTimerFlag(char flag){return;}
 

Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/sound.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- sound.h	30 Apr 2005 11:32:18 -0000	1.6
+++ sound.h	6 May 2005 15:59:33 -0000	1.7
@@ -30,7 +30,7 @@
 int16 snd_checkAdlib(void);
 int16 snd_checkBlaster(void);
 void snd_setBlasterPort(int16 port);
-void snd_speakerOn(int16 frequency);
+void snd_speakerOn(int16 frequency, int32 length);
 void snd_speakerOff(void);
 void snd_stopSound(int16 arg);
 void snd_setResetTimerFlag(char flag);

Index: util.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/util.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- util.cpp	29 Apr 2005 15:01:03 -0000	1.13
+++ util.cpp	6 May 2005 15:59:33 -0000	1.14
@@ -192,9 +192,7 @@
 	if (soundFlags == 0)
 		return;
 
-	//sound(freq);
-	util_delay(50);
-	//nosound();
+	snd_speakerOn(freq, 50);
 }
 
 uint32 util_getTimeKey(void) {





More information about the Scummvm-git-logs mailing list