[Scummvm-cvs-logs] SF.net SVN: scummvm: [21237] scummvm/trunk/engines/kyra/sound_adlib.cpp

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Sun Mar 12 09:07:00 CET 2006


Revision: 21237
Author:   eriktorbjorn
Date:     2006-03-12 09:05:59 -0800 (Sun, 12 Mar 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=21237&view=rev

Log Message:
-----------
After several days, telling LordHoto over and over that "no, I don't think the
timer inaccuracies can cause that kind of problems, or we'd have noticed it in
the other game engines as well", guess what? The other game engines do not
necessary use a timer for their Adlib music. So now Kyra doesn't either.

Fortunately for my dignity, the music is still a bit uneven at times, but the
situation does seem to have improved a bit, and the sound effects sound better
to me now.

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/sound_adlib.cpp
Modified: scummvm/trunk/engines/kyra/sound_adlib.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sound_adlib.cpp	2006-03-12 15:38:59 UTC (rev 21236)
+++ scummvm/trunk/engines/kyra/sound_adlib.cpp	2006-03-12 17:05:59 UTC (rev 21237)
@@ -46,9 +46,21 @@
 
 	// AudioStream API
 	int readBuffer(int16 *buffer, const int numSamples) {
-		memset(buffer, 0, sizeof(int16)*numSamples);
+		int samplesLeft = numSamples;
+		memset(buffer, 0, sizeof(int16) * numSamples);
 		lock();
-		YM3812UpdateOne(_adlib, buffer, numSamples);
+		while (samplesLeft) {
+			if (!_samplesTillCallback) {
+				callback();
+				_samplesTillCallback = _samplesPerCallback;
+			}
+
+			int32 render = MIN(samplesLeft, _samplesTillCallback);
+			samplesLeft -= render;
+			_samplesTillCallback -= render;
+			YM3812UpdateOne(_adlib, buffer, render);
+			buffer += render;
+		}
 		unlock();
 		return numSamples;
 	}
@@ -299,6 +311,9 @@
 	// _unkTable2_2[]  - One of the tables in _unkTable2[]
 	// _unkTable2_3[]  - One of the tables in _unkTable2[]
 
+	int32 _samplesPerCallback;
+	int32 _samplesTillCallback;
+
 	int _lastProcessed;
 	int8 _flagTrigger;
 	int _curTable;
@@ -360,11 +375,6 @@
 	void unlock() { _mutex.unlock(); }
 };
 
-void AdlibTimerCall(void *refCon) {
-	AdlibDriver *driver = (AdlibDriver*)refCon;
-	driver->callback();
-}
-
 AdlibDriver::AdlibDriver(Audio::Mixer *mixer) {
 	_mixer = mixer;
 
@@ -393,11 +403,12 @@
 
 	_mixer->setupPremix(this);
 
-	Common::g_timer->installTimerProc(&AdlibTimerCall, 13888, this);
+	// FIXME: Handle the rounding error?
+	_samplesPerCallback = getRate() / 72;
+	_samplesTillCallback = 0;
 }
 
 AdlibDriver::~AdlibDriver() {
-	Common::g_timer->removeTimerProc(&AdlibTimerCall);
 	_mixer->setupPremix(0);
 	OPLDestroy(_adlib);
 	_adlib = 0;


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