[Scummvm-cvs-logs] SF.net SVN: scummvm:[40332] scummvm/trunk/engines/sci/sfx/softseq

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue May 5 23:34:33 CEST 2009


Revision: 40332
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40332&view=rev
Author:   lordhoto
Date:     2009-05-05 21:34:32 +0000 (Tue, 05 May 2009)

Log Message:
-----------
Update SCI code for the upcoming AdLib emulator changes:
- Switch old 'opl2' code to use less of the MAME specific API.
- Since 'interleave' parameter on "YM3812UpdateOne" will be dropped, work around that in SCI code by hand.

Modified Paths:
--------------
    scummvm/trunk/engines/sci/sfx/softseq/adlib.cpp
    scummvm/trunk/engines/sci/sfx/softseq/opl2.cpp

Modified: scummvm/trunk/engines/sci/sfx/softseq/adlib.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/softseq/adlib.cpp	2009-05-05 17:01:22 UTC (rev 40331)
+++ scummvm/trunk/engines/sci/sfx/softseq/adlib.cpp	2009-05-05 21:34:32 UTC (rev 40332)
@@ -183,10 +183,24 @@
 
 void MidiDriver_Adlib::generateSamples(int16 *data, int len) {
 	if (isStereo()) {
-		YM3812UpdateOne(_fmopl[0], data, len, 1);
-		YM3812UpdateOne(_fmopl[1], data + 1, len, 1);
+		int16 buffer[512];
+
+		while (len > 0) {
+			int process = len > ARRAYSIZE(buffer) ? ARRAYSIZE(buffer) : len;
+			len -= process;
+
+			YM3812UpdateOne(_fmopl[0], buffer, process);
+			for (int i = 0; i < process; ++i)
+				data[(i << 1) + 0] = buffer[i];
+			
+			YM3812UpdateOne(_fmopl[1], buffer, process);
+			for (int i = 0; i < process; ++i)
+				data[(i << 1) + 1] = buffer[i];
+
+			data += (process << 1);
+		}
 	} else {
-		YM3812UpdateOne(_fmopl[0], data, len, 0);
+		YM3812UpdateOne(_fmopl[0], data, len);
 	}
 
 	// Increase the age of the notes

Modified: scummvm/trunk/engines/sci/sfx/softseq/opl2.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/softseq/opl2.cpp	2009-05-05 17:01:22 UTC (rev 40331)
+++ scummvm/trunk/engines/sci/sfx/softseq/opl2.cpp	2009-05-05 21:34:32 UTC (rev 40332)
@@ -42,6 +42,8 @@
 
 ***************************************************************************/
 
+#include "common/util.h"
+
 #include "sci/tools.h"
 #include "sci/sfx/iterator.h"
 #include "../softseq.h"
@@ -79,9 +81,6 @@
 #define ADLIB_LEFT 0
 #define ADLIB_RIGHT 1
 
-/* #define OPL_INTERNAL_FREQ     3600000 */
-#define OPL_INTERNAL_FREQ    3579545
-
 static int ready = 0;
 static int pcmout_stereo = STEREO;
 
@@ -157,21 +156,21 @@
 
 /* more shamelessly lifted from xmp and adplug.  And altered.  :) */
 
-static int opl_write_L(int a, int v) {
+static void opl_write_L(int a, int v) {
 	adlib_reg_L[a] = v;
 	OPLWrite(ym3812_L, 0x388, a);
-	return OPLWrite(ym3812_L, 0x389, v);
+	OPLWrite(ym3812_L, 0x389, v);
 }
 
-static int opl_write_R(int a, int v) {
+static void opl_write_R(int a, int v) {
 	adlib_reg_R[a] = v;
 	OPLWrite(ym3812_R, 0x388, a);
-	return OPLWrite(ym3812_R, 0x389, v);
+	OPLWrite(ym3812_R, 0x389, v);
 }
 
-static int opl_write(int a, int v) {
+static void opl_write(int a, int v) {
 	opl_write_L(a, v);
-	return opl_write_R(a, v);
+	opl_write_R(a, v);
 }
 
 /*
@@ -472,16 +471,13 @@
    We assume 16-bit stereo frames (ie 4 bytes)
 */
 static void opl2_poll(sfx_softseq_t *self, byte *dest, int count) {
-	int16 *buffer = (int16 *) dest;
-	int16 *ptr = buffer;
+	int16 *ptr = (int16 *)dest;
 
-	if (!ready) {
+	if (!ready)
 		error("synth_mixer(): !ready \n");
-	}
 
-	if (!buffer) {
+	if (!ptr)
 		error("synth_mixer(): !buffer \n");
-	}
 
 #if 0
 	{
@@ -509,10 +505,24 @@
 #endif
 
 	if (pcmout_stereo) {
-		YM3812UpdateOne(ym3812_L, ptr, count, 1);
-		YM3812UpdateOne(ym3812_R, ptr + 1, count, 1);
+		int16 buffer[512];
+
+		while (count > 0) {
+			int process = count > ARRAYSIZE(buffer) ? ARRAYSIZE(buffer) : count;
+			count -= process;
+
+			YM3812UpdateOne(ym3812_L, buffer, process);
+			for (int i = 0; i < process; ++i)
+				ptr[(i << 1) + 0] = buffer[i];
+			
+			YM3812UpdateOne(ym3812_R, buffer, process);
+			for (int i = 0; i < process; ++i)
+				ptr[(i << 1) + 1] = buffer[i];
+
+			ptr += (process << 1);
+		}
 	} else {
-		YM3812UpdateOne(ym3812_L, ptr, count, 0);
+		YM3812UpdateOne(ym3812_L, ptr, count);
 	}
 }
 
@@ -533,10 +543,7 @@
 		for (i = 48; i < 96; i++)
 			make_sbi((adlib_def *)(data_ptr + 2 + (28 * i)), adlib_sbi[i]);
 
-	OPLBuildTables(FMOPL_ENV_BITS_HQ, FMOPL_EG_ENT_HQ);
-
-	if (!(ym3812_L = OPLCreate(OPL_TYPE_YM3812, OPL_INTERNAL_FREQ, SAMPLE_RATE)) ||
-	        !(ym3812_R = OPLCreate(OPL_TYPE_YM3812, OPL_INTERNAL_FREQ, SAMPLE_RATE))) {
+	if (!(ym3812_L = makeAdlibOPL(SAMPLE_RATE)) || !(ym3812_R = makeAdlibOPL(SAMPLE_RATE))) {
 		sciprintf("[sfx:seq:opl2] Failure: Emulator init failed!\n");
 		return SFX_ERROR;
 	}
@@ -549,12 +556,10 @@
 
 
 static void opl2_exit(sfx_softseq_t *self) {
-	FM_OPL *opl = ym3812_L;
+	OPLDestroy(ym3812_L);
 	ym3812_L = NULL;
-	OPLDestroy(opl);
-	opl = ym3812_R;
+	OPLDestroy(ym3812_R);
 	ym3812_R = NULL;
-	OPLDestroy(opl);
 
 	// XXX deregister with pcm layer.
 }


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