[Scummvm-cvs-logs] CVS: scummvm script_v1.cpp,1.78,1.79 scummvm.cpp,1.115,1.116 sdl.cpp,1.95,1.96 sound.cpp,1.46,1.47 x11.cpp,1.12,1.13 scumm.h,1.122,1.123

Nicolas Bacca arisme at users.sourceforge.net
Wed Apr 17 13:23:00 CEST 2002


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

Modified Files:
	script_v1.cpp scummvm.cpp sdl.cpp sound.cpp x11.cpp scumm.h 
Log Message:
Return of the MP3 CD patch ... use CBR 22 kHz

Index: script_v1.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/script_v1.cpp,v
retrieving revision 1.78
retrieving revision 1.79
diff -C2 -d -r1.78 -r1.79
*** script_v1.cpp	16 Apr 2002 16:25:56 -0000	1.78
--- script_v1.cpp	17 Apr 2002 20:22:20 -0000	1.79
***************
*** 2673,2678 ****
  					offset = 0;
  				delay = (int)((getVarOrDirectWord(0x40) & 0xffff) * 7.5);
! 				if (_gameId == GID_LOOM256)
  					_system->play_cdrom(1, 0, offset, delay);
  				else
  					warning("parseString: 8");
--- 2673,2684 ----
  					offset = 0;
  				delay = (int)((getVarOrDirectWord(0x40) & 0xffff) * 7.5);
! 				if (_gameId == GID_LOOM256) {					
! 					_vars[VAR_MUSIC_FLAG] = 0;
! #ifdef COMPRESSED_SOUND_FILE
! 					playMP3CDTrack(1, 0, offset, delay);
! #else
  					_system->play_cdrom(1, 0, offset, delay);
+ #endif
+ 				}
  				else
  					warning("parseString: 8");

Index: scummvm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scummvm.cpp,v
retrieving revision 1.115
retrieving revision 1.116
diff -C2 -d -r1.115 -r1.116
*** scummvm.cpp	16 Apr 2002 16:25:57 -0000	1.115
--- scummvm.cpp	17 Apr 2002 20:22:21 -0000	1.116
***************
*** 64,68 ****
  		loadCharset(1);
  
- 	
  	initScreens(0, 16, 320, 144);
  
--- 64,67 ----
***************
*** 168,171 ****
--- 167,175 ----
  
  	getGraphicsPerformance();
+ 
+ #ifdef COMPRESSED_SOUND_FILE
+ 	_current_cache = 0;
+ 	_mp3_buffer = NULL;
+ #endif
  }
  
***************
*** 239,243 ****
  	_vars[VAR_DEBUGMODE] = _debugMode;
  
! 	if (_features & GF_AUDIOTRACKS) {
  		if (delta) {
  			if (++counter != 2)
--- 243,247 ----
  	_vars[VAR_DEBUGMODE] = _debugMode;
  
! 	if (_features & GF_AUDIOTRACKS) {		
  		if (delta) {
  			if (++counter != 2)
***************
*** 246,250 ****
  				counter = 0;
  				_vars[VAR_MI1_TIMER] += 6;
! 			}
  		}
  	} else if (_features & GF_OLD256)
--- 250,254 ----
  				counter = 0;
  				_vars[VAR_MI1_TIMER] += 6;
! 			}				
  		}
  	} else if (_features & GF_OLD256)
***************
*** 903,908 ****
  {
  	if (id < 1 || id >= NUM_ACTORS) {
! 		if (_debugMode)
! 			warning("Invalid actor %d in %s (script %d, opcode 0x%x) - This is potentially a BIG problem.", id, errmsg, vm.slot[_curExecScript].number, _opcode);
  		return NULL;
  	}
--- 907,913 ----
  {
  	if (id < 1 || id >= NUM_ACTORS) {
! 		warning
! 			("Invalid actor %d in %s (script %d, opcode 0x%x) - This is potentially a BIG problem.",
! 			 id, errmsg, vm.slot[_curExecScript].number, _opcode);
  		return NULL;
  	}
***************
*** 1148,1152 ****
  		}
  
- 		_system->update_cdrom(); /* Loop CD Audio if needed */
  		if (_system->get_msecs() >= start_time + msec_delay)
  			break;
--- 1153,1156 ----
***************
*** 1213,1217 ****
  
  	/* Create a primary virtual screen */
- 	_videoBuffer = (byte*)malloc(328*200);
  
  	allocResTypeData(rtBuffer, MKID('NONE'), 10, "buffer", 0);
--- 1217,1220 ----
***************
*** 1289,1301 ****
  	/* bind the mixer to the system => mixer will be invoked
  	 * automatically when samples need to be generated */
! 	if (!scumm->_mixer->bind_to_system(syst)) {
! 		warning("Sound initialization failed");
! 		if (detector->_use_adlib) {
! 			detector->_use_adlib = false;
! 			detector->_midi_driver = MD_NULL;
! 			warning("Adlib music was selected, switching to midi null driver");
! 		}
! 	}
! 		
  	scumm->_mixer->set_volume(128);
  
--- 1292,1296 ----
  	/* bind the mixer to the system => mixer will be invoked
  	 * automatically when samples need to be generated */
! 	scumm->_mixer->bind_to_system(syst);
  	scumm->_mixer->set_volume(128);
  

Index: sdl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sdl.cpp,v
retrieving revision 1.95
retrieving revision 1.96
diff -C2 -d -r1.95 -r1.96
*** sdl.cpp	17 Apr 2002 11:20:55 -0000	1.95
--- sdl.cpp	17 Apr 2002 20:22:21 -0000	1.96
***************
*** 5,9 ****
  #include "gameDetector.h"
  
- #include "mp3_cd.h"
  #include <SDL.h>
  
--- 5,8 ----

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** sound.cpp	16 Apr 2002 18:33:03 -0000	1.46
--- sound.cpp	17 Apr 2002 20:22:21 -0000	1.47
***************
*** 505,508 ****
--- 505,509 ----
  		return file;
  	}
+ 
  	/* Try opening the file <_exe_name>.sou first, eg tentacle.sou.
  	 * That way, you can keep .sou files for multiple games in the
***************
*** 584,591 ****
  void Scumm::playSfxSound_MP3(void *sound, uint32 size)
  {
  #ifdef COMPRESSED_SOUND_FILE
  	_mixer->play_mp3(NULL, sound, size, SoundMixer::FLAG_AUTOFREE);
! #else
! 	error("Should never happen !!!");
  #endif
  }
--- 585,717 ----
  void Scumm::playSfxSound_MP3(void *sound, uint32 size)
  {
+ 
  #ifdef COMPRESSED_SOUND_FILE
+ 
  	_mixer->play_mp3(NULL, sound, size, SoundMixer::FLAG_AUTOFREE);
! 
  #endif
  }
+ 
+ #ifdef COMPRESSED_SOUND_FILE
+ 
+ int Scumm::getCachedTrack(int track) {
+ 	int i;
+ 	char track_name[1024];
+ 	FILE* file;
+ 	int current_index;
+ 	struct mad_stream stream;
+ 	struct mad_frame frame;
+ 	unsigned char buffer[8192];
+ 	unsigned int buflen = 0;
+ 	int count = 0, result = 0;
+ 
+ 	// See if we find the track in the cache
+ 	for (i=0; i<CACHE_TRACKS; i++)
+ 		if (_cached_tracks[i] == track) {
+ 			if (_mp3_tracks[i])
+ 				return i;
+ 			else
+ 				return -1;
+ 		}
+ 	current_index = _current_cache++;
+ 	_current_cache %= CACHE_TRACKS;
+ 	// Not found, see if it exists
+ 	sprintf(track_name, "%strack%d.mp3", _gameDataPath, track);
+ 	file = fopen(track_name, "rb");
+ 	_cached_tracks[current_index] = track;
+ 	_mp3_tracks[current_index] = NULL;
+ 	if (!file) {
+ 		warning("Track %d not available in mp3 format", track);
+ 		return -1;
+ 	}
+ 	// Check the format and bitrate
+ 	mad_stream_init(&stream);
+ 	mad_frame_init(&frame);
+ 
+ 	while (1) {
+ 		if (buflen < sizeof(buffer)) {
+ 			uint16 bytes;
+ 
+ 			bytes = fread(buffer + buflen, 1, sizeof(buffer) - buflen, file);
+ 			if (bytes <= 0) {
+ 				if (bytes == -1) {
+ 					warning("Invalid format for track %d", track);
+ 					return -1;
+ 				}
+ 				break;
+ 			}
+ 
+ 			buflen += bytes;
+ 		}
+ 
+ 		mad_stream_buffer(&stream, buffer, buflen);
+ 
+ 		while (1) {
+ 			if (mad_frame_decode(&frame, &stream) == -1) {
+ 				if (!MAD_RECOVERABLE(stream.error))
+ 					break;
+ 
+ 				if (stream.error != MAD_ERROR_BADCRC)
+ 					continue;
+ 			}
+ 
+ 			if (count++)
+ 				break;
+ 		}
+ 
+ 		if (count || stream.error != MAD_ERROR_BUFLEN)
+ 			break;
+ 
+ 		memmove(buffer, stream.next_frame,
+ 						buflen = &buffer[buflen] - stream.next_frame);
+ 	}
+ 
+ 	if (count)
+ 		memcpy(&_mad_header[current_index], &frame.header, sizeof(mad_header));
+ 	else {
+ 		warning("Invalid format for track %d", track);
+ 		return -1;
+ 	}
+ 
+ 	mad_frame_finish(&frame);
+ 	mad_stream_finish(&stream);
+ 	// Get file size
+ 	fseek(file, 0, SEEK_END);
+ 	_mp3_size[current_index] = ftell(file);
+ 	_mp3_tracks[current_index] = file;
+ 	if (!_mp3_buffer)
+ 		_mp3_buffer = malloc(MP3_BUFFER_SIZE);
+ 	
+ 	return current_index;
+ }
+ 		
+ void Scumm::playMP3CDTrack(int track, int num_loops, int start, int delay) {
+ 	int index;
+ 	long offset;
+ 	float frame_size;
+ 	mad_timer_t duration;
+ 
+ 	if (!start && !delay) {
+ 		_mixer->stop(_mp3_handle);
+ 		return;
+ 	}
+ 
+ 	index = getCachedTrack(track);
+ 	if (index < 0)
+ 		return;
+ 
+ 	// Calc offset
+ 	frame_size = 144 * _mad_header[index].bitrate / _mad_header[index].samplerate;
+ 	offset = (long)((float)start / (float)75 * 1000 /
+ 	       			(float)((float)1152 / (float)_mad_header[index].samplerate *
+ 									  	  1000) * (float)(frame_size + 0.5));
+ 	// Calc delay
+ 	mad_timer_set(&duration, 0, delay, 75);
+ 	// Go
+ 	fseek(_mp3_tracks[index], offset, SEEK_SET);
+ 
+ 	_mixer->play_mp3_cdtrack(&_mp3_handle, _mp3_tracks[index], _mp3_buffer, MP3_BUFFER_SIZE, duration);
+ 
+ }
+ 
+ #endif
\ No newline at end of file

Index: x11.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/x11.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** x11.cpp	14 Apr 2002 18:13:07 -0000	1.12
--- x11.cpp	17 Apr 2002 20:22:22 -0000	1.13
***************
*** 26,30 ****
  #include "gui.h"
  #include "cdmusic.h"
- #include "mp3_cd.h"
  
  #include <sys/time.h>
--- 26,29 ----

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm.h,v
retrieving revision 1.122
retrieving revision 1.123
diff -C2 -d -r1.122 -r1.123
*** scumm.h	17 Apr 2002 04:35:04 -0000	1.122
--- scumm.h	17 Apr 2002 20:22:22 -0000	1.123
***************
*** 83,87 ****
  
  #define RES_DATA(x) (((byte*)x) + sizeof(ResHdr))
! #define RES_SIZE(x) ( READ_BE_UINT32_UNALIGNED(&((ResHdr*)x)->size) )
  
  
--- 83,87 ----
  
  #define RES_DATA(x) (((byte*)x) + sizeof(ResHdr))
! #define RES_SIZE(x) ( READ_BE_UINT32(&((ResHdr*)x)->size) )
  
  
***************
*** 596,600 ****
  	Scumm(); // constructor
  
! 	byte *_videoBuffer;
  
  	/* Scumm main loop */
--- 596,603 ----
  	Scumm(); // constructor
  
! 	/* video buffer */
! 	byte _videoBuffer[328*200]; // main video buffer
! 
! 	/* system call object */
  
  	/* Scumm main loop */
***************
*** 951,955 ****
  	uint16 _mouthSyncTimes[52];
  	uint _curSoundPos;
! 	int current_cd_sound;
  
  	int16 _soundQuePos, _soundQue[0x100];
--- 954,979 ----
  	uint16 _mouthSyncTimes[52];
  	uint _curSoundPos;
! 	int current_cd_sound;
! 
! #ifdef COMPRESSED_SOUND_FILE
! 
! 	#define CACHE_TRACKS 10
! 	#define MP3_BUFFER_SIZE 200000
! 
! 	/* used for mp3 CD music */
! 
! 	int	_current_cache;
! 	int _cached_tracks[CACHE_TRACKS];
! 	struct mad_header _mad_header[CACHE_TRACKS];
! 	long _mp3_size[CACHE_TRACKS];
! 	FILE* _mp3_tracks[CACHE_TRACKS];
! 	void* _mp3_buffer;
! 	PlayingSoundHandle _mp3_handle;
! 
! 	int getCachedTrack(int track);
! 	void playMP3CDTrack(int track, int num_loops, int start, int delay);
! 
! 
! #endif
  
  	int16 _soundQuePos, _soundQue[0x100];
***************
*** 1121,1124 ****
--- 1145,1149 ----
  	void redrawBGStrip(int start, int num);	
  	void redrawBGAreas();
+ 	void redrawLines(int from, int to);	
  	
  	void moveCamera();
***************
*** 1822,1824 ****
  void setWindowName(Scumm *s);
  uint16 newTag2Old(uint32 oldTag);
! 
--- 1847,1849 ----
  void setWindowName(Scumm *s);
  uint16 newTag2Old(uint32 oldTag);
! //void cd_playtrack(int track, int offset, int delay);





More information about the Scummvm-git-logs mailing list