[Scummvm-cvs-logs] CVS: scummvm imuse.cpp,NONE,1.1 sound.h,NONE,1.1 actor.cpp,1.12,1.13 gfx.cpp,1.19,1.20 gui.cpp,1.2,1.3 gui.h,1.3,1.4 resource.cpp,1.19,1.20 saveload.cpp,1.14,1.15 script_v1.cpp,1.12,1.13 script_v2.cpp,1.10,1.11 scumm.h,1.26,1.27 scummvm.cpp,1.25,1.26 scummvm.dsp,1.12,1.13 sdl.cpp,1.21,1.22 sound.cpp,1.6,1.7 string.cpp,1.9,1.10 windows.cpp,1.17,1.18

Ludvig Strigeus strigeus at users.sourceforge.net
Wed Nov 14 10:47:01 CET 2001


Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv20544

Modified Files:
	actor.cpp gfx.cpp gui.cpp gui.h resource.cpp saveload.cpp 
	script_v1.cpp script_v2.cpp scumm.h scummvm.cpp scummvm.dsp 
	sdl.cpp sound.cpp string.cpp windows.cpp 
Added Files:
	imuse.cpp sound.h 
Log Message:
music support,
fixed timing bugs

--- NEW FILE: imuse.cpp ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2001 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/scummvm/imuse.cpp,v 1.1 2001/11/14 18:37:38 strigeus Exp $
 *
[...2490 lines suppressed...]

void SoundEngine::midiPan(byte chan, int8 pan) {
	if (_midi_pan_last[chan] != pan) {
		_midi_pan_last[chan] = pan;
		MIDI_OUT(_mo, ((pan-64)&0x7F)<<16 | 10<<8 | 0xB0 | chan);
	}
}

void SoundEngine::midiNoteOn(byte chan, byte note, byte velocity) {
	MIDI_OUT(_mo, velocity<<16 | note<<8 | 0x90 | chan);	
}

void SoundEngine::midiNoteOff(byte chan, byte note) {
	MIDI_OUT(_mo, note<<8 | 0x80 | chan);	
}

void SoundEngine::midiSilence(byte chan) {
	MIDI_OUT(_mo, (64<<8)|0xB0|chan);
	MIDI_OUT(_mo, (123<<8)|0xB0|chan);
}
--- NEW FILE: sound.h ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2001  The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Change Log:
 * $Log: sound.h,v $
 * Revision 1.1  2001/11/14 18:37:38  strigeus
 * music support,
 * fixed timing bugs
 *
 */

struct Part;
struct MidiChannel;
struct VolumeFader;
struct Player;
struct HookDatas;
struct SoundEngine;

struct Part {
	SoundEngine *_se;
	Part *_next, *_prev;
	MidiChannel *_mc;
	Player *_player;
	int16 _pitchbend;
	byte _pitchbend_factor;
	int8 _transpose,_transpose_eff;
	byte _vol,_vol_eff;
	int8 _detune,_detune_eff;
	int8 _pan,_pan_eff;
	bool _on;
	byte _modwheel;
	bool _pedal;
	byte _program;
	int8 _pri;
	byte _pri_eff;
	byte _chan;
	byte _effect_level;
	byte _chorus;
	byte _gmidi_5;
	byte _gmidi_1;

	void key_on(byte note, byte velocity);
	void key_off(byte note);
	void set_param(int b, byte c) {}
	void init(SoundEngine *se);
	void setup(Player *player);
	void uninit();
	void off();
	void silence();
	void set_instrument(uint b);
	void set_instrument(byte *data) {}

	void set_transpose(int8 transpose);
	void set_vol(uint8 volume);
	void set_detune(int8 detune);
	void set_pri(int8 pri, bool recalc);
	void set_pan(int8 pan);
	void set_modwheel(uint value);
	void set_pedal(bool value);
	void set_pitchbend(int value);
	void release_pedal();
	void set_program(byte program);
	void set_chorus(uint chorus);
	void set_effect_level(uint level);
	void set_chan_param(int b, int c) {}
	void mod_changed();
	void vol_changed();
	void pedal_changed();
	void modwheel_changed();
	void pan_changed();
	void effect_level_changed();
	void program_changed();
	void chorus_changed();
	int update_actives(uint16 *active);
	void set_pitchbend_factor(uint8 value);
	void set_onoff(bool on);

	void fix_after_load();
};

struct MidiChannel {
	Part *_part;
	byte _chan;
	uint16 _actives[8];

	void init(byte chan);
};

struct VolumeFader {
	Player *player;
	bool active;
	byte curvol;
	uint16 speed_lo_max,num_steps;
	int8 speed_hi;
	int8 direction;
	int8 speed_lo;
	uint16 speed_lo_counter;
	
	void initialize() { active = false; }
	void on_timer();
};

struct HookDatas {
	byte _jump,_transpose;
	byte _part_onoff[16];
	byte _part_volume[16];
	byte _part_program[16];
	byte _part_transpose[16];

	int query_param(int param, byte chan);
	int set(byte cls, byte value, byte chan);
};

struct Player {
	SoundEngine *_se;

	Part *_parts;
	bool _active;
	bool _scanning;
	int _id;
	byte _priority;
	byte _volume;
	int8 _pan;
	int8 _transpose;
	int8 _detune;
	uint _vol_chan;
	byte _vol_eff;
	
	uint _song_index;
	uint _track_index;
	uint _timer_counter;
	uint _loop_to_beat;
	uint _loop_from_beat;
	uint _loop_counter;
	uint _loop_to_tick;
	uint _loop_from_tick;
	uint32 _tempo;
	uint32 _tempo_eff; /* NoSave */
	uint32 _cur_pos;
	uint32 _next_pos;
	uint32 _song_offset;
	uint32 _timer_speed; /* NoSave */
	uint _tick_index;
	uint _beat_index;
	uint _ticks_per_beat;
	byte _speed; /* NoSave */
	bool _abort;

	HookDatas _hook;

	/* Player part */
	void hook_clear();
	void clear();
	bool start_sound(int sound);
	void uninit_parts();
	byte *parse_midi(byte *s);
	void key_off(uint8 chan, byte data);
	void key_on(uint8 chan, byte data, byte velocity);
	void part_set_transpose(uint8 chan, byte relative, int8 b);
	void parse_sysex(byte *p, uint len);
	void maybe_jump(byte *data);
	void maybe_set_transpose(byte *data);
	void maybe_part_onoff(byte *data);
	void maybe_set_volume(byte *data);
	void maybe_set_program(byte *data);
	void maybe_set_transpose_part(byte *data);
	uint update_actives();
	Part *get_part(uint8 part);
	void turn_off_pedals();
	int set_vol(byte vol);
	int get_param(int param, byte chan);
	int query_part_param(int param, byte chan);
	int set_transpose(byte relative, int b);
	void set_priority(int pri);
	void set_pan(int pan);
	void set_detune(int detune);
	void silence_parts();
	void play_active_notes();
	void cancel_volume_fade();

	static void decode_sysex_bytes(byte *src, byte *dst, int len);

	void clear_active_note(int chan, byte note);
	void set_active_note(int chan, byte note);
	void clear_active_notes();

	/* Sequencer part */
	bool set_loop(uint count, uint tobeat, uint totick, uint frombeat, uint fromtick);
	void clear_loop();
	void set_speed(byte speed);
	bool jump(uint track, uint beat, uint tick);
	void uninit_seq();
	void set_tempo(uint32 data);
	int start_seq_sound(int sound);
	void find_sustaining_notes(byte *a, byte *b, uint32 l);
	int scan(uint totrack, uint tobeat, uint totick);
	int query_param(int param);

	int fade_vol(byte vol, int time);
	void sequencer_timer();
};


struct SustainingNotes {
	SustainingNotes *next;
	SustainingNotes *prev;
	Player *player;
	byte note,chan;
	uint32 off_pos;
	uint32 pos;
	uint16 counter;
};

struct CommandQueue {
	uint16 array[8];
};

struct IsNoteCmdData {
	byte chan;
	byte note;
	byte vel;
};

struct SoundEngine {
	void *_mo; /* midi out */

	byte **_base_sounds;

	Scumm *_s;
	
	byte _locked;

	bool _paused;
	bool _active_volume_faders;
	bool _initialized;
	byte _volume_fader_counter;

	uint _queue_end, _queue_pos, _queue_sound;
	byte _queue_adding;

	SustainingNotes *_sustain_notes_used;
	SustainingNotes *_sustain_notes_free;
	SustainingNotes *_sustain_notes_head;

	uint16 _timer_counter_1;

	byte _queue_marker;
	byte _queue_cleared;
	byte _master_volume;

	uint16 _trigger_count;
	
	uint16 _channel_volume[8];
	uint16 _channel_volume_eff[8]; /* NoSave */
	uint16 _volchan_table[8];
	
	Player _players[8];
	SustainingNotes _sustaining_notes[24];
	VolumeFader _volume_fader[8];
	Part _parts[32];
	MidiChannel _midi_channels[9];
	uint16 _active_notes[128];
	CommandQueue _cmd_queue[64];

	int16 _midi_pitchbend_last[16];
	uint8 _midi_volume_last[16];
	bool _midi_pedal_last[16];
	byte _midi_modwheel_last[16];
	byte _midi_effectlevel_last[16];
	byte _midi_chorus_last[16];
	int8 _midi_pan_last[16];

	byte *findTag(int sound, char *tag, int index);
	int initialize(Scumm *scumm);
	int terminate();
	int save_or_load(Serializer *ser);
	int set_master_volume(uint vol);
	int get_master_volume();
	bool start_sound(int sound);
	int stop_sound(int sound);
	int stop_all_sounds();
	int get_sound_status(int sound);
	int get_queue_sound_status(int sound);
	Player *allocate_player(byte priority);
	void handle_marker(uint id, byte data);
	int get_channel_volume(uint a);
	void init_players();
	void init_parts();
	void init_volume_fader();
	void init_sustaining_notes();
	void init_queue();

	void on_timer();
	void sequencer_timers();
	void expire_sustain_notes();
	void expire_volume_faders();

	void set_instrument(uint slot, byte *data) {}
	
	int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h);
	Part *allocate_part(byte pri);

	int clear_queue();
	int enqueue_command(int a, int b, int c, int d, int e, int f, int g);
	int enqueue_trigger(int sound, int marker);
	int query_queue(int param);
	Player *get_player_byid(int id);
	
	int get_volchan_entry(uint a);
	int set_volchan_entry(uint a, uint b);
	int set_channel_volume(uint chan, uint vol);
	void update_volumes();
	void reset_tick();
	VolumeFader *allocate_volume_fader();

	int set_volchan(int sound, int volchan);

	void midiPitchBend(byte chan, int16 pitchbend);
	void midiVolume(byte chan, byte volume);
	void midiPedal(byte chan, bool pedal);
	void midiModWheel(byte chan, byte modwheel);
	void midiEffectLevel(byte chan, byte level);
	void midiChorus(byte chan, byte chorus);
	void midiControl0(byte chan, byte value);
	void midiProgram(byte chan, byte program);
	void midiPan(byte chan, int8 pan);
	void midiNoteOn(byte chan, byte note, byte velocity);
	void midiNoteOff(byte chan, byte note);
	void midiSilence(byte chan);
	void midiInit();

	void adjust_priorities();

	void fix_parts_after_load();
	void fix_players_after_load();

	static int saveReference(SoundEngine *me, byte type, void *ref);
	static void *loadReference(SoundEngine *me, byte type, int ref);

	void lock();
	void unlock();

	void pause(bool paused);
};

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/actor.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** actor.cpp	2001/11/11 16:54:45	1.12
--- actor.cpp	2001/11/14 18:37:38	1.13
***************
*** 586,589 ****
--- 586,591 ----
  	int act;
  
+ 	stopTalkSound();
+ 
  	_haveMsg = 0;
  	_talkDelay = 0;

Index: gfx.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gfx.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** gfx.cpp	2001/11/11 16:54:45	1.19
--- gfx.cpp	2001/11/14 18:37:38	1.20
***************
*** 1397,1401 ****
  		
  		updateScreen(this);
! 		waitForTimer(this,3);
  	}
  }
--- 1397,1401 ----
  		
  		updateScreen(this);
! 		waitForTimer(this,30);
  	}
  }

Index: gui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** gui.cpp	2001/11/10 20:51:55	1.2
--- gui.cpp	2001/11/14 18:37:38	1.3
***************
*** 3,6 ****
--- 3,11 ----
  #include "gui.h"
  
+ enum {
+ 	SAVELOAD_DIALOG,
+ 	PAUSE_DIALOG
+ };
+ 
  void Gui::draw(int start,int end) {
  	int i;
***************
*** 250,253 ****
--- 255,264 ----
  };
  
+ const GuiWidget pause_dialog[] = {
+ 	{GUI_TEXT,0x01,GWF_DEFAULT,50,80,220,16,0,10},
+ 	{0},
+ };
+ 
+ 
  void Gui::handleCommand(int cmd) {
  	int lastEdit = _editString;
***************
*** 333,336 ****
--- 344,348 ----
  	100, /* Quit */
  	101, /* Ok */
+ 	93,  /* Game paused */
  };
  
***************
*** 338,342 ****
  	0, /* How may I serve you? */
  	20, /* Select a game to LOAD */
! 	21, /* Name your SAVE game */
    7,  /* Save */
  	8,  /* Load */
--- 350,354 ----
  	0, /* How may I serve you? */
  	20, /* Select a game to LOAD */
! 	19, /* Name your SAVE game */
    7,  /* Save */
  	8,  /* Load */
***************
*** 345,348 ****
--- 357,361 ----
  	11, /* Quit */
  	12, /* Ok */
+ 	4,  /* Game paused */
  };
  
***************
*** 400,424 ****
  
  void Gui::addLetter(byte letter) {
! 	if (_editString==-1)
! 		return;
  
! 	if (letter==13) {
! 		handleCommand(8);
! 		return;
! 	}
  
! 	if (letter>=32 && letter<128 && _editLen < SAVEGAME_NAME_LEN-1) {
! 		game_names[_editString][_editLen++] = letter;	
! 	} else if (letter==8 && _editLen>0) {
! 		_editLen--;
  	}
- 	showCaret(true);
- }
- 
- void Gui::saveLoadDialog() {
- 	_widgets[0] = save_load_dialog;
- 	_editString = -1;
- 	_cur_page = 0;
- 	_active = 1;
  }
  
--- 413,438 ----
  
  void Gui::addLetter(byte letter) {
! 	switch(_dialog) {
! 	case SAVELOAD_DIALOG:
! 		if (_editString==-1)
! 			return;
  
! 		if (letter==13) {
! 			handleCommand(8);
! 			return;
! 		}
  
! 		if (letter>=32 && letter<128 && _editLen < SAVEGAME_NAME_LEN-1) {
! 			game_names[_editString][_editLen++] = letter;	
! 		} else if (letter==8 && _editLen>0) {
! 			_editLen--;
! 		}
! 		showCaret(true);
! 		break;
! 	case PAUSE_DIALOG:
! 		if (letter==32)
! 			close();
! 		break;
  	}
  }
  
***************
*** 432,436 ****
  }
  
- 
  void Gui::init(Scumm *s) {
  	_s = s;
--- 446,449 ----
***************
*** 448,451 ****
--- 461,465 ----
  		_s->_cursorAnimate++;
  		_s->gdi._cursorActive = 1;
+ 		_s->pauseSounds(true);
  	}
  	
***************
*** 472,475 ****
--- 486,504 ----
  	_s->_completeScreenRedraw = true;
  	_s->_cursorAnimate--;
+ 	_s->pauseSounds(false);
  	_active = false;
+ }
+ 
+ void Gui::saveLoadDialog() {
+ 	_widgets[0] = save_load_dialog;
+ 	_editString = -1;
+ 	_cur_page = 0;
+ 	_active = true;
+ 	_dialog = SAVELOAD_DIALOG;
+ }
+ 
+ void Gui::pause() {
+ 	_widgets[0] = pause_dialog;
+ 	_active = true;
+ 	_dialog = PAUSE_DIALOG;
  }

Index: gui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** gui.h	2001/11/10 20:51:55	1.3
--- gui.h	2001/11/14 18:37:38	1.4
***************
*** 44,47 ****
--- 44,48 ----
  	byte _clickTimer;
  	byte _cur_page;
+ 	byte _dialog;
  	int _clickWidget;
  	char *_queryMess;
***************
*** 78,81 ****
--- 79,83 ----
  	void queryMessage(const char *msg, const char *alts);
  	byte getDefaultColor(int color);
+ 	void pause();
  };
  

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/resource.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** resource.cpp	2001/11/11 16:54:45	1.19
--- resource.cpp	2001/11/14 18:37:38	1.20
***************
*** 552,560 ****
  	}	
  
- 	setResourceCounter(type, index, 1);
- 
  	ptr=(byte*)res.address[type][index];
  	if (!ptr)
  		return NULL;
  
  	return ptr + sizeof(ResHeader);
--- 552,560 ----
  	}	
  
  	ptr=(byte*)res.address[type][index];
  	if (!ptr)
  		return NULL;
+ 
+ 	setResourceCounter(type, index, 1);
  
  	return ptr + sizeof(ResHeader);

Index: saveload.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saveload.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** saveload.cpp	2001/11/12 20:50:36	1.14
--- saveload.cpp	2001/11/14 18:37:38	1.15
***************
*** 22,25 ****
--- 22,26 ----
  #include "stdafx.h"
  #include "scumm.h"
+ #include "sound.h"
  
  struct SaveGameHeader {
***************
*** 30,34 ****
  };
  
! #define CURRENT_VER 4
  
  bool Scumm::saveState(int slot, bool compat) {
--- 31,35 ----
  };
  
! #define CURRENT_VER 5
  
  bool Scumm::saveState(int slot, bool compat) {
***************
*** 68,71 ****
--- 69,73 ----
  	Serializer ser;
  	int sb,sh;
+ 	SoundEngine *se;
  
  	makeSavegameName(filename, slot, compat);
***************
*** 89,93 ****
  
  	memcpy(_saveLoadName, hdr.name, sizeof(hdr.name));
! 	
  	CHECK_HEAP
  
--- 91,97 ----
  
  	memcpy(_saveLoadName, hdr.name, sizeof(hdr.name));
! 
! 	pauseSounds(true);
! 
  	CHECK_HEAP
  
***************
*** 135,138 ****
--- 139,144 ----
  	debug(1,"State loaded from '%s'", filename);
  
+ 	pauseSounds(false);
+ 
  	return true;
  }
***************
*** 414,431 ****
  
  	const SaveLoadEntry stringTabEntries[] = {
  		MKLINE(StringTab,t_xpos,sleInt16),
  		MKLINE(StringTab,t_ypos,sleInt16),
  		MKLINE(StringTab,t_center,sleByte),
  		MKLINE(StringTab,t_overhead,sleByte),
  		MKLINE(StringTab,t_no_talk_anim,sleByte),
- 		MKLINE(StringTab,t_right,sleInt16),
- 		MKLINE(StringTab,t_color,sleInt16),
- 		MKLINE(StringTab,t_charset,sleInt16),
- 		MKLINE(StringTab,xpos,sleInt16),
- 		MKLINE(StringTab,ypos,sleInt16),
- 		MKLINE(StringTab,center,sleInt16),
- 		MKLINE(StringTab,overhead,sleInt16),
- 		MKLINE(StringTab,no_talk_anim,sleInt16),
- 		MKLINE(StringTab,right,sleInt16),
  		MKEND()
  	};
--- 420,439 ----
  
  	const SaveLoadEntry stringTabEntries[] = {
+ 		MKLINE(StringTab,xpos,sleInt16),
  		MKLINE(StringTab,t_xpos,sleInt16),
+ 		MKLINE(StringTab,ypos,sleInt16),
  		MKLINE(StringTab,t_ypos,sleInt16),
+ 		MKLINE(StringTab,right,sleInt16),
+ 		MKLINE(StringTab,t_right,sleInt16),
+ 		MKLINE(StringTab,color,sleInt8),
+ 		MKLINE(StringTab,t_color,sleInt8),
+ 		MKLINE(StringTab,charset,sleInt8),
+ 		MKLINE(StringTab,t_charset,sleInt8),
+ 		MKLINE(StringTab,center,sleByte),
  		MKLINE(StringTab,t_center,sleByte),
+ 		MKLINE(StringTab,overhead,sleByte),
  		MKLINE(StringTab,t_overhead,sleByte),
+ 		MKLINE(StringTab,no_talk_anim,sleByte),
  		MKLINE(StringTab,t_no_talk_anim,sleByte),
  		MKEND()
  	};
***************
*** 479,482 ****
--- 487,493 ----
  		}
  	}
+ 
+ 	if (_soundDriver)
+ 		((SoundEngine*)_soundDriver)->save_or_load(s);
  }
  
***************
*** 631,637 ****
  	byte type;
  	byte *at;
- 
  	int size;
  	int value;
  	
  	while(sle->offs != 0xFFFF) {
--- 642,649 ----
  	byte type;
  	byte *at;
  	int size;
  	int value;
+ 	int num;
+ 	void *ptr;
  	
  	while(sle->offs != 0xFFFF) {
***************
*** 643,650 ****
  			if (_saveOrLoad) {
  				/* save reference */
! 				saveWord((*_save_ref)(_ref_me, type, *((void**)at)));
  			} else {
  				/* load reference */
! 				*((void**)at) = (*_load_ref)(_ref_me, type, loadWord());
  			}
  		} else {
--- 655,664 ----
  			if (_saveOrLoad) {
  				/* save reference */
! 				ptr = *((void**)at);
! 				saveWord(ptr ? ((*_save_ref)(_ref_me, type, ptr ) + 1) : 0);
  			} else {
  				/* load reference */
! 				num = loadWord();
! 				*((void**)at) = num ? (*_load_ref)(_ref_me, type, num-1) : NULL;
  			}
  		} else {
***************
*** 656,661 ****
  			}
  			saveLoadArrayOf(at, replen, size, type);
- 			sle++;
  		}
  	}
  }
--- 670,675 ----
  			}
  			saveLoadArrayOf(at, replen, size, type);
  		}
+ 		sle++;
  	}
  }

Index: script_v1.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/script_v1.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** script_v1.cpp	2001/11/12 20:50:36	1.12
--- script_v1.cpp	2001/11/14 18:37:38	1.13
***************
*** 1228,1232 ****
  	switch(fetchScriptByte()) {
  	case 1:
! 		pauseGame(0);
  		break;
  	case 3:
--- 1228,1232 ----
  	switch(fetchScriptByte()) {
  	case 1:
! 		pauseGame(false);
  		break;
  	case 3:

Index: script_v2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/script_v2.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** script_v2.cpp	2001/11/12 20:50:36	1.10
--- script_v2.cpp	2001/11/14 18:37:38	1.11
***************
*** 1795,1799 ****
  	switch(fetchScriptByte()) {
  	case 158:
! 		pauseGame(0);
  		break;
  	case 160:
--- 1795,1799 ----
  	switch(fetchScriptByte()) {
  	case 158:
! 		pauseGame(false);
  		break;
  	case 160:

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** scumm.h	2001/11/12 20:50:36	1.26
--- scumm.h	2001/11/14 18:37:38	1.27
***************
*** 29,34 ****
  typedef void (Scumm::*OpcodeProc)();
  
! #define NUM_SCRIPT_SLOT 25
! #define NUM_ACTORS 13
  
  #pragma START_PACK_STRUCTS
--- 29,40 ----
  typedef void (Scumm::*OpcodeProc)();
  
! /* System Wide Constants */
! enum {
! 	SAMPLES_PER_SEC =  22050,
! 	BITS_PER_SAMPLE = 16,
! 	NUM_MIXER = 4,
! 	NUM_SCRIPT_SLOT = 25,
! 	NUM_ACTORS = 13
! };
  
  #pragma START_PACK_STRUCTS
***************
*** 597,600 ****
--- 603,616 ----
  };
  
+ struct MixerChannel {
+ 	void *_sfx_sound;
+ 	uint32 _sfx_pos;
+ 	uint32 _sfx_size;
+ 	uint32 _sfx_fp_speed;
+ 	uint32 _sfx_fp_pos;
+ 
+ 	void mix(int16 *data, uint32 len);
+ 	void clear();
+ };
  
  enum GameId {
***************
*** 641,644 ****
--- 657,662 ----
  	byte _resFilePathId;
  
+ 	bool _soundsPaused;
+ 
  	bool _useTalkAnims;
  	
***************
*** 919,922 ****
--- 937,942 ----
  	char _saveLoadName[32];
  
+ 	MixerChannel _mixer_channel[NUM_MIXER];
+ 
  	OpcodeProc getOpcode(int i) { return _opcodes[i]; }
  
***************
*** 926,930 ****
  	void askForDisk(const char *filename);
  
- 	
  	bool openResourceFile(const char *filename);
  	
--- 946,949 ----
***************
*** 1450,1454 ****
  	void removeObjectFromRoom(int obj);
  	void decodeParseString();
! 	void pauseGame(int i);
  	void shutDown(int i);
  	void lock(int type, int i);
--- 1469,1473 ----
  	void removeObjectFromRoom(int obj);
  	void decodeParseString();
! 	void pauseGame(bool user);
  	void shutDown(int i);
  	void lock(int type, int i);
***************
*** 1591,1594 ****
--- 1610,1614 ----
  	void processSfxQueues();
  	void startTalkSound(uint32 a, uint32 b, int mode);
+ 	void stopTalkSound();
  	bool isMouthSyncOff(uint pos);
  	void startSfxSound(void *file);
***************
*** 1632,1635 ****
--- 1652,1666 ----
  	void removeEnqueuedObjects();
  	void removeEnqueuedObject(EnqueuedObject *eo);
+ 
+ 	void pauseSounds(bool pause);
+ 
+ 	MixerChannel *allocateMixer();
+ 	bool isSfxFinished();
+ 	void playSfxSound(void *sound, uint32 size, uint rate);
+ 	void stopSfxSound();
+ 
+ 	void mixWaves(int16 *sounds, int len);
+ 	
+ 
  };
  
***************
*** 1672,1675 ****
--- 1703,1707 ----
  		SerializerSaveReference *_save_ref;
  		SerializerLoadReference *_load_ref;
+ 		void *_saveload_ref;
  	};
  	void *_ref_me;
***************
*** 1691,1694 ****
--- 1723,1727 ----
  
  	bool isSaving() { return _saveOrLoad; }
+ 
  };
  
***************
*** 1715,1717 ****
  void playSfxSound(void *sound, uint32 size, uint rate);
  bool isSfxFinished();
! void waitForTimer(Scumm *s, int delay);
\ No newline at end of file
--- 1748,1750 ----
  void playSfxSound(void *sound, uint32 size, uint rate);
  bool isSfxFinished();
! void waitForTimer(Scumm *s, int msec_delay);
\ No newline at end of file

Index: scummvm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scummvm.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** scummvm.cpp	2001/11/12 20:50:36	1.25
--- scummvm.cpp	2001/11/14 18:37:38	1.26
***************
*** 197,202 ****
  	_debugMode = 1;
  
! 	_maxHeapThreshold = 500000;
! 	_minHeapThreshold = 450000;
  	
  	parseCommandLine(argc, argv);
--- 197,202 ----
  	_debugMode = 1;
  
! 	_maxHeapThreshold = 450000;
! 	_minHeapThreshold = 400000;
  	
  	parseCommandLine(argc, argv);
***************
*** 214,217 ****
--- 214,222 ----
  	}
  
+ 	if (_gameId==GID_MONKEY2 && _bootParam==0) {
+ 		_bootParam = 10001;
+ 	}
+ 
+ 
  	initGraphics(this, _fullScreen);
  
***************
*** 753,759 ****
  }
  
! void Scumm::pauseGame(int i) {
! 	/* TODO: implement this */
! 	warning("pauseGame: not implemented");
  }
  
--- 758,763 ----
  }
  
! void Scumm::pauseGame(bool user) {
! 	((Gui*)_gui)->pause();
  }
  
***************
*** 778,787 ****
  	if (_lastKeyHit==_vars[VAR_RESTART_KEY]) {
  		warning("Restart not implemented");
! 		pauseGame(1);
  		return;
  	}
  
  	if (_lastKeyHit==_vars[VAR_PAUSE_KEY]) {
! 		warning("Pause not implemented");
  		/* pause */
  		return;
--- 782,791 ----
  	if (_lastKeyHit==_vars[VAR_RESTART_KEY]) {
  		warning("Restart not implemented");
! //		pauseGame(true);
  		return;
  	}
  
  	if (_lastKeyHit==_vars[VAR_PAUSE_KEY]) {
! 		pauseGame(true);
  		/* pause */
  		return;
***************
*** 794,797 ****
--- 798,803 ----
  	} else if (_lastKeyHit==_vars[VAR_TALKSTOP_KEY]) {
  		_talkDelay = 0;
+ 		if (_sfxMode==2)
+ 			stopTalk();
  		return;
  	}

Index: scummvm.dsp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scummvm.dsp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** scummvm.dsp	2001/11/09 18:54:15	1.12
--- scummvm.dsp	2001/11/14 18:37:38	1.13
***************
*** 43,47 ****
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
! # ADD CPP /nologo /Zp4 /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "DUMP_SCRIPTS" /Yu"stdafx.h" /FD /c
  # ADD BASE RSC /l 0x41d /d "NDEBUG"
  # ADD RSC /l 0x41d /d "NDEBUG"
--- 43,47 ----
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
! # ADD CPP /nologo /Zp4 /MD /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
  # ADD BASE RSC /l 0x41d /d "NDEBUG"
  # ADD RSC /l 0x41d /d "NDEBUG"
***************
*** 158,161 ****
--- 158,165 ----
  # Begin Source File
  
+ SOURCE=.\imuse.cpp
+ # End Source File
+ # Begin Source File
+ 
  SOURCE=.\object.cpp
  
***************
*** 333,336 ****
--- 337,344 ----
  
  SOURCE=.\scummsys.h
+ # End Source File
+ # Begin Source File
+ 
+ SOURCE=.\sound.h
  # End Source File
  # Begin Source File

Index: sdl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sdl.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** sdl.cpp	2001/11/11 16:54:45	1.21
--- sdl.cpp	2001/11/14 18:37:38	1.22
***************
*** 25,32 ****
  #include "scumm.h"
  #include "gui.h"
- 
- #if defined(USE_IMUSE)
  #include "sound.h"
! #endif
  
  #define SCALEUP_2x2
--- 25,31 ----
  #include "scumm.h"
  #include "gui.h"
  #include "sound.h"
! 
! #include "SDL_thread.h"
  
  #define SCALEUP_2x2
***************
*** 36,42 ****
  Gui gui;
  
- #if defined(USE_IMUSE)
  SoundEngine sound;
- #endif
  
  static SDL_Surface *screen;
--- 35,39 ----
***************
*** 75,150 ****
  }
  
! void waitForTimer(Scumm *s, int delay) {
  	SDL_Event event;
! 	
! 	while (SDL_PollEvent(&event)) {
! 		switch(event.type) {
! 		case SDL_KEYDOWN:
! 			s->_keyPressed = mapKey(event.key.keysym.sym, event.key.keysym.mod);
! 			if (event.key.keysym.sym >= '0' && event.key.keysym.sym<='9') {
! 				s->_saveLoadSlot = event.key.keysym.sym - '0';
! 				if (event.key.keysym.mod&KMOD_SHIFT) {
! 					sprintf(s->_saveLoadName, "Quicksave %d", s->_saveLoadSlot);
! 					s->_saveLoadFlag = 1;
! 				} else if (event.key.keysym.mod&KMOD_CTRL)
! 					s->_saveLoadFlag = 2;
! 				s->_saveLoadCompatible = false;
! 			}
! 			if (event.key.keysym.sym=='z' && event.key.keysym.mod&KMOD_CTRL) {
! 				exit(1);
! 			} 
! 			if (event.key.keysym.sym=='f' && event.key.keysym.mod&KMOD_CTRL) {
! 				s->_fastMode ^= 1;
! 			}
! 			if (event.key.keysym.sym=='g' && event.key.keysym.mod&KMOD_CTRL) {
! 				s->_fastMode ^= 2;
! 			}
  
! 			if (event.key.keysym.sym=='d' && event.key.keysym.mod&KMOD_CTRL) {
! 				debugger.attach(s);
! 			}
! 			if (event.key.keysym.sym=='s' && event.key.keysym.mod&KMOD_CTRL) {
! 				s->resourceStats();
! 			}
  
! #if defined(__APPLE__)
! 			if (event.key.keysym.sym=='q' && event.key.keysym.mod&KMOD_LMETA) {
  				exit(1);
! 			} 
! #endif
! 			break;
! 		case SDL_MOUSEMOTION: {
! 			int newx,newy;
! #if !defined(SCALEUP_2x2)
! 			newx = event.motion.x;
! 			newy = event.motion.y;
! #else
! 			newx = event.motion.x>>1;
! 			newy = event.motion.y>>1;
! #endif
! 			if (newx != s->mouse.x || newy != s->mouse.y) {
! 				s->mouse.x = newx;
! 				s->mouse.y = newy;
! 				s->drawMouse();
! 				updateScreen(s);
! 			}
! 			break;
  			}
- 		case SDL_MOUSEBUTTONDOWN:
- 			if (event.button.button==SDL_BUTTON_LEFT)
- 				s->_leftBtnPressed |= 1;
- 			else if (event.button.button==SDL_BUTTON_RIGHT)
- 				s->_rightBtnPressed |= 1;
- 			break;
- 		case SDL_QUIT:
- 			exit(1);
- 			break;
  		}
! 	}
! 	
! 	if (!(s->_fastMode&2)) {
! 		assert(delay<500);
! 		SDL_Delay(delay*10);
! 	}
  }
  
--- 72,159 ----
  }
  
! void waitForTimer(Scumm *s, int msec_delay) {
  	SDL_Event event;
! 	uint32 start_time;
  
! 	if (msec_delay<0)
! 		return;
  
! 	if (s->_fastMode&2)
! 		msec_delay = 0;
! 	else if (s->_fastMode&1)
! 		msec_delay = 10;
! 
! 	start_time = SDL_GetTicks();
! 
! 	do {
! 		while (SDL_PollEvent(&event)) {
! 			switch(event.type) {
! 			case SDL_KEYDOWN:
! 				s->_keyPressed = mapKey(event.key.keysym.sym, event.key.keysym.mod);
! 				if (event.key.keysym.sym >= '0' && event.key.keysym.sym<='9') {
! 					s->_saveLoadSlot = event.key.keysym.sym - '0';
! 					if (event.key.keysym.mod&KMOD_SHIFT) {
! 						sprintf(s->_saveLoadName, "Quicksave %d", s->_saveLoadSlot);
! 						s->_saveLoadFlag = 1;
! 					} else if (event.key.keysym.mod&KMOD_CTRL)
! 						s->_saveLoadFlag = 2;
! 					s->_saveLoadCompatible = false;
! 				}
! 				if (event.key.keysym.sym=='z' && event.key.keysym.mod&KMOD_CTRL) {
! 					exit(1);
! 				} 
! 				if (event.key.keysym.sym=='f' && event.key.keysym.mod&KMOD_CTRL) {
! 					s->_fastMode ^= 1;
! 				}
! 				if (event.key.keysym.sym=='g' && event.key.keysym.mod&KMOD_CTRL) {
! 					s->_fastMode ^= 2;
! 				}
! 
! 				if (event.key.keysym.sym=='d' && event.key.keysym.mod&KMOD_CTRL) {
! 					debugger.attach(s);
! 				}
! 				if (event.key.keysym.sym=='s' && event.key.keysym.mod&KMOD_CTRL) {
! 					s->resourceStats();
! 				}
! 
! 	#if defined(__APPLE__)
! 				if (event.key.keysym.sym=='q' && event.key.keysym.mod&KMOD_LMETA) {
! 					exit(1);
! 				} 
! 	#endif
! 				break;
! 			case SDL_MOUSEMOTION: {
! 				int newx,newy;
! 	#if !defined(SCALEUP_2x2)
! 				newx = event.motion.x;
! 				newy = event.motion.y;
! 	#else
! 				newx = event.motion.x>>1;
! 				newy = event.motion.y>>1;
! 	#endif
! 				if (newx != s->mouse.x || newy != s->mouse.y) {
! 					s->mouse.x = newx;
! 					s->mouse.y = newy;
! 					s->drawMouse();
! 					updateScreen(s);
! 				}
! 				break;
! 				}
! 			case SDL_MOUSEBUTTONDOWN:
! 				if (event.button.button==SDL_BUTTON_LEFT)
! 					s->_leftBtnPressed |= 1;
! 				else if (event.button.button==SDL_BUTTON_RIGHT)
! 					s->_rightBtnPressed |= 1;
! 				break;
! 			case SDL_QUIT:
  				exit(1);
! 				break;
  			}
  		}
! 
! 		if (SDL_GetTicks() >= start_time + msec_delay)
! 			break;
! 		SDL_Delay(10);
! 	} while (1);
  }
  
***************
*** 469,577 ****
  		old_mouse_y = ydraw;
  	}
- 
- }
- 
- #define SAMPLES_PER_SEC 22050
- #define BUFFER_SIZE (8192)
- #define BITS_PER_SAMPLE 16
- 
- struct MixerChannel {
- 	void *_sfx_sound;
- 	uint32 _sfx_pos;
- 	uint32 _sfx_size;
- 	uint32 _sfx_fp_speed;
- 	uint32 _sfx_fp_pos;
- 
- 	void mix(int16 *data, uint32 len);
- 	void clear();
- };
- 
- #define NUM_MIXER 4
- 
- static MixerChannel mixer_channel[NUM_MIXER];
- 
- MixerChannel *find_channel() {
- 	int i;
- 	MixerChannel *mc = mixer_channel;
- 	for(i=0; i<NUM_MIXER; i++,mc++) {
- 		if (!mc->_sfx_sound)
- 			return mc;
- 	}
- 	return NULL;
- }
- 
- 
- bool isSfxFinished() {
- 	int i;
- 	for(i=0; i<NUM_MIXER; i++)
- 		if (mixer_channel[i]._sfx_sound)
- 			return false;
- 	return true;
  }
- 
- void playSfxSound(void *sound, uint32 size, uint rate) {
- 	MixerChannel *mc = find_channel();
- 
- 	if (!mc) {
- 		warning("No mixer channel available");
- 		return;
- 	}
  
! 	mc->_sfx_sound = sound;
! 	mc->_sfx_pos = 0;
! 	mc->_sfx_fp_speed = (1<<16) * rate / 22050;
! 	mc->_sfx_fp_pos = 0;
  
! 	while (size&0xFFFF0000) size>>=1, rate>>=1;
! 	mc->_sfx_size = size * 22050 / rate;
  }
  
! void MixerChannel::mix(int16 *data, uint32 len) {
! 	int8 *s;
! 	int i;
! 	uint32 fp_pos, fp_speed;
! 
! 	if (!_sfx_sound)
! 		return;
! 	if (len > _sfx_size)
! 		len = _sfx_size;
! 	_sfx_size -= len;
  
! 	s = (int8*)_sfx_sound + _sfx_pos;
! 	fp_pos = _sfx_fp_pos;
! 	fp_speed = _sfx_fp_speed;
  
  	do {
! 		fp_pos += fp_speed;
! 		*data++ += (*s<<6);
! 		s += fp_pos >> 16;
! 		fp_pos &= 0x0000FFFF;
! 	} while (--len);
! 
! 	_sfx_pos = s - (int8*)_sfx_sound;
! 	_sfx_fp_speed = fp_speed;
! 	_sfx_fp_pos = fp_pos;
! 
! 	if (!_sfx_size)
! 		clear();
! }
! 
! void MixerChannel::clear() {
! 	free(_sfx_sound);
! 	_sfx_sound = NULL;
! }
! 
! void fill_sound(void *userdata, Uint8 *stream, int len) {
! 	int i;
! 
! #if defined(USE_IMUSE)
! 	sound.generate_samples((int16*)stream, len>>1);
! #else
! 	memset(stream, 0, len);
! #endif
  	
! 	for(i=NUM_MIXER-1; i>=0;i--) {
! 		mixer_channel[i].mix((int16*)stream, len>>1);
! 	}
  }
  
--- 478,506 ----
  		old_mouse_y = ydraw;
  	}
  }
  
! static uint32 midi_counter;
  
! void fill_sound(void *userdata, Uint8 *stream, int len) {
! 	memset(stream, 0, len);
! 	scumm.mixWaves((int16*)stream, len>>1);
  }
  
! int music_thread(Scumm *s) {
! 	int old_time, cur_time;
  
! 	old_time = SDL_GetTicks();
  
  	do {
! 		SDL_Delay(10);
! 		
! 		cur_time = SDL_GetTicks();
! 		while (old_time < cur_time) {
! 			old_time += 10;
! 			sound.on_timer();	
! 		}
! 	} while (1);
  	
! 	return 0;
  }
  
***************
*** 600,607 ****
  	SDL_PauseAudio(0);
  
- 
  	SDL_WM_SetCaption(buf,buf);
  	SDL_ShowCursor(SDL_DISABLE);
  
  #if !defined(SCALEUP_2x2)
  	screen = SDL_SetVideoMode(320, 200, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE);
--- 529,538 ----
  	SDL_PauseAudio(0);
  
  	SDL_WM_SetCaption(buf,buf);
  	SDL_ShowCursor(SDL_DISABLE);
  
+ 	/* Create Music Thread */
+ 	SDL_CreateThread((int (*)(void *))&music_thread, &scumm);
+ 
  #if !defined(SCALEUP_2x2)
  	screen = SDL_SetVideoMode(320, 200, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE);
***************
*** 628,636 ****
  int main(int argc, char* argv[]) {
  	int delta,tmp;
  
! #if defined(USE_IMUSE)
! 	sound.initialize(NULL);
  	scumm._soundDriver = &sound;
- #endif
  
  	scumm._gui = &gui;
--- 559,566 ----
  int main(int argc, char* argv[]) {
  	int delta,tmp;
+ 	int last_time, new_time;
  
! 	sound.initialize(&scumm);
  	scumm._soundDriver = &sound;
  
  	scumm._gui = &gui;
***************
*** 639,658 ****
  	gui.init(&scumm);
  
  	delta = 0;
  	do {
  		updateScreen(&scumm);
  
  		if (gui._active) {
  			gui.loop();
! 			tmp = 5;
  		} else {
! 			tmp = delta = scumm.scummLoop(delta);
! 			tmp += tmp>>1;
! 			
! 			if (scumm._fastMode)
! 				tmp=1;
  		}
- 
- 		waitForTimer(&scumm, tmp);
  	} while(1);
  
--- 569,587 ----
  	gui.init(&scumm);
  
+ 	last_time = SDL_GetTicks();
  	delta = 0;
  	do {
  		updateScreen(&scumm);
  
+ 		new_time = SDL_GetTicks();
+ 		waitForTimer(&scumm, delta * 15 + last_time - new_time);
+ 		last_time = SDL_GetTicks();
+ 
  		if (gui._active) {
  			gui.loop();
! 			delta = 5;
  		} else {
! 			delta = scumm.scummLoop(delta);
  		}
  	} while(1);
  

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** sound.cpp	2001/11/12 20:50:36	1.6
--- sound.cpp	2001/11/14 18:37:38	1.7
***************
*** 22,39 ****
  #include "stdafx.h"
  #include "scumm.h"
- 
- #if defined(USE_IMUSE)
  #include "sound.h"
- #else
- struct SoundEngine {
- 	byte **_base_sounds;
- 	int start_sound(int sound) { return -1; }
- 	int stop_sound(int sound) { return -1; }
- 	int stop_all_sounds() { return -1; }
- 	int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h) { return -1; }
- 	int get_sound_status(int sound) { return -1; }
- 	int clear_queue() { return -1; }
- };
- #endif
  
  void Scumm::addSoundToQueue(int sound) {
--- 22,26 ----
***************
*** 171,174 ****
--- 158,168 ----
  }
  
+ void Scumm::stopTalkSound() {
+ 	if (_sfxMode==2) {
+ 		stopSfxSound();
+ 		_sfxMode = 0;
+ 	}
+ }
+ 
  bool Scumm::isMouthSyncOff(uint pos) {
  	uint j;
***************
*** 204,208 ****
  	if (!isResourceLoaded(rtSound, sound))
  		return 0;
- 
  	
  	se = (SoundEngine*)_soundDriver;
--- 198,201 ----
***************
*** 252,255 ****
--- 245,249 ----
  	}
  	clearSoundQue();
+ 	stopSfxSound();
  }
  
***************
*** 284,296 ****
  }
  
  static const uint32 sound_tags[] = {
! 	MKID('ADL ')
  };
  
  void Scumm::setupSound() {
  	SoundEngine *se = (SoundEngine*)_soundDriver;
! 	if (se) {
  		se->_base_sounds = res.address[rtSound];
! 	}
  	_soundTagTable = (byte*)sound_tags;
  	_numSoundTags = 1;
--- 278,297 ----
  }
  
+ /* The sound code currently only supports General Midi.
+  * General Midi is used in Day Of The Tentacle.
+  * Roland music is also playable, but doesn't sound well.
+  * A mapping between roland instruments and GM instruments
+  * is needed.
+  */
+    
  static const uint32 sound_tags[] = {
! 	MKID('GMD ')
  };
  
  void Scumm::setupSound() {
  	SoundEngine *se = (SoundEngine*)_soundDriver;
! 	if (se)
  		se->_base_sounds = res.address[rtSound];
! 
  	_soundTagTable = (byte*)sound_tags;
  	_numSoundTags = 1;
***************
*** 298,301 ****
--- 299,309 ----
  }
  
+ void Scumm::pauseSounds(bool pause) {
+ 	SoundEngine *se = (SoundEngine*)_soundDriver;
+ 	if (se)
+ 		se->pause(pause);
+ 	_soundsPaused = pause;
+ }
+ 
  struct VOCHeader {
  	byte id[19];
***************
*** 304,308 ****
  
  static const char VALID_VOC_ID[] = "Creative Voice File";
! static const char VALID_VOC_VERSION[] = "";
  void Scumm::startSfxSound(void *file) {
  	VOCHeader hdr;
--- 312,316 ----
  
  static const char VALID_VOC_ID[] = "Creative Voice File";
! 
  void Scumm::startSfxSound(void *file) {
  	VOCHeader hdr;
***************
*** 355,357 ****
  void *Scumm::openSfxFile() {
  	return fopen("monster.sou", "rb");
! }
\ No newline at end of file
--- 363,459 ----
  void *Scumm::openSfxFile() {
  	return fopen("monster.sou", "rb");
! }
! 
! #define NUM_MIXER 4
! 
! MixerChannel *Scumm::allocateMixer() {
! 	int i;
! 	MixerChannel *mc = _mixer_channel;
! 	for(i=0; i<NUM_MIXER; i++,mc++) {
! 		if (!mc->_sfx_sound)
! 			return mc;
! 	}
! 	return NULL;
! }
! 
! void Scumm::stopSfxSound() {
! 	MixerChannel *mc = _mixer_channel;
! 	int i;
! 	for(i=0; i<NUM_MIXER; i++,mc++) {
! 		if (mc->_sfx_sound)
! 			mc->clear();
! 	}
! }
! 
! 
! bool Scumm::isSfxFinished() {
! 	int i;
! 	for(i=0; i<NUM_MIXER; i++)
! 		if (_mixer_channel[i]._sfx_sound)
! 			return false;
! 	return true;
! }
! 
! void Scumm::playSfxSound(void *sound, uint32 size, uint rate) {
! 	MixerChannel *mc = allocateMixer();
! 
! 	if (!mc) {
! 		warning("No mixer channel available");
! 		return;
! 	}
! 
! 	mc->_sfx_sound = sound;
! 	mc->_sfx_pos = 0;
! 	mc->_sfx_fp_speed = (1<<16) * rate / 22050;
! 	mc->_sfx_fp_pos = 0;
! 
! 	while (size&0xFFFF0000) size>>=1, rate>>=1;
! 	mc->_sfx_size = size * 22050 / rate;
! }
! 
! void MixerChannel::mix(int16 *data, uint32 len) {
! 	int8 *s;
! 	int i;
! 	uint32 fp_pos, fp_speed;
! 
! 	if (!_sfx_sound)
! 		return;
! 	if (len > _sfx_size)
! 		len = _sfx_size;
! 	_sfx_size -= len;
! 
! 	s = (int8*)_sfx_sound + _sfx_pos;
! 	fp_pos = _sfx_fp_pos;
! 	fp_speed = _sfx_fp_speed;
! 
! 	do {
! 		fp_pos += fp_speed;
! 		*data++ += (*s<<6);
! 		s += fp_pos >> 16;
! 		fp_pos &= 0x0000FFFF;
! 	} while (--len);
! 
! 	_sfx_pos = s - (int8*)_sfx_sound;
! 	_sfx_fp_speed = fp_speed;
! 	_sfx_fp_pos = fp_pos;
! 
! 	if (!_sfx_size)
! 		clear();
! }
! 
! void MixerChannel::clear() {
! 	free(_sfx_sound);
! 	_sfx_sound = NULL;
! }
! 
! void Scumm::mixWaves(int16 *sounds, int len) {
! 	int i;
! 
! 	if (_soundsPaused)
! 		return;
! 
! 	for(i=NUM_MIXER-1; i>=0;i--) {
! 		_mixer_channel[i].mix(sounds, len);
! 	}
! }
! 

Index: string.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/string.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** string.cpp	2001/11/09 18:54:15	1.9
--- string.cpp	2001/11/14 18:37:38	1.10
***************
*** 277,280 ****
--- 277,282 ----
  	if (charset._center) {
  		charset._xpos2 -= charset.getStringWidth(0, buffer,0) >> 1;
+ 		if (charset._xpos2<0)
+ 			charset._xpos2 = 0;
  	}
  

Index: windows.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/windows.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** windows.cpp	2001/11/10 23:30:11	1.17
--- windows.cpp	2001/11/14 18:37:38	1.18
***************
*** 32,40 ****
  
  #include "scumm.h"
- 
- #if defined(USE_IMUSE)
  #include "sound.h"
- #endif
- 
  #include "gui.h"
  
--- 32,36 ----
***************
*** 136,143 ****
  ScummDebugger debugger;
  Gui gui;
- 
- #if defined(USE_IMUSE)
  SoundEngine sound;
- #endif
  
  WndMan wm[1];
--- 132,136 ----
***************
*** 820,913 ****
  }
  
- #define SAMPLES_PER_SEC 22050
- #define BUFFER_SIZE (8192)
- #define BITS_PER_SAMPLE 16
- 
- struct MixerChannel {
- 	void *_sfx_sound;
- 	uint32 _sfx_pos;
- 	uint32 _sfx_size;
- 	uint32 _sfx_fp_speed;
- 	uint32 _sfx_fp_pos;
- 
- 	void mix(int16 *data, uint32 len);
- 	void clear();
- };
- 
- #define NUM_MIXER 4
- 
- static MixerChannel mixer_channel[NUM_MIXER];
- 
- MixerChannel *find_channel() {
- 	int i;
- 	MixerChannel *mc = mixer_channel;
- 	for(i=0; i<NUM_MIXER; i++,mc++) {
- 		if (!mc->_sfx_sound)
- 			return mc;
- 	}
- 	return NULL;
- }
- 
- 
- bool isSfxFinished() {
- 	int i;
- 	for(i=0; i<NUM_MIXER; i++)
- 		if (mixer_channel[i]._sfx_sound)
- 			return false;
- 	return true;
- }
- 
- void playSfxSound(void *sound, uint32 size, uint rate) {
- 	MixerChannel *mc = find_channel();
- 
- 	if (!mc) {
- 		warning("No mixer channel available");
- 		return;
- 	}
- 
- 	mc->_sfx_sound = sound;
- 	mc->_sfx_pos = 0;
- 	mc->_sfx_fp_speed = (1<<16) * rate / 22050;
- 	mc->_sfx_fp_pos = 0;
- 
- 	while (size&0xFFFF0000) size>>=1, rate>>=1;
- 	mc->_sfx_size = size * 22050 / rate;
- }
- 
- void MixerChannel::mix(int16 *data, uint32 len) {
- 	int8 *s;
- 	int i;
- 	uint32 fp_pos, fp_speed;
- 
- 	if (!_sfx_sound)
- 		return;
- 	if (len > _sfx_size)
- 		len = _sfx_size;
- 	_sfx_size -= len;
  
- 	s = (int8*)_sfx_sound + _sfx_pos;
- 	fp_pos = _sfx_fp_pos;
- 	fp_speed = _sfx_fp_speed;
- 
- 	do {
- 		fp_pos += fp_speed;
- 		*data++ += (*s<<6);
- 		s += fp_pos >> 16;
- 		fp_pos &= 0x0000FFFF;
- 	} while (--len);
- 
- 	_sfx_pos = s - (int8*)_sfx_sound;
- 	_sfx_fp_speed = fp_speed;
- 	_sfx_fp_pos = fp_pos;
- 
- 	if (!_sfx_size)
- 		clear();
- }
- 
- void MixerChannel::clear() {
- 	free(_sfx_sound);
- 	_sfx_sound = NULL;
- }
- 
  int clock;
  
--- 813,817 ----
***************
*** 924,929 ****
  	wm->handleMessage();
  	if (!veryFastMode) {
! 		assert(delay<500);
! 		Sleep(delay*10);
  	} 
  }
--- 828,833 ----
  	wm->handleMessage();
  	if (!veryFastMode) {
! 		assert(delay<5000);
! 		Sleep(delay);
  	} 
  }
***************
*** 941,954 ****
  
  void fill_buffer(int16 *buf, int len) {
- 	int i;
- #if defined(USE_IMUSE)
- 	sound.generate_samples(buf,len);
- #else
  	memset(buf, 0, len*2);
! #endif
! 	for(i=NUM_MIXER-1; i>=0;i--) {
! 		mixer_channel[i].mix((int16*)buf, len);
! 	}
! 
  }
  
--- 845,850 ----
  
  void fill_buffer(int16 *buf, int len) {
  	memset(buf, 0, len*2);
! 	scumm.mixWaves(buf, len);
  }
  
***************
*** 976,979 ****
--- 872,876 ----
  
  	CreateThread(NULL, 0, (unsigned long (__stdcall *)(void *))&sound_thread, this, 0, &_threadId);
+ 	SetThreadPriority((void*)_threadId, THREAD_PRIORITY_HIGHEST);
  
  	_event = CreateEvent(NULL, false, false, NULL);
***************
*** 989,999 ****
  DWORD _stdcall WndMan::sound_thread(WndMan *wm) {
  	int i;
  	while (1) {
! 		WaitForSingleObject(wm->_event, INFINITE);
! 		for(i=0; i<2; i++) {
! 			WAVEHDR *hdr = &wm->_hdr[i];
! 			if (hdr->dwFlags & WHDR_DONE) {
! 				fill_buffer((int16*)hdr->lpData, hdr->dwBufferLength>>1);
! 				waveOutWrite(wm->_handle, hdr, sizeof(WAVEHDR));
  			}
  		}
--- 886,908 ----
  DWORD _stdcall WndMan::sound_thread(WndMan *wm) {
  	int i;
+ 	bool signaled;
+ 	int time = GetTickCount(), cur;
+ 
  	while (1) {
! 		cur = GetTickCount();
! 		while (time < cur) {
! 			sound.on_timer();
! 			time += 10;
! 		}
! 
! 		signaled = WaitForSingleObject(wm->_event, time - cur) == WAIT_OBJECT_0;
! 
! 		if (signaled) {
! 			for(i=0; i<2; i++) {
! 				WAVEHDR *hdr = &wm->_hdr[i];
! 				if (hdr->dwFlags & WHDR_DONE) {
! 					fill_buffer((int16*)hdr->lpData, hdr->dwBufferLength>>1);
! 					waveOutWrite(wm->_handle, hdr, sizeof(WAVEHDR));
! 				}
  			}
  		}
***************
*** 1012,1019 ****
  	wm->_scumm = &scumm;
  	
! #if defined(USE_IMUSE)
! 	sound.initialize(NULL);
  	scumm._soundDriver = &sound;
- #endif
  
  	scumm._gui = &gui;
--- 921,926 ----
  	wm->_scumm = &scumm;
  	
! 	sound.initialize(&scumm);
  	scumm._soundDriver = &sound;
  
  	scumm._gui = &gui;
***************
*** 1025,1028 ****
--- 932,937 ----
  		updateScreen(&scumm);
  
+ 		waitForTimer(&scumm, tmp*10);
+ 
  		if (gui._active) {
  			gui.loop();
***************
*** 1036,1041 ****
  				tmp=1;
  		}
- 		
- 		waitForTimer(&scumm, tmp);
  	} while(1);
  
--- 945,948 ----





More information about the Scummvm-git-logs mailing list