[Scummvm-cvs-logs] CVS: scummvm/sound imuse.cpp,1.31,1.32 imuse.h,1.3,1.4

Max Horn fingolfin at users.sourceforge.net
Fri May 3 17:21:02 CEST 2002


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

Modified Files:
	imuse.cpp imuse.h 
Log Message:
automatic detecion of MT32 vs. GM midi; removed obsolete -r command line option

Index: imuse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/imuse.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- imuse.cpp	2 May 2002 14:47:17 -0000	1.31
+++ imuse.cpp	4 May 2002 00:20:39 -0000	1.32
@@ -116,6 +116,8 @@
 
 	HookDatas _hook;
 
+	bool _mt32emulate;
+
 	/* Player part */
 	void hook_clear();
 	void clear();
@@ -320,8 +322,6 @@
 	byte _locked;
 	byte _hardware_type;
 
-public:
-	bool _mt32emulate;
 private:
 	
 
@@ -359,6 +359,7 @@
 	CommandQueue _cmd_queue[64];
 
 	byte *findTag(int sound, char *tag, int index);
+	bool isMT32(int sound);
 	int get_queue_sound_status(int sound);
 	Player *allocate_player(byte priority);
 	void handle_marker(uint id, byte data);
@@ -494,7 +495,7 @@
 	Struct11 _s11b;
 };
 
-struct IMuseAdlib : public IMuseDriver {
+class IMuseAdlib : public IMuseDriver {
 private:
 	FM_OPL *_opl;
 	byte *_adlib_reg_cache;
@@ -592,7 +593,7 @@
 	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 midiProgram(byte chan, byte program, bool mt32emulate);
 	void midiPan(byte chan, int8 pan);
 	void midiNoteOn(byte chan, byte note, byte velocity);
 	void midiNoteOff(byte chan, byte note);
@@ -774,7 +775,34 @@
 	
 	debug(1, "IMuseInternal::findTag failed finding sound %d", sound);
 	return NULL;
+}
+
+bool IMuseInternal::isMT32(int sound)
+{
+	byte *ptr = NULL;
+	uint32 tag;
 
+	if (_base_sounds)
+		ptr = _base_sounds[sound];
+
+	if (ptr == NULL)
+		return false;
+
+	tag = *(((uint32 *)ptr)+1);
+	switch (tag) {
+	case MKID('ADL '):
+		return false;
+	case MKID('ROL '):
+		return true;
+	case MKID('GMD '):
+		return false;
+	case MKID('MAC '):
+		return true;
+	case MKID('SPK '):
+		return false;
+	}
+	
+	return false;
 }
 
 bool IMuseInternal::start_sound(int sound)
@@ -922,46 +950,6 @@
 	}
 }
 
-void Player::sequencer_timer()
-{
-	byte *mtrk;
-	uint32 counter;
-	byte *song_ptr;
-
-	counter = _timer_counter + _timer_speed;
-	_timer_counter = counter & 0xFFFF;
-	_cur_pos += counter >> 16;
-	_tick_index += counter >> 16;
-
-	if (_tick_index >= _ticks_per_beat) {
-		_beat_index += _tick_index / _ticks_per_beat;
-		_tick_index %= _ticks_per_beat;
-	}
-	if (_loop_counter && _beat_index >= _loop_from_beat
-			&& _tick_index >= _loop_from_tick) {
-		_loop_counter--;
-		jump(_track_index, _loop_to_beat, _loop_to_tick);
-	}
-	if (_next_pos <= _cur_pos) {
-		mtrk = _se->findTag(_song_index, "MTrk", _track_index);
-		if (!mtrk) {
-			warning("Sound %d was unloaded while active", _song_index);
-			clear();
-		} else {
-			song_ptr = mtrk + _song_offset;
-			_abort = false;
-
-			while (_next_pos <= _cur_pos) {
-				song_ptr = parse_midi(song_ptr);
-				if (!song_ptr || _abort)
-					return;
-				_next_pos += get_delta_time(&song_ptr);
-			}
-			_song_offset = song_ptr - mtrk;
-		}
-	}
-}
-
 void IMuseInternal::handle_marker(uint id, byte data)
 {
 	uint16 *p;
@@ -1577,10 +1565,6 @@
 	case IMuse::PROP_TEMPO_BASE:
 		_game_tempo = value;
 		break;
-
-	case IMuse::PROP_MT32_EMULATE:
-		_mt32emulate = !!value;
-		break;
 	}
 	return 0;
 }
@@ -1719,6 +1703,7 @@
 			return false;
 		}
 	}
+	_mt32emulate = _se->isMT32(sound);
 	_parts = NULL;
 	_active = true;
 	_id = sound;
@@ -2728,6 +2713,46 @@
 	return 129;
 }
 
+void Player::sequencer_timer()
+{
+	byte *mtrk;
+	uint32 counter;
+	byte *song_ptr;
+
+	counter = _timer_counter + _timer_speed;
+	_timer_counter = counter & 0xFFFF;
+	_cur_pos += counter >> 16;
+	_tick_index += counter >> 16;
+
+	if (_tick_index >= _ticks_per_beat) {
+		_beat_index += _tick_index / _ticks_per_beat;
+		_tick_index %= _ticks_per_beat;
+	}
+	if (_loop_counter && _beat_index >= _loop_from_beat
+			&& _tick_index >= _loop_from_tick) {
+		_loop_counter--;
+		jump(_track_index, _loop_to_beat, _loop_to_tick);
+	}
+	if (_next_pos <= _cur_pos) {
+		mtrk = _se->findTag(_song_index, "MTrk", _track_index);
+		if (!mtrk) {
+			warning("Sound %d was unloaded while active", _song_index);
+			clear();
+		} else {
+			song_ptr = mtrk + _song_offset;
+			_abort = false;
+
+			while (_next_pos <= _cur_pos) {
+				song_ptr = parse_midi(song_ptr);
+				if (!song_ptr || _abort)
+					return;
+				_next_pos += get_delta_time(&song_ptr);
+			}
+			_song_offset = song_ptr - mtrk;
+		}
+	}
+}
+
 /*******************************************************************/
 
 #define OFFS(type,item) ((int)(&((type*)0)->item))
@@ -2912,6 +2937,7 @@
 		if (player->_active) {
 			player->set_tempo(player->_tempo);
 			scumm->getResourceAddress(rtSound, player->_id);
+			player->_mt32emulate = isMT32(player->_id);
 		}
 	}
 }
@@ -4153,10 +4179,10 @@
 }
 
 
-void IMuseGM::midiProgram(byte chan, byte program)
+void IMuseGM::midiProgram(byte chan, byte program, bool mt32emulate)
 {
 //	if ((chan + 1) != 10) {				/* Ignore percussion prededed by patch change */
-		if (_se->_mt32emulate)
+		if (mt32emulate)
 			program = mt32_to_gmidi[program];
 
 		_md->send(program << 8 | 0xC0 | chan);
@@ -4197,7 +4223,7 @@
 		midiNoteOn(mc->_chan, note, velocity);
 	} else if (part->_percussion) {
 		midiVolume(SPECIAL_CHANNEL, part->_vol_eff);
-		midiProgram(SPECIAL_CHANNEL, part->_bank);
+		midiProgram(SPECIAL_CHANNEL, part->_bank, part->_player->_mt32emulate);
 		midiNoteOn(SPECIAL_CHANNEL, note, velocity);
 	}
 }
@@ -4408,10 +4434,10 @@
 	if (what & pcProgram) {
 		if (part->_bank) {
 			midiControl0(mc->_chan, part->_bank);
-			midiProgram(mc->_chan, part->_program);
+			midiProgram(mc->_chan, part->_program, part->_player->_mt32emulate);
 			midiControl0(mc->_chan, 0);
 		} else {
-			midiProgram(mc->_chan, part->_program);
+			midiProgram(mc->_chan, part->_program, part->_player->_mt32emulate);
 		}
 	}
 

Index: imuse.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/imuse.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- imuse.h	29 Apr 2002 11:48:33 -0000	1.3
+++ imuse.h	4 May 2002 00:20:39 -0000	1.4
@@ -26,7 +26,6 @@
 public:
 	enum {
 		PROP_TEMPO_BASE = 1,
-		PROP_MT32_EMULATE = 2,
 	};
 
 	IMuse();





More information about the Scummvm-git-logs mailing list