[Scummvm-cvs-logs] CVS: residual actor.cpp,1.16,1.17 bits.h,1.7,1.8 costume.cpp,1.10,1.11 lua.cpp,1.34,1.35 main.cpp,1.15,1.16 residual.vcproj,1.10,1.11 smush.cpp,1.1,1.2 smush.h,1.1,1.2 sound.cpp,1.4,1.5 sound.h,1.3,1.4 mixer.cpp,1.5,NONE mixer.h,1.5,NONE

Pawel Kolodziejski aquadran at users.sourceforge.net
Fri Dec 12 13:19:01 CET 2003


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1:/tmp/cvs-serv13367

Modified Files:
	actor.cpp bits.h costume.cpp lua.cpp main.cpp residual.vcproj 
	smush.cpp smush.h sound.cpp sound.h 
Removed Files:
	mixer.cpp mixer.h 
Log Message:
added mixer code, handle smush sound, handle smush filenames in lua

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/actor.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- actor.cpp	12 Oct 2003 13:04:46 -0000	1.16
+++ actor.cpp	12 Dec 2003 21:17:31 -0000	1.17
@@ -20,7 +20,6 @@
 #include "engine.h"
 #include "costume.h"
 #include "sound.h"
-#include "mixer.h"
 #include <cmath>
 #include <cstring>
 #include <SDL.h>

Index: bits.h
===================================================================
RCS file: /cvsroot/scummvm/residual/bits.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- bits.h	12 Dec 2003 09:53:29 -0000	1.7
+++ bits.h	12 Dec 2003 21:17:31 -0000	1.8
@@ -36,6 +36,10 @@
 
 #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
 
+template<typename T> inline T ABS (T x)			{ return (x>=0) ? x : -x; }
+template<typename T> inline T MIN (T a, T b)	{ return (a<b) ? a : b; }
+template<typename T> inline T MAX (T a, T b)	{ return (a>b) ? a : b; }
+
 #if defined(_MSC_VER)
 
 	#define scumm_stricmp stricmp

Index: costume.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/costume.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- costume.cpp	5 Oct 2003 17:45:46 -0000	1.10
+++ costume.cpp	12 Dec 2003 21:17:31 -0000	1.11
@@ -25,7 +25,6 @@
 #include "model.h"
 #include "lua.h"
 #include "sound.h"
-#include "mixer.h"
 #include <string>
 #include <cstdio>
 #include <map>

Index: lua.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- lua.cpp	12 Dec 2003 08:39:07 -0000	1.34
+++ lua.cpp	12 Dec 2003 21:17:31 -0000	1.35
@@ -25,7 +25,6 @@
 #include "color.h"
 #include "costume.h"
 #include "engine.h"
-#include "mixer.h"
 #include "sound.h"
 #include "smush.h"
 #include "textobject.h"
@@ -1023,12 +1022,14 @@
 
 static void StartMovie() {
 	Smush player;
-	player.play("intro.snm", "");
+	char *filename = lua_getstring(lua_getparam(1));
+	player.play(filename, "");
 }
 
 static void StartFullscreenMovie() {
 	Smush player;
-	player.play("intro.snm", "");
+	char *filename = lua_getstring(lua_getparam(1));
+	player.play(filename, "");
 }
 
 // Stub function for builtin functions not yet implemented

Index: main.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/main.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- main.cpp	28 Oct 2003 18:39:24 -0000	1.15
+++ main.cpp	12 Dec 2003 21:17:31 -0000	1.16
@@ -25,7 +25,8 @@
 #include "lua.h"
 #include "registry.h"
 #include "engine.h"
-#include "mixer.h"
+#include "sound.h"
+#include "mixer/mixer.h"
 #ifndef _MSC_VER
 #include <unistd.h>
 #endif
@@ -52,6 +53,8 @@
 }
 #endif
 
+extern SoundMixer *g_mixer;
+
 int main(int argc, char *argv[]) {
   char 	GLDriver[1024];
   int i;
@@ -102,6 +105,7 @@
     }
   }
 
+  g_mixer = new SoundMixer();
   Mixer::instance()->start();
 
   lua_open();
@@ -153,6 +157,8 @@
   }
   #endif
   Engine::instance()->mainLoop();
+
+  delete g_mixer;
 
   return 0;
 }

Index: residual.vcproj
===================================================================
RCS file: /cvsroot/scummvm/residual/residual.vcproj,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- residual.vcproj	12 Dec 2003 08:39:07 -0000	1.10
+++ residual.vcproj	12 Dec 2003 21:17:31 -0000	1.11
@@ -192,12 +192,6 @@
 				RelativePath="material.h">

 			</File>

 			<File

-				RelativePath="mixer.cpp">

-			</File>

-			<File

-				RelativePath="mixer.h">

-			</File>

-			<File

 				RelativePath="model.cpp">

 			</File>

 			<File

@@ -280,6 +274,40 @@
 				</File>

 				<File

 					RelativePath="vector3d.h">

+				</File>

+			</Filter>

+			<Filter

+				Name="mixer"

+				Filter="">

+				<File

+					RelativePath="mixer\audiostream.cpp">

+				</File>

+				<File

+					RelativePath="mixer\audiostream.h">

+				</File>

+				<File

+					RelativePath="mixer\mixer.cpp">

+					<FileConfiguration

+						Name="Debug|Win32">

+						<Tool

+							Name="VCCLCompilerTool"

+							ObjectFile="$(IntDir)/$(InputName)1.obj"/>

+					</FileConfiguration>

+					<FileConfiguration

+						Name="Release|Win32">

+						<Tool

+							Name="VCCLCompilerTool"

+							ObjectFile="$(IntDir)/$(InputName)1.obj"/>

+					</FileConfiguration>

+				</File>

+				<File

+					RelativePath="mixer\mixer.h">

+				</File>

+				<File

+					RelativePath="mixer\rate.cpp">

+				</File>

+				<File

+					RelativePath="mixer\rate.h">

 				</File>

 			</Filter>

 		</Filter>


Index: smush.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/smush.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- smush.cpp	12 Dec 2003 08:39:07 -0000	1.1
+++ smush.cpp	12 Dec 2003 21:17:31 -0000	1.2
@@ -19,10 +19,8 @@
 #include "bits.h"
 #include "debug.h"
 #include <cstring>
-//#include "file.h"
-//#include "util.h"
 #include "smush.h"
-//#include "system.h"
+#include "mixer/mixer.h"
 #include <SDL.h>
 
 Smush::Smush() {
@@ -33,18 +31,11 @@
 	_speed = 0;
 	_channels = -1;
 	_freq = 0;
-//	g_system = new OSystem();
-//	_mixer = new SoundMixer();
-//	_mixer->bindToSystem(g_system);
-//	_mixer->setVolume(100);
-//	_mixer->setMusicVolume(100);
-//	_soundHandle = 0;
+	_soundHandle = 0;
 }
 
 Smush::~Smush() {
 	deinit();
-//	delete g_system;
-//	delete _mixer;
 }
 
 void Smush::init() {
@@ -68,23 +59,24 @@
 void decompressVima(const char *src, int16 *dest, int destLen);
 void vimaInit();
 
+extern SoundMixer *g_mixer;
+
 void Smush::handleWave(const byte *src, uint32 size) {
     
 	int16 *dst = new int16[size * _channels];
-	decompressVima((char *)src, dst, size * _channels * 2); delete dst;
-/*	// convert our LE ones to BE
-	for (uint32_t j = 0; j < size * _channels; j++)
+	decompressVima((char *)src, dst, size * _channels * 2);
+	// convert our LE ones to BE
+	for (uint32 j = 0; j < size * _channels; j++)
 		dst[j] = SWAP_BYTES_16(dst[j]);
 
 	int flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE;
 	if (_channels == 2)
 		flags |= SoundMixer::FLAG_STEREO;
 	if (_soundHandle == 0)
-		_mixer->newStream(&_soundHandle, (byte *)dst, size * _channels * 2, _freq,
+		g_mixer->newStream(&_soundHandle, (byte *)dst, size * _channels * 2, _freq,
 							flags, 300000);
 	else
-		_mixer->appendStream(_soundHandle, (byte *)dst, size * _channels * 2);
-*/
+		g_mixer->appendStream(_soundHandle, (byte *)dst, size * _channels * 2);
 }
 
 void Smush::handleFrame() {
@@ -196,7 +188,7 @@
 
 //		SDL_BlitSurface(image, &src, screen, NULL);
 //		SDL_UpdateRect(screen, 0, 0, 0, 0);
-//		SDL_Delay(_speed / 1000);
+		SDL_Delay(_speed / 1000);
 	}
 }
 

Index: smush.h
===================================================================
RCS file: /cvsroot/scummvm/residual/smush.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- smush.h	12 Dec 2003 08:39:07 -0000	1.1
+++ smush.h	12 Dec 2003 21:17:31 -0000	1.2
@@ -22,7 +22,7 @@
 #include "debug.h"
 #include <cstring>
 #include "blocky16.h"
-//#include "mixer.h"
+#include "mixer/mixer.h"
 
 class File {
 private:
@@ -65,8 +65,7 @@
 	int32 _nbframes;
 	Blocky16 _blocky16;
 	File _file;
-//	SoundMixer *_mixer;
-//	PlayingSoundHandle _soundHandle;
+	PlayingSoundHandle _soundHandle;
 
 	int32 _frame;
 	bool _alreadyInit;

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/sound.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- sound.cpp	12 Dec 2003 08:39:07 -0000	1.4
+++ sound.cpp	12 Dec 2003 21:17:31 -0000	1.5
@@ -17,10 +17,401 @@
 
 #include "stdafx.h"
 #include "sound.h"
+#include "mixer/mixer.h"
 #include "bits.h"
 #include "debug.h"
 #include <cstring>
 #include <SDL_endian.h>
+
+struct imuseTableEntry {
+  int stateNum;
+  const char *filename;
+};
+
+static const imuseTableEntry grimMusicTable[] = {
+  { 1001, "1001 - Manny's Office.IMC" },
+  { 1002, "1002 - Mr. Frustration.IMC" },
+  { 1003, "1002 - Mr. Frustration.IMC" },
+  { 1004, "1002 - Mr. Frustration.IMC" },
+  { 1005, "1002 - Mr. Frustration.IMC" },
+  { 1006, "1002 - Mr. Frustration.IMC" },
+  { 1007, "1002 - Mr. Frustration.IMC" },
+  { 1008, "1008 - Domino's Office.IMC" },
+  { 1009, "1009 - Copal's Office.IMC" },
+  { 1010, "1010 - Ledge.IMC" },
+  { 1011, "1011 - Roof.IMC" },
+  { 1020, "1020 - Tube Room.IMC" },
+  { 1021, "1021 - Brennis.IMC" },
+  { 1022, "1022 - Lobby.IMC" },
+  { 1023, "1023 - Packing Room.IMC" },
+  { 1030, "1030 - Garage.IMC" },
+  { 1031, "1031 - Glottis' Shop.IMC" },
+  { 1032, "1030 - Garage.IMC" },
+  { 1040, "1040 - Festival Wet.IMC" },
+  { 1041, "1041 - Festival Dry.IMC" },
+  { 1042, "1041 - Festival Dry.IMC" },
+  { 1043, "1041 - Festival Dry.IMC" },
+  { 1044, "1040 - Festival Wet.IMC" },
+  { 1050, "1050 - Headquarters.IMC" },
+  { 1060, "1060 - Real World.IMC" },
+  { 1070, "1070 - Stump Room.IMC" },
+  { 1071, "1071 - Signpost Room.IMC" },
+  { 1072, "1072 - Navigation.IMC" },
+  { 1073, "1071 - Signpost Room.IMC" },
+  { 1074, "1074 - Bone Wagon.IMC" },
+  { 1075, "1075 - Spider's Eye.IMC" },
+  { 1076, "1076 - Spider Room.IMC" },
+  { 1077, "1077 - Tree Pump Amb.IMC" },
+  { 1078, "1078 - Tree Pump.IMC" },
+  { 1079, "1071 - Signpost Room.IMC" },
+  { 1080, "1080 - Beaver Room Lobby.IMC" },
+  { 1081, "1081 - Beaver Dam.IMC" },
+  { 1082, "1083 - Beaver Room.IMC" },
+  { 1083, "1083 - Beaver Room.IMC" },
+  { 1084, "1084 - Foggy Cactus.IMC" },
+  { 1085, "1085 - Rubamat Exterior.IMC" },
+  { 1086, "1086 - Blue Hector.IMC" },
+  { 1100, "1109 - Cafe Exterior.IMC" },
+  { 1101, "1101 - Cafe Office.IMC" },
+  { 1102, "1102 - Cafe Intercom.IMC" },
+  { 1103, "1103 - Coat Check.IMC" },
+  { 1104, "1104 - Lupe.IMC" },
+  { 1105, "1106 - Glottis Noodle.IMC" },
+  { 1106, "1106 - Glottis Noodle.IMC" },
+  { 1107, "1101 - Cafe Office.IMC" },
+  { 1108, "1108 - Casino Interior.IMC" },
+  { 1109, "1109 - Cafe Exterior.IMC" },
+  { 1110, "1110 - Cafe Ledge.IMC" },
+  { 1111, "1108 - Casino Interior.IMC" },
+  { 1112, "1112 - Rusty Sans Vox.IMC" },
+  { 1120, "1120 - Elevator Station.IMC" },
+  { 1121, "1122 - Blue Exterior.IMC" },
+  { 1122, "1122 - Blue Exterior.IMC" },
+  { 1123, "1123 - Blue Casket Ins.IMC" },
+  { 1124, "1124 - Blue Casket Amb.IMC" },
+  { 1125, "1125 - Smooth Hector.IMC" },
+  { 1126, "1122 - Blue Exterior.IMC" },
+  { 1127, "1127 - Limbo Dock.IMC" },
+  { 1128, "1128 - Limbo Talk.IMC" },
+  { 1129, "1129 - Limbo Poem.IMC" },
+  { 1130, "1130 - Dry Dock.IMC" },
+  { 1131, "1131 - Dry Dock Strike.IMC" },
+  { 1132, "1132 - Lighthouse Ext.IMC" },
+  { 1133, "1133 - Lola's Last.IMC" },
+  { 1140, "1140 - Police Station.IMC" },
+  { 1141, "1141 - Police Interior.IMC" },
+  { 1142, "1141 - Police Interior.IMC" },
+  { 1143, "1143 - Morgue.IMC" },
+  { 1144, "1140 - Police Station.IMC" },
+  { 1145, "1145 - Bridge Blimp.IMC" },
+  { 1146, "1146 - LOL Security Ext.IMC" },
+  { 1147, "1147 - LOL Security Int.IMC" },
+  { 1148, "1148 - Carla's Life.IMC" },
+  { 1149, "1149 - Bomb.IMC" },
+  { 1150, "1150 - Track Stairs.IMC" },
+  { 1151, "1151 - Track Stairs.IMC" },
+  { 1152, "1152 - Track Stairs.IMC" },
+  { 1153, "1153 - Track Base.IMC" },
+  { 1154, "1154 - Kitty Hall.IMC" },
+  { 1155, "1155 - Sanspoof.IMC" },
+  { 1156, "1156 - Kitty Stables.IMC" },
+  { 1160, "1160 - High Roller Hall.IMC" },
+  { 1161, "1161 - High Roller Lnge.IMC" },
+  { 1162, "1162 - Glottis Gambling.IMC" },
+  { 1163, "1163 - Max's Office.IMC" },
+  { 1164, "1125 - Hector Steps Out.IMC" },
+  { 1165, "1125 - Hector Steps Out.IMC" },
+  { 1166, "1125 - Hector Steps Out.IMC" },
+  { 1167, "1167 - Dillopede Elev.IMC" },
+  { 1168, "1168 - Dillopede Elev.IMC" },
+  { 1169, "1169 - Dillopede Elev.IMC" },
+  { 1170, "1170 - Extendo Bridge.IMC" },
+  { 1171, "1170 - Extendo Bridge.IMC" },
+  { 1172, "1170 - Extendo Bridge.IMC" },
+  { 1173, "1173 - Scrimshaw Int.IMC" },
+  { 1174, "1174 - Scrim Sleep.IMC" },
+  { 1180, "1180 - Note to Manny.IMC" },
+  { 1181, "1155 - Sanspoof.IMC" },
+  { 1190, "1106 - Glottis Noodle.IMC" },
+  { 1191, "1106 - Glottis Noodle.IMC" },
+  { 1201, "1201 - Lola Zapata.IMC" },
+  { 1202, "1202 - Inside the Lola.IMC" },
+  { 1203, "1203 - Engine Room.IMC" },
+  { 1204, "1204 - Porthole.IMC" },
+  { 1205, "1204 - Porthole.IMC" },
+  { 1210, "1210 - Sunken Lola.IMC" },
+  { 1211, "1211 - Pearl Crater Sub.IMC" },
+  { 1220, "1220 - Miner's Room.IMC" },
+  { 1221, "1221 - Miner's Room.IMC" },
+  { 1222, "1222 - Exterior Airlock.IMC" },
+  { 1223, "1223 - Factory Hub.IMC" },
+  { 1224, "1224 - Foreman's Office.IMC" },
+  { 1230, "1230 - Vault Door.IMC" },
+  { 1231, "1231 - Outer Vault.IMC" },
+  { 1232, "1232 - Inner Vault.IMC" },
+  { 1233, "1233 - Ashtray Room.IMC" },
+  { 1234, "1234 - Ashtray Scary.IMC" },
+  { 1235, "1235 - Ashtray Pensive.IMC" },
+  { 1236, "1236 - Domino's Room.IMC" },
+  { 1240, "1240 - Conveyor Under.IMC" },
+  { 1241, "1240 - Conveyor Under.IMC" },
+  { 1242, "1241 - Crane Intro.IMC" },
+  { 1243, "1243 - Anchor Room.IMC" },
+  { 1244, "1244 - Glottis Hanging.IMC" },
+  { 1245, "1245 - End of the World.IMC" },
+  { 1246, "1246 - End World Later.IMC" },
+  { 1247, "1241 - Crane Intro.IMC" },
+  { 1250, "1250 - Upper Beach.IMC" },
+  { 1251, "1250 - Upper Beach.IMC" },
+  { 1252, "1252 - Lower Beach Boat.IMC" },
+  { 1253, "1253 - Lamancha Sub.IMC" },
+  { 1254, "1254 - Crane Later.IMC" },
+  { 1301, "1301 - Temple Gate.IMC" },
+  { 1302, "1301 - Temple Gate.IMC" },
+  { 1303, "1303 - Truck Depot.IMC" },
+  { 1304, "1304 - Mayan Train Sta.IMC" },
+  { 1305, "1305 - Mayan Workshop.IMC" },
+  { 1306, "1306 - Mayan Train Pad.IMC" },
+  { 1307, "1307 - Mechanic's Kitch.IMC" },
+  { 1310, "1310 - Jello Bomb.IMC" },
+  { 1311, "1310 - Jello Bomb.IMC" },
+  { 1312, "1125 - Smooth Hector.IMC" },
+  { 1313, "1125 - Smooth Hector.IMC" },
+  { 1314, "1125 - Smooth Hector.IMC" },
+  { 1315, "1122 - Blue Exterior.IMC" },
+  { 1316, "1122 - Blue Exterior.IMC" },
+  { 1317, "1122 - Blue Exterior.IMC" },
+  { 1318, "1332 - Hector's Foyer.IMC" },
+  { 1319, "1319 - Florist Video.IMC" },
+  { 1320, "1320 - New LSA HQ.IMC" },
+  { 1321, "1321 - LSA Sewer.IMC" },
+  { 1322, "1321 - LSA Sewer.IMC" },
+  { 1323, "1323 - Sewer Maze.IMC" },
+  { 1324, "1324 - Albinozod.IMC" },
+  { 1325, "1325 - Florist Shop.IMC" },
+  { 1326, "1326 - Florist Shop Int.IMC" },
+  { 1327, "1327 - Florist OK.IMC" },
+  { 1328, "1323 - Sewer Maze.IMC" },
+  { 1329, "1329 - Theater Backstag.IMC" },
+  { 1330, "1330 - Lemans Lobby.IMC" },
+  { 1331, "1330 - Lemans Lobby.IMC" },
+  { 1332, "1332 - Hector's Foyer.IMC" },
+  { 1333, "1333 - Brennis Talk.IMC" },
+  { 1334, "1334 - Albino Trap.IMC" },
+  { 1340, "1342 - Neon Ledge.IMC" },
+  { 1350, "1350 - Meadow Flowers.IMC" },
+  { 1351, "1351 - Meadow.IMC" },
+  { 1352, "1352 - Car Head.IMC" },
+  { 1353, "1353 - Greenhouse Appr.IMC" },
+  { 1354, "1354 - Game Ending.IMC" },
+  { 1355, "1355 - Shootout.IMC" },
+  { 1400, "1400 - Start Credits.IMC" },
+  { 1401, "1401 - Smooth Hector.IMC" },
+  { 2001, "2001 - Climb Rope.IMC" },
+  { 2010, "2010 - Glottis OK.IMC" },
+  { 2020, "2020 - Reap Bruno.IMC" },
+  { 2030, "2030 - Ledgepeckers.IMC" },
+  { 2050, "2050 - Glottis Heart.IMC" },
+  { 2055, "2055 - Slingshot Bone.IMC" },
+  { 2060, "2060 - Glott Tree Fall.IMC" },
+  { 2070, "2070 - Beaver Fly.IMC" },
+  { 2071, "2071 - Beaver Sink.IMC" },
+  { 2080, "2080 - Meet Velasco.IMC" },
+  { 2140, "2140 - Ooo Bonewagon.IMC" },
+  { 2141, "2141 - Ooo Meche.IMC" },
+  { 2155, "2155 - Find Detector.IMC" },
+  { 2156, "2156 - Glott Drink Wine.IMC" },
+  { 2157, "2157 - Glott No Wine.IMC" },
+  { 2161, "2161 - Raoul Appears.IMC" },
+  { 2162, "2162 - Raoul KO.IMC" },
+  { 2163, "2163 - Raoul Dissed.IMC" },
+  { 2165, "2165 - Fake Tix.IMC" },
+  { 2180, "2180 - Befriend Commies.IMC" },
+  { 2186, "2186 - Nick Punchout.IMC" },
+  { 2200, "2200 - Year 3 Iris.IMC" },
+  { 2210, "2210 - Hit Men.IMC" },
+  { 2230, "2230 - Open Vault.IMC" },
+  { 2235, "2235 - Dead Tix.IMC" },
+  { 2240, "2240 - Sprinkler.IMC" },
+  { 2250, "2250 - Crane Track.IMC" },
+  { 2255, "2255 - Crane Fall.IMC" },
+  { 2300, "2300 - Yr 4 Iris.IMC" },
+  { 2301, "2301 - Pop Bruno Casket.IMC" },
+  { 2310, "2310 - Rocket Idea.IMC" },
+  { 2320, "2320 - Jello Suspense.IMC" },
+  { 2325, "2325 - Lumbago Lemo.IMC" },
+  { 2327, "2327 - Breath Mint.IMC" },
+  { 2330, "2330 - Pigeon Fly.IMC" },
+  { 2340, "2340 - Coffee On Boys.IMC" },
+  { 2350, "2350 - Sprout Aha.IMC" },
+  { 2360, "2360 - Chowchilla Bye.IMC" },
+  { 2370, "2370 - Salvador Death.IMC" },
+  { 2399, "2399 - End Credits.IMC" }
+};
+
+Mixer *Mixer::instance_ = NULL;
+
+Mixer *Mixer::instance() {
+  if (instance_ == NULL)
+    instance_ = new Mixer;
+  return instance_;
+}
+
+void mixerCallback(void *userdata, int16 *stream, uint len) {
+  Mixer *m = static_cast<Mixer *>(userdata);
+  m->getAudio(stream, len * 2);
+}
+
+extern SoundMixer *g_mixer;
+
+Mixer::Mixer() :
+  musicSound_(NULL), seqSound_(NULL)
+{
+}
+
+void Mixer::start() {
+  Sound::init();
+  g_mixer->setupPremix(mixerCallback, this);
+  g_mixer->bindToSystem();
+  g_mixer->setVolume(100);
+}
+
+void Mixer::playVoice(Sound *s) {
+  s->reset();
+  voiceSounds_.push_back(s);
+}
+
+void Mixer::playSfx(Sound *s) {
+  s->reset();
+  sfxSounds_.push_back(s);
+}
+
+void Mixer::stopSfx(Sound *s) {
+  for (sound_list::iterator i = sfxSounds_.begin();
+       i != sfxSounds_.end(); ) {
+    if (*i == s)
+      i = sfxSounds_.erase(i);
+    else
+      i++;
+  }
+}
+
+void Mixer::stopVoice(Sound *s) {
+  for (sound_list::iterator i = voiceSounds_.begin();
+       i != voiceSounds_.end(); ) {
+    if (*i == s)
+      i = voiceSounds_.erase(i);
+    else
+      i++;
+  }
+}
+
+static int compareStates(const void *p1, const void *p2) {
+  const imuseTableEntry *e1 = static_cast<const imuseTableEntry *>(p1);
+  const imuseTableEntry *e2 = static_cast<const imuseTableEntry *>(p2);
+  return e1->stateNum - e2->stateNum;
+}
+
+void Mixer::setImuseState(int state) {
+  Sound *newSound = NULL;
+
+  if (state != 1000) {
+    imuseTableEntry key;
+    key.stateNum = state;
+    const imuseTableEntry *e = static_cast<imuseTableEntry *>
+      (std::bsearch(&key, grimMusicTable,
+		    sizeof(grimMusicTable) / sizeof(grimMusicTable[0]),
+		    sizeof(grimMusicTable[0]), compareStates));
+    if (e == NULL) {
+      warning("Unknown IMuse state %d\n", state);
+      return;
+    }
+
+    newSound = ResourceLoader::instance()->loadSound(e->filename);
+    if (newSound == NULL) {
+      warning("Could not find music file %s\n", e->filename);
+      return;
+    }
+  }
+
+  if (newSound != musicSound_) {
+    if (newSound != NULL)
+      newSound->reset();
+    musicSound_ = newSound;
+  }
+}
+
+void Mixer::setImuseSeq(int state) {
+  Sound *newSound = NULL;
+
+  if (state != 2000) {
+    imuseTableEntry key;
+    key.stateNum = state;
+    const imuseTableEntry *e = static_cast<imuseTableEntry *>
+      (std::bsearch(&key, grimMusicTable,
+		    sizeof(grimMusicTable) / sizeof(grimMusicTable[0]),
+		    sizeof(grimMusicTable[0]), compareStates));
+    if (e == NULL) {
+      warning("Unknown IMuse state %d\n", state);
+      return;
+    }
+
+    Sound *newSound = ResourceLoader::instance()->loadSound(e->filename);
+    if (newSound == NULL) {
+      warning("Could not find music file %s\n", e->filename);
+      return;
+    }
+  }
+
+  if (newSound != seqSound_) {
+    if (newSound != NULL)
+      newSound->reset();
+    seqSound_ = newSound;
+  }
+}
+
+Sound *Mixer::findSfx(const char *filename) {
+  for (sound_list::iterator i = sfxSounds_.begin();
+       i != sfxSounds_.end(); i++) {
+    if (std::strcmp((*i)->filename(), filename) == 0)
+      return *i;
+  }
+  return NULL;
+}
+
+bool Mixer::voicePlaying() const {
+  return ! voiceSounds_.empty();
+}
+
+void Mixer::getAudio(int16 *data, int numSamples) {
+  memset(data, 0, numSamples * 2);
+  for (sound_list::iterator i = voiceSounds_.begin();
+       i != voiceSounds_.end(); ) {
+    (*i)->mix(data, numSamples);
+    if ((*i)->done())
+      i = voiceSounds_.erase(i);
+    else
+      i++;
+  }
+  for (sound_list::iterator i = sfxSounds_.begin();
+       i != sfxSounds_.end(); ) {
+    (*i)->mix(data, numSamples);
+    if ((*i)->done())
+      i = sfxSounds_.erase(i);
+    else
+      i++;
+  }
+  if (seqSound_ != NULL) {
+    seqSound_->mix(data, numSamples);
+    if (seqSound_->done())
+      seqSound_ = NULL;
+  }
+  else if (musicSound_ != NULL) {
+    musicSound_->mix(data, numSamples);
+    if (musicSound_->done())
+      musicSound_->reset();
+  }
+}
 
 #define ST_SAMPLE_MAX 0x7fffL
 #define ST_SAMPLE_MIN (-ST_SAMPLE_MAX - 1L)

Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/residual/sound.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sound.h	12 Dec 2003 08:39:07 -0000	1.3
+++ sound.h	12 Dec 2003 21:17:31 -0000	1.4
@@ -20,6 +20,7 @@
 
 #include "bits.h"
 #include "resource.h"
+#include <list>
 
 class Sound : public Resource {
 public:
@@ -38,6 +39,36 @@
   void mix(int16 *data, int samples);
 
   friend class Mixer;
+};
+
+class Mixer {
+public:
+  static Mixer *instance();
+
+  void start();
+
+  void playVoice(Sound *s);
+  void playSfx(Sound *s);
+  void stopSfx(Sound *s);
+  void stopVoice(Sound *s);
+  void setImuseState(int state);
+  void setImuseSeq(int seq);
+
+  Sound *findSfx(const char *filename);
+  bool voicePlaying() const;
+
+  void getAudio(int16 *data, int numSamples);
+
+private:
+  Mixer();
+  ~Mixer();
+
+  static Mixer *instance_;
+  typedef std::list<ResPtr<Sound> > sound_list;
+  sound_list voiceSounds_, sfxSounds_;
+  ResPtr<Sound> musicSound_, seqSound_;
+
+  friend void mixerCallback(void *userdata, uint8 *stream, int len);
 };
 
 #endif

--- mixer.cpp DELETED ---

--- mixer.h DELETED ---





More information about the Scummvm-git-logs mailing list