[Scummvm-cvs-logs] CVS: scummvm gameDetector.cpp,1.12,1.13 gameDetector.h,1.7,1.8 gfx.cpp,1.63,1.64 gui.cpp,1.29,1.30 main.cpp,1.3,1.4 saveload.cpp,1.36,1.37 scumm.h,1.117,1.118 scummvm.cpp,1.108,1.109 scummvm.dsp,1.36,1.37 sdl.cpp,1.90,1.91 sound.cpp,1.40,1.41 system.h,1.5,1.6 windows.cpp,1.33,1.34 x11.cpp,1.11,1.12 sound.h,1.15,NONE

Ludvig Strigeus strigeus at users.sourceforge.net
Sun Apr 14 11:14:04 CEST 2002


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

Modified Files:
	gameDetector.cpp gameDetector.h gfx.cpp gui.cpp main.cpp 
	saveload.cpp scumm.h scummvm.cpp scummvm.dsp sdl.cpp sound.cpp 
	system.h windows.cpp x11.cpp 
Removed Files:
	sound.h 
Log Message:
wrote new mixer class,
cleaned up sound header files,
integrated mixer into scummvm & simon


Index: gameDetector.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gameDetector.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** gameDetector.cpp	13 Apr 2002 21:06:46 -0000	1.12
--- gameDetector.cpp	14 Apr 2002 18:13:07 -0000	1.13
***************
*** 24,29 ****
  #include "stdafx.h"
  #include "scumm.h"
  #include "gameDetector.h"
! 
  
  
--- 24,30 ----
  #include "stdafx.h"
  #include "scumm.h"
+ #include "mididrv.h"
  #include "gameDetector.h"
! #include "imuse.h"
  
  
***************
*** 105,119 ****
  						if (*(s + 1) == '\0')
  							goto ShowHelpAndExit;
! 						SoundEngine *se = (SoundEngine *)_soundEngine;
! 
! 						if (se)
! 							se->set_music_volume(atoi(s + 1));
  						goto NextArg;
  					}
  				case 'r':{
! 						SoundEngine *se = (SoundEngine *)_soundEngine;
! 
! 						if (se)
! 							se->_mt32emulate = true;
  						break;
  					}
--- 106,114 ----
  						if (*(s + 1) == '\0')
  							goto ShowHelpAndExit;
! 						_music_volume = atoi(s + 1);
  						goto NextArg;
  					}
  				case 'r':{
! 						_mt32emulate = true;
  						break;
  					}
***************
*** 209,214 ****
  		if (!scumm_stricmp(md->name, s)) {
  			/* FIXME: when adlib driver is in use, propagate that to
! 			 * the Scumm class, and let it create an AdlibSoundDriver
! 			 * instead of MidiSoundDriver */
  			if (md->id == -1) {
  				_use_adlib = true;
--- 204,209 ----
  		if (!scumm_stricmp(md->name, s)) {
  			/* FIXME: when adlib driver is in use, propagate that to
! 			 * the IMuse class, and let it create an IMuseAdlib driver
! 			 * instead of IMuseGM driver */
  			if (md->id == -1) {
  				_use_adlib = true;

Index: gameDetector.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gameDetector.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** gameDetector.h	13 Apr 2002 18:31:44 -0000	1.7
--- gameDetector.h	14 Apr 2002 18:13:07 -0000	1.8
***************
*** 35,38 ****
--- 35,41 ----
  	bool _use_adlib;
  
+ 	byte _music_volume;
+ 	bool _mt32emulate;
+ 
  	uint16 _debugMode;
  	uint16 _noSubtitles;
***************
*** 42,46 ****
  	char *_gameDataPath;
  	int _gameTempo;
- 	void *_soundEngine;
  	int _midi_driver;
  	char *_exe_name;
--- 45,48 ----

Index: gfx.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gfx.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** gfx.cpp	12 Apr 2002 21:26:34 -0000	1.63
--- gfx.cpp	14 Apr 2002 18:13:07 -0000	1.64
***************
*** 585,589 ****
  		//updateDirtyScreen(0);
  		/* XXX: EGA_proc4(0); */
! 		warning("EGA_proc4");				/* FIXME */
  		break;
  	case 134:
--- 585,589 ----
  		//updateDirtyScreen(0);
  		/* XXX: EGA_proc4(0); */
! //		warning("EGA_proc4");				/* FIXME */
  		break;
  	case 134:

Index: gui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** gui.cpp	13 Apr 2002 04:39:04 -0000	1.29
--- gui.cpp	14 Apr 2002 18:13:07 -0000	1.30
***************
*** 22,27 ****
--- 22,29 ----
  #include "stdafx.h"
  #include "scumm.h"
+ #include "mididrv.h"
  #include "gui.h"
  #include "guimaps.h"
+ #include "imuse.h"
  
  #ifdef _WIN32_WCE
***************
*** 485,494 ****
  	if (cmd == 40 || cmd == 50) {
  		if (cmd == 40) {
- 			SoundEngine *se = (SoundEngine *)_s->_soundEngine;
  			_s->_sound_volume_master = _gui_variables[0];	// Master
  			_s->_sound_volume_music = _gui_variables[1];	// Music
  			_s->_sound_volume_sfx = _gui_variables[2];	// SFX
! 			se->set_music_volume(_s->_sound_volume_music);
! 			se->set_master_volume(_s->_sound_volume_master);
  			registry_save();
  		}
--- 487,497 ----
  	if (cmd == 40 || cmd == 50) {
  		if (cmd == 40) {
  			_s->_sound_volume_master = _gui_variables[0];	// Master
  			_s->_sound_volume_music = _gui_variables[1];	// Music
  			_s->_sound_volume_sfx = _gui_variables[2];	// SFX
! 			
! 			IMuse *imuse = _s->_imuse;
! 			imuse->set_music_volume(_s->_sound_volume_music);
! 			imuse->set_master_volume(_s->_sound_volume_master);
  			registry_save();
  		}

Index: main.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/main.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** main.cpp	13 Apr 2002 18:31:44 -0000	1.3
--- main.cpp	14 Apr 2002 18:13:07 -0000	1.4
***************
*** 1,4 ****
--- 1,5 ----
  #include "stdafx.h"
  #include "scumm.h"
+ #include "mididrv.h"
  #include "gameDetector.h"
  #include "gui.h"
***************
*** 58,62 ****
  	{
  		char *s = detector.getGameName();
! 		system->set_param(OSystem::PARAM_WINDOW_CAPTION, (long)s);
  		free(s);
  	}
--- 59,63 ----
  	{
  		char *s = detector.getGameName();
! 		system->property(OSystem::PROP_SET_WINDOW_CAPTION, (long)s);
  		free(s);
  	}

Index: saveload.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saveload.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** saveload.cpp	11 Apr 2002 17:19:15 -0000	1.36
--- saveload.cpp	14 Apr 2002 18:13:07 -0000	1.37
***************
*** 23,26 ****
--- 23,28 ----
  #include "stdafx.h"
  #include "scumm.h"
+ #include "mididrv.h"
+ #include "imuse.h"
  
  #ifdef _WIN32_WCE
***************
*** 743,749 ****
  	}
  
! 	if (_soundEngine)
! 		((SoundEngine *)_soundEngine)->save_or_load(s);
! 
  }
  
--- 745,750 ----
  	}
  
! 	if (_imuse)
! 		_imuse->save_or_load(s, this);
  }
  

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm.h,v
retrieving revision 1.117
retrieving revision 1.118
diff -C2 -d -r1.117 -r1.118
*** scumm.h	13 Apr 2002 18:31:44 -0000	1.117
--- scumm.h	14 Apr 2002 18:13:07 -0000	1.118
***************
*** 22,25 ****
--- 22,26 ----
  #include "scummsys.h"
  #include "system.h"
+ #include "mixer.h"
  
  #ifdef COMPRESSED_SOUND_FILE
***************
*** 36,39 ****
--- 37,41 ----
  class Gui;
  class Scumm;
+ class IMuse;
  struct Actor;
  struct ScummDebugger;
***************
*** 550,554 ****
  #include "gfx.h"
  #include "boxes.h"
- #include "sound.h"
  #include "akos.h"
  #include "smush.h"
--- 552,555 ----
***************
*** 560,564 ****
  	 * on some architectures. */
  	OSystem *_system;
! 	void *_soundEngine;
  	Gui *_gui;
  	uint32 _features;
--- 561,565 ----
  	 * on some architectures. */
  	OSystem *_system;
! 	IMuse *_imuse;
  	Gui *_gui;
  	uint32 _features;
***************
*** 940,947 ****
  	void setVerbObject(uint room, uint object, uint verb);
  
- 
  	/* Should be in Sound class */
! 	MixerChannel _mixer_channel[NUM_MIXER];
! 	int _gameTempo;	
  	byte _sfxMode;
  	bool _use_adlib;
--- 941,948 ----
  	void setVerbObject(uint room, uint object, uint verb);
  
  	/* Should be in Sound class */
! 	SoundMixer _mixer[1];
! 
! //	MixerChannel _mixer_channel[NUM_MIXER];
  	byte _sfxMode;
  	bool _use_adlib;
***************
*** 983,993 ****
  
  	void pauseSounds(bool pause);
- 	MixerChannel *allocateMixer();
  	bool isSfxFinished();
  	void playBundleSound(char *sound);
  	void playSfxSound(void *sound, uint32 size, uint rate);
!   	void playSfxSound_MP3(void *sound, uint32 size);
  	void stopSfxSound();
- 	void mixWaves(int16 *sounds, int len);
  
  	bool _useTalkAnims;
--- 984,992 ----
  
  	void pauseSounds(bool pause);
  	bool isSfxFinished();
  	void playBundleSound(char *sound);
  	void playSfxSound(void *sound, uint32 size, uint rate);
!  	void playSfxSound_MP3(void *sound, uint32 size);
  	void stopSfxSound();
  
  	bool _useTalkAnims;
***************
*** 1683,1687 ****
  	void animateCursor();
  	void updatePalette();
- 	static void on_generate_samples(void *s, int16 *samples, int len);
  };
  
--- 1682,1685 ----
***************
*** 1798,1801 ****
--- 1796,1800 ----
  
  };
+ 
  
  extern const uint32 IMxx_tags[];

Index: scummvm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scummvm.cpp,v
retrieving revision 1.108
retrieving revision 1.109
diff -C2 -d -r1.108 -r1.109
*** scummvm.cpp	13 Apr 2002 18:31:44 -0000	1.108
--- scummvm.cpp	14 Apr 2002 18:13:07 -0000	1.109
***************
*** 23,26 ****
--- 23,28 ----
  #include "stdafx.h"
  #include "scumm.h"
+ #include "mididrv.h"
+ #include "imuse.h"
  #include "gui.h"
  #include "string.h"
***************
*** 1260,1267 ****
  }
  
- void Scumm::on_generate_samples(void *s, int16 *samples, int len) {
- 	((Scumm*)s)->mixWaves(samples, len);
- }
- 
  Scumm *Scumm::createFromDetector(GameDetector *detector, OSystem *syst)
  {
--- 1262,1265 ----
***************
*** 1282,1289 ****
  
  	/* This initializes SDL */
! 	syst->init_size(320,200, OSystem::SOUND_16BIT);
! 	syst->set_param(OSystem::PARAM_OPEN_CD, detector->_cdrom);
  
! 	syst->set_sound_proc(scumm, on_generate_samples);
  
  	scumm->_fullScreen = detector->_fullScreen;
--- 1280,1290 ----
  
  	/* This initializes SDL */
! 	syst->init_size(320,200);
! 	syst->property(OSystem::PROP_OPEN_CD, detector->_cdrom);
  
! 	/* 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);
  
  	scumm->_fullScreen = detector->_fullScreen;
***************
*** 1291,1296 ****
  	scumm->_bootParam = detector->_bootParam;
  	scumm->_gameDataPath = detector->_gameDataPath;
- 	scumm->_gameTempo = detector->_gameTempo;
- 	scumm->_soundEngine = detector->_soundEngine;
  	scumm->_exe_name = detector->_exe_name;
  	scumm->_gameId = detector->_gameId;
--- 1292,1295 ----
***************
*** 1302,1319 ****
  
  	{
! 		SoundDriver *sdriv;
! 		SoundEngine *seng;
  
  		scumm->_use_adlib = detector->_use_adlib;
! 		
! 		if (!detector->_use_adlib) {
! 			MidiDriver *midi = detector->createMidi();
! 			sdriv = new MidiSoundDriver;
! 			((MidiSoundDriver*)sdriv)->midiSetDriver(midi);
  		} else {
! 			sdriv = new AdlibSoundDriver;
  		}
! 		seng = new SoundEngine;
! 		seng->initialize(scumm, sdriv);
  	}
  
--- 1301,1319 ----
  
  	{
! 		IMuse *imuse;
  
  		scumm->_use_adlib = detector->_use_adlib;
! 
! 		if (detector->_use_adlib) {
! 			imuse = IMuse::create_adlib(syst, scumm->_mixer);
  		} else {
! 			imuse = IMuse::create_midi(syst, detector->createMidi());
  		}
! 		
! 		imuse->property(IMuse::PROP_MT32_EMULATE, detector->_mt32emulate);
! 		if (detector->_gameTempo != 0)
! 			imuse->property(IMuse::PROP_TEMPO_BASE, detector->_gameTempo);
! 					
! 		scumm->_imuse = imuse;
  	}
  

Index: scummvm.dsp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scummvm.dsp,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** scummvm.dsp	13 Apr 2002 18:31:44 -0000	1.36
--- scummvm.dsp	14 Apr 2002 18:13:07 -0000	1.37
***************
*** 122,146 ****
  # Begin Source File
  
! SOURCE=.\sound\adlib.cpp
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\fmopl.cpp
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\gmidi.cpp
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\gmidi.h
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\imuse.cpp
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\mididrv.cpp
  # End Source File
  # End Group
--- 122,150 ----
  # Begin Source File
  
! SOURCE=.\sound\fmopl.cpp
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\imuse.cpp
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\imuse.h
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\mididrv.cpp
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\mididrv.h
  # End Source File
  # Begin Source File
  
! SOURCE=.\sound\mixer.cpp
! # End Source File
! # Begin Source File
! 
! SOURCE=.\sound\mixer.h
  # End Source File
  # End Group
***************
*** 510,517 ****
  
  SOURCE=.\smush.h
- # End Source File
- # Begin Source File
- 
- SOURCE=.\sound.h
  # End Source File
  # Begin Source File
--- 514,517 ----

Index: sdl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sdl.cpp,v
retrieving revision 1.90
retrieving revision 1.91
diff -C2 -d -r1.90 -r1.91
*** sdl.cpp	13 Apr 2002 21:06:46 -0000	1.90
--- sdl.cpp	14 Apr 2002 18:13:07 -0000	1.91
***************
*** 1,4 ****
--- 1,5 ----
  #include "stdafx.h"
  #include "scumm.h"
+ #include "mididrv.h"
  #include "SDL_thread.h"
  #include "gameDetector.h"
***************
*** 17,21 ****
  	// Set the size of the video bitmap.
  	// Typically, 320x200
! 	void init_size(uint w, uint h, byte sound);
  
  	// Draw a bitmap to screen.
--- 18,22 ----
  	// Set the size of the video bitmap.
  	// Typically, 320x200
! 	void init_size(uint w, uint h);
  
  	// Draw a bitmap to screen.
***************
*** 52,56 ****
  	
  	// Set function that generates samples 
! 	void set_sound_proc(void *param, SoundProc *proc);
  		
  	// Quit
--- 53,57 ----
  	
  	// Set function that generates samples 
! 	void set_sound_proc(void *param, SoundProc *proc, byte sound);
  		
  	// Quit
***************
*** 58,62 ****
  
  	// Set a parameter
! 	uint32 set_param(int param, uint32 value);
  
  	static OSystem *create(int gfx_mode, bool full_screen);
--- 59,63 ----
  
  	// Set a parameter
! 	uint32 property(int param, uint32 value);
  
  	static OSystem *create(int gfx_mode, bool full_screen);
***************
*** 109,115 ****
  	int scaling;
  
- 	SoundProc *_sound_proc;
- 	void *_sound_param;
- 
  	struct MousePos {
  		int16 x,y,w,h;
--- 110,113 ----
***************
*** 198,209 ****
  }
  
- void OSystem_SDL::fill_sound(void *userdata, Uint8 * stream, int len) {
- 	OSystem_SDL *os = (OSystem_SDL*)userdata;
- 	if (os->_sound_proc)
- 		os->_sound_proc(os->_sound_param, (int16*)stream, len>>1);
- 	else
- 		memset(stream, 0x0, len);
- }
- 
  void OSystem_SDL::load_gfx_mode() {
  	force_full = true;
--- 196,199 ----
***************
*** 308,329 ****
  }
  
! void OSystem_SDL::init_size(uint w, uint h, byte sound) {
! 	SDL_AudioSpec desired;
! 
  	if (w != SCREEN_WIDTH && h != SCREEN_HEIGHT)
  		error("320x200 is the only game resolution supported");
  
- 	/* init sound */
- 	if (sound != SOUND_NONE) {
- 		desired.freq = SAMPLES_PER_SEC;
- 		desired.format = sound==SOUND_8BIT ? AUDIO_U8 : AUDIO_S16SYS;
- 		desired.channels = 1;
- 		desired.samples = 2048;
- 		desired.callback = fill_sound;
- 		desired.userdata = this;
- 		SDL_OpenAudio(&desired, NULL);
- 		SDL_PauseAudio(0);
- 	}
- 
  	/* allocate palette, it needs to be persistent across
  	 * driver changes, so i'll alloc it here */
--- 298,305 ----
  }
  
! void OSystem_SDL::init_size(uint w, uint h) {
  	if (w != SCREEN_WIDTH && h != SCREEN_HEIGHT)
  		error("320x200 is the only game resolution supported");
  
  	/* allocate palette, it needs to be persistent across
  	 * driver changes, so i'll alloc it here */
***************
*** 669,673 ****
  				/* internal keypress? */				
  				if (b == KBD_ALT && ev.key.keysym.sym==SDLK_RETURN) {
! 					set_param(PARAM_TOGGLE_FULLSCREEN, 0);
  					break;
  				}
--- 645,649 ----
  				/* internal keypress? */				
  				if (b == KBD_ALT && ev.key.keysym.sym==SDLK_RETURN) {
! 					property(PROP_TOGGLE_FULLSCREEN, 0);
  					break;
  				}
***************
*** 680,684 ****
  				if (b == (KBD_CTRL|KBD_ALT) && 
  						ev.key.keysym.sym>='1' && ev.key.keysym.sym<='6') {
! 					set_param(PARAM_HOTSWAP_GFX_MODE, ev.key.keysym.sym - '1');
  					break;
  				}
--- 656,660 ----
  				if (b == (KBD_CTRL|KBD_ALT) && 
  						ev.key.keysym.sym>='1' && ev.key.keysym.sym<='6') {
! 					property(PROP_SET_GFX_MODE, ev.key.keysym.sym - '1');
  					break;
  				}
***************
*** 734,740 ****
  }
  	
! void OSystem_SDL::set_sound_proc(void *param, SoundProc *proc) {
! 	_sound_proc = proc;	
! 	_sound_param = param;
  }
  
--- 710,726 ----
  }
  	
! void OSystem_SDL::set_sound_proc(void *param, SoundProc *proc, byte format) {
! 	SDL_AudioSpec desired;
! 
! 	/* only one format supported at the moment */
! 
! 	desired.freq = SAMPLES_PER_SEC;
! 	desired.format = AUDIO_S16SYS;
! 	desired.channels = 1;
! 	desired.samples = 2048;
! 	desired.callback = proc;
! 	desired.userdata = param;
! 	SDL_OpenAudio(&desired, NULL);
! 	SDL_PauseAudio(0);
  }
  
***************
*** 807,814 ****
  }
  
! uint32 OSystem_SDL::set_param(int param, uint32 value) {
  	switch(param) {
  
! 	case PARAM_TOGGLE_FULLSCREEN:
  		_full_screen ^= true;
  		
--- 793,800 ----
  }
  
! uint32 OSystem_SDL::property(int param, uint32 value) {
  	switch(param) {
  
! 	case PROP_TOGGLE_FULLSCREEN:
  		_full_screen ^= true;
  		
***************
*** 819,827 ****
  		return 1;
  
! 	case PARAM_WINDOW_CAPTION:
  		SDL_WM_SetCaption((char*)value, (char*)value);
  		return 1;
  
! 	case PARAM_OPEN_CD:
  		if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
  			cdrom = NULL;
--- 805,813 ----
  		return 1;
  
! 	case PROP_SET_WINDOW_CAPTION:
  		SDL_WM_SetCaption((char*)value, (char*)value);
  		return 1;
  
! 	case PROP_OPEN_CD:
  		if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
  			cdrom = NULL;
***************
*** 835,839 ****
  		break;
  
! 	case PARAM_HOTSWAP_GFX_MODE:
  		if (value >= 6)
  			return 0;
--- 821,825 ----
  		break;
  
! 	case PROP_SET_GFX_MODE:
  		if (value >= 6)
  			return 0;
***************
*** 844,850 ****
  		return 1;
  
! 	case PARAM_SHOW_DEFAULT_CURSOR:
  		SDL_ShowCursor(value ? SDL_ENABLE : SDL_DISABLE);		
  		break;
  	}
  
--- 830,839 ----
  		return 1;
  
! 	case PROP_SHOW_DEFAULT_CURSOR:
  		SDL_ShowCursor(value ? SDL_ENABLE : SDL_DISABLE);		
  		break;
+ 
+ 	case PROP_GET_SAMPLE_RATE:
+ 		return SAMPLES_PER_SEC;
  	}
  
***************
*** 1028,1032 ****
  public:
  	void set_palette(const byte *colors, uint start, uint num) {}
! 	void init_size(uint w, uint h, byte sound);
  	void copy_rect(const byte *buf, int pitch, int x, int y, int w, int h) {}
  	void update_screen() {}
--- 1017,1021 ----
  public:
  	void set_palette(const byte *colors, uint start, uint num) {}
! 	void init_size(uint w, uint h);
  	void copy_rect(const byte *buf, int pitch, int x, int y, int w, int h) {}
  	void update_screen() {}
***************
*** 1039,1045 ****
  	void *create_thread(ThreadProc *proc, void *param) { return NULL; }
  	bool poll_event(Event *event) { return false; }
! 	void set_sound_proc(void *param, SoundProc *proc) {}
  	void quit() { exit(1); }
! 	uint32 set_param(int param, uint32 value) { return 0; }
  	static OSystem *create(int gfx_mode, bool full_screen);
  private:
--- 1028,1034 ----
  	void *create_thread(ThreadProc *proc, void *param) { return NULL; }
  	bool poll_event(Event *event) { return false; }
! 	void set_sound_proc(void *param, SoundProc *proc, byte sound) {}
  	void quit() { exit(1); }
! 	uint32 property(int param, uint32 value) { return 0; }
  	static OSystem *create(int gfx_mode, bool full_screen);
  private:

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** sound.cpp	13 Apr 2002 18:31:44 -0000	1.40
--- sound.cpp	14 Apr 2002 18:13:07 -0000	1.41
***************
*** 23,26 ****
--- 23,28 ----
  #include "stdafx.h"
  #include "scumm.h"
+ #include "mididrv.h"
+ #include "imuse.h"
  #include "cdmusic.h"
  
***************
*** 55,59 ****
  	int num;
  	int16 data[16];
! 	SoundEngine *se;
  
  	processSfxQueues();
--- 57,61 ----
  	int num;
  	int16 data[16];
! 	IMuse *se;
  
  	processSfxQueues();
***************
*** 78,82 ****
  			i += num;
  
! 			se = (SoundEngine *)_soundEngine;
  #if 0
  			debug(1, "processSoundQues(%d,%d,%d,%d,%d,%d,%d,%d,%d)",
--- 80,84 ----
  			i += num;
  
! 			se = _imuse;
  #if 0
  			debug(1, "processSoundQues(%d,%d,%d,%d,%d,%d,%d,%d,%d)",
***************
*** 101,105 ****
  {
  	byte *ptr;
! 	SoundEngine *se = (SoundEngine *)_soundEngine;
  
  	ptr = getResourceAddress(rtSound, sound);
--- 103,107 ----
  {
  	byte *ptr;
! 	IMuse *se = _imuse;
  
  	ptr = getResourceAddress(rtSound, sound);
***************
*** 254,258 ****
  int Scumm::isSoundRunning(int sound)
  {
! 	SoundEngine *se;
  	int i;
  
--- 256,260 ----
  int Scumm::isSoundRunning(int sound)
  {
! 	IMuse *se;
  	int i;
  
***************
*** 272,276 ****
  		return 0;
  
! 	se = (SoundEngine *)_soundEngine;
  	if (!se)
  		return 0;
--- 274,278 ----
  		return 0;
  
! 	se = _imuse;
  	if (!se)
  		return 0;
***************
*** 301,305 ****
  void Scumm::stopSound(int a)
  {
! 	SoundEngine *se;
  	int i;
  
--- 303,307 ----
  void Scumm::stopSound(int a)
  {
! 	IMuse *se;
  	int i;
  
***************
*** 309,313 ****
  	}
  
! 	se = (SoundEngine *)_soundEngine;
  	if (se)
  		se->stop_sound(a);
--- 311,315 ----
  	}
  
! 	se = _imuse;
  	if (se)
  		se->stop_sound(a);
***************
*** 320,324 ****
  void Scumm::stopAllSounds()
  {
! 	SoundEngine *se = (SoundEngine *)_soundEngine;
  
  	if (current_cd_sound != 0) {
--- 322,326 ----
  void Scumm::stopAllSounds()
  {
! 	IMuse *se = _imuse;
  
  	if (current_cd_sound != 0) {
***************
*** 377,381 ****
  void Scumm::setupSound()
  {
! 	SoundEngine *se = (SoundEngine *)_soundEngine;
  	if (se) {
  		se->setBase(res.address[rtSound]);
--- 379,383 ----
  void Scumm::setupSound()
  {
! 	IMuse *se = _imuse;
  	if (se) {
  		se->setBase(res.address[rtSound]);
***************
*** 393,397 ****
  void Scumm::pauseSounds(bool pause)
  {
! 	SoundEngine *se = (SoundEngine *)_soundEngine;
  	if (se)
  		se->pause(pause);
--- 395,399 ----
  void Scumm::pauseSounds(bool pause)
  {
! 	IMuse *se = _imuse;
  	if (se)
  		se->pause(pause);
***************
*** 563,585 ****
  }
  
- 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();
! 	}
  }
  
--- 565,571 ----
  }
  
  void Scumm::stopSfxSound()
  {
! 	_mixer->stop_all();
  }
  
***************
*** 587,644 ****
  bool Scumm::isSfxFinished()
  {
! 	int i;
! 	for (i = 0; i < NUM_MIXER; i++)
! 		if (_mixer_channel[i]._sfx_sound)
! 			return false;
! 	return true;
! }
! 
! #ifdef COMPRESSED_SOUND_FILE
! void Scumm::playSfxSound_MP3(void *sound, uint32 size)
! {
! 	MixerChannel *mc = allocateMixer();
! 
! 	if (!mc) {
! 		warning("No mixer channel available");
! 		return;
! 	}
! 
! 	mc->type = MIXER_MP3;
! 	mc->_sfx_sound = sound;
! 
! 	mad_stream_init(&mc->sound_data.mp3.stream);
! 
! 
! 
! #ifdef _WIN32_WCE
! 
! 	// 11 kHz on WinCE
! 
! 	mad_stream_options((mad_stream *) & mc->sound_data.mp3.stream,
! 										 MAD_OPTION_HALFSAMPLERATE);
! 
! #endif
! 
! 
! 	mad_frame_init(&mc->sound_data.mp3.frame);
! 	mad_synth_init(&mc->sound_data.mp3.synth);
! 	mc->sound_data.mp3.position = 0;
! 	mc->sound_data.mp3.pos_in_frame = 0xFFFFFFFF;
! 	mc->sound_data.mp3.size = size;
! 	/* This variable is the number of samples to cut at the start of the MP3
! 	   file. This is needed to have lip-sync as the MP3 file have some miliseconds
! 	   of blank at the start (as, I suppose, the MP3 compression algorithm need to
! 	   have some silence at the start to really be efficient and to not distort
! 	   too much the start of the sample).
! 
! 	   This value was found by experimenting out. If you recompress differently your
! 	   .SO3 file, you may have to change this value.
! 
! 	   When using Lame, it seems that the sound starts to have some volume about 50 ms
! 	   from the start of the sound => we skip about 1024 samples.
! 	 */
! 	mc->sound_data.mp3.silence_cut = 1024;
  }
- #endif
  
  void Scumm::playBundleSound(char *sound)
--- 573,578 ----
  bool Scumm::isSfxFinished()
  {
! 	return !_mixer->has_active_channel();
  }
  
  void Scumm::playBundleSound(char *sound)
***************
*** 649,951 ****
  void Scumm::playSfxSound(void *sound, uint32 size, uint rate)
  {
! 	MixerChannel *mc = allocateMixer();
! 
! 	if (!mc) {
! 		warning("No mixer channel available");
! 		return;
! 	}
! 
! 	mc->type = MIXER_STANDARD;
! 	mc->_sfx_sound = sound;
! 	mc->sound_data.standard._sfx_pos = 0;
! 	mc->sound_data.standard._sfx_fp_pos = 0;
! 
! #ifdef _WIN32_WCE
! 	mc->sound_data.standard._sfx_fp_speed = (1 << 16) * rate / 11025;
! #else
! 	mc->sound_data.standard._sfx_fp_speed = (1 << 16) * rate / 22050;
! #endif
! 	while (size & 0xFFFF0000)
! 		size >>= 1, rate >>= 1;
! 
! 
! #ifdef _WIN32_WCE
! 	mc->sound_data.standard._sfx_size = size * 11025 / rate;
! #else
! 	mc->sound_data.standard._sfx_size = size * 22050 / rate;
! #endif
! }
! 
! #ifdef COMPRESSED_SOUND_FILE
! static inline int scale_sample(mad_fixed_t sample)
! {
! 	/* round */
! 	sample += (1L << (MAD_F_FRACBITS - 16));
! 
! 	/* clip */
! 	if (sample >= MAD_F_ONE)
! 		sample = MAD_F_ONE - 1;
! 	else if (sample < -MAD_F_ONE)
! 		sample = -MAD_F_ONE;
! 
! 	/* quantize and scale to not saturate when mixing a lot of channels */
! 	return sample >> (MAD_F_FRACBITS + 2 - 16);
! }
! #endif
! 
! void MixerChannel::mix(int16 * data, uint32 len)
! {
! 	if (!_sfx_sound)
! 		return;
! 
! #ifdef COMPRESSED_SOUND_FILE
! 	if (type == MIXER_STANDARD) {
! #endif
! 		int8 *s;
! 		uint32 fp_pos, fp_speed;
! 
! 		if (len > sound_data.standard._sfx_size)
! 			len = sound_data.standard._sfx_size;
! 		sound_data.standard._sfx_size -= len;
! 
! 		s = (int8 *) _sfx_sound + sound_data.standard._sfx_pos;
! 		fp_pos = sound_data.standard._sfx_fp_pos;
! 		fp_speed = sound_data.standard._sfx_fp_speed;
! 
! 		do {
! 			fp_pos += fp_speed;
! 			*data++ += (*s << 6);
! 			s += fp_pos >> 16;
! 			fp_pos &= 0x0000FFFF;
! 		} while (--len);
! 
! 		sound_data.standard._sfx_pos = s - (int8 *) _sfx_sound;
! 		sound_data.standard._sfx_fp_speed = fp_speed;
! 		sound_data.standard._sfx_fp_pos = fp_pos;
! 
! 		if (!sound_data.standard._sfx_size)
! 			clear();
! #ifdef COMPRESSED_SOUND_FILE
! 	} else {
! 		if (type == MIXER_MP3) {
! 			mad_fixed_t const *ch;
! 			while (1) {
! 				ch =
! 					sound_data.mp3.synth.pcm.samples[0] + sound_data.mp3.pos_in_frame;
! 				while ((sound_data.mp3.pos_in_frame < sound_data.mp3.synth.pcm.length)
! 							 && (len > 0)) {
! 					if (sound_data.mp3.silence_cut > 0) {
! 						sound_data.mp3.silence_cut--;
! 					} else {
! 						*data++ += scale_sample(*ch++);
! 						len--;
! 					}
! 					sound_data.mp3.pos_in_frame++;
! 				}
! 				if (len == 0)
! 					return;
! 
! 				if (sound_data.mp3.position >= sound_data.mp3.size) {
! 					clear();
! 					return;
! 				}
! 
! 				mad_stream_buffer(&sound_data.mp3.stream,
! 													((unsigned char *)_sfx_sound) +
! 													sound_data.mp3.position,
! 													sound_data.mp3.size + MAD_BUFFER_GUARD -
! 													sound_data.mp3.position);
! 
! 				if (mad_frame_decode(&sound_data.mp3.frame, &sound_data.mp3.stream) ==
! 						-1) {
! 					/* End of audio... */
! 					if (sound_data.mp3.stream.error == MAD_ERROR_BUFLEN) {
! 						clear();
! 						return;
! 					} else if (!MAD_RECOVERABLE(sound_data.mp3.stream.error)) {
! 						error("MAD frame decode error !");
! 					}
! 				}
! 				mad_synth_frame(&sound_data.mp3.synth, &sound_data.mp3.frame);
! 				sound_data.mp3.pos_in_frame = 0;
! 				sound_data.mp3.position =
! 					(unsigned char *)sound_data.mp3.stream.next_frame -
! 					(unsigned char *)_sfx_sound;
! 			}
! 		} else if (type == MIXER_MP3_CDMUSIC) {
! 			mad_fixed_t const *ch;
! 			mad_timer_t frame_duration;
! 			static long last_pos = 0;
! 
! 			if (!sound_data.mp3_cdmusic.playing)
! 				return;
! 
! 			while (1) {
! 
! 				// See if we just skipped
! 				if (ftell(sound_data.mp3_cdmusic.file) != last_pos) {
! 					int skip_loop;
! 
! 					// Read the new data
! 					memset(_sfx_sound, 0,
! 								 sound_data.mp3_cdmusic.buffer_size + MAD_BUFFER_GUARD);
! 					sound_data.mp3_cdmusic.size =
! 						fread(_sfx_sound, 1, sound_data.mp3_cdmusic.buffer_size,
! 									sound_data.mp3_cdmusic.file);
! 					if (!sound_data.mp3_cdmusic.size) {
! 						sound_data.mp3_cdmusic.playing = false;
! 						return;
! 					}
! 					last_pos = ftell(sound_data.mp3_cdmusic.file);
! 					// Resync
! 					mad_stream_buffer(&sound_data.mp3_cdmusic.stream,
! 														(unsigned char *)_sfx_sound,
! 														sound_data.mp3_cdmusic.size);
! 					skip_loop = 2;
! 					while (skip_loop != 0) {
! 						if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
! 																 &sound_data.mp3_cdmusic.stream) == 0) {
! 							/* Do not decrease duration - see if it's a problem */
! 							skip_loop--;
! 							if (skip_loop == 0) {
! 								mad_synth_frame(&sound_data.mp3_cdmusic.synth,
! 																&sound_data.mp3_cdmusic.frame);
! 							}
! 						} else {
! 							if (!MAD_RECOVERABLE(sound_data.mp3_cdmusic.stream.error)) {
! 								debug(1, "Unrecoverable error while skipping !");
! 								sound_data.mp3_cdmusic.playing = false;
! 								return;
! 							}
! 						}
! 					}
! 					// We are supposed to be in synch
! 					mad_frame_mute(&sound_data.mp3_cdmusic.frame);
! 					mad_synth_mute(&sound_data.mp3_cdmusic.synth);
! 					// Resume decoding
! 					if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
! 															 &sound_data.mp3_cdmusic.stream) == 0) {
! 						sound_data.mp3_cdmusic.position =
! 							(unsigned char *)sound_data.mp3_cdmusic.stream.next_frame -
! 							(unsigned char *)_sfx_sound;
! 						sound_data.mp3_cdmusic.pos_in_frame = 0;
! 					} else {
! 						sound_data.mp3_cdmusic.playing = false;
! 						return;
! 					}
! 				}
! 				// Get samples, play samples ... 
! 
! 				ch = sound_data.mp3_cdmusic.synth.pcm.samples[0] +
! 					sound_data.mp3_cdmusic.pos_in_frame;
! 				while ((sound_data.mp3_cdmusic.pos_in_frame <
! 								sound_data.mp3_cdmusic.synth.pcm.length) && (len > 0)) {
! 					*data++ += scale_sample(*ch++);
! 					len--;
! 					sound_data.mp3_cdmusic.pos_in_frame++;
! 				}
! 				if (len == 0) {
! 					return;
! 				}
! 				// See if we have finished
! 				// May be incorrect to check the size at the end of a frame but I suppose
! 				// they are short enough :)   
! 
! 				frame_duration = sound_data.mp3_cdmusic.frame.header.duration;
! 
! 				mad_timer_negate(&frame_duration);
! 				mad_timer_add(&sound_data.mp3_cdmusic.duration, frame_duration);
! 				if (mad_timer_compare(sound_data.mp3_cdmusic.duration, mad_timer_zero)
! 						< 0) {
! 					sound_data.mp3_cdmusic.playing = false;
! 				}
! 
! 				if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
! 														 &sound_data.mp3_cdmusic.stream) == -1) {
! 
! 					if (sound_data.mp3_cdmusic.stream.error == MAD_ERROR_BUFLEN) {
! 						int not_decoded;
! 
! 						if (!sound_data.mp3_cdmusic.stream.next_frame) {
! 							memset(_sfx_sound, 0,
! 										 sound_data.mp3_cdmusic.buffer_size + MAD_BUFFER_GUARD);
! 							sound_data.mp3_cdmusic.size =
! 								fread(_sfx_sound, 1, sound_data.mp3_cdmusic.buffer_size,
! 											sound_data.mp3_cdmusic.file);
! 							sound_data.mp3_cdmusic.position = 0;
! 							not_decoded = 0;
! 						} else {
! 							not_decoded = sound_data.mp3_cdmusic.stream.bufend -
! 								sound_data.mp3_cdmusic.stream.next_frame;
! 							memcpy(_sfx_sound, sound_data.mp3_cdmusic.stream.next_frame,
! 										 not_decoded);
! 
! 							sound_data.mp3_cdmusic.size =
! 								fread((unsigned char *)_sfx_sound + not_decoded, 1,
! 											sound_data.mp3_cdmusic.buffer_size - not_decoded,
! 											sound_data.mp3_cdmusic.file);
! 						}
! 						last_pos = ftell(sound_data.mp3_cdmusic.file);
! 						sound_data.mp3_cdmusic.stream.error = MAD_ERROR_NONE;
! 						// Restream
! 						mad_stream_buffer(&sound_data.mp3_cdmusic.stream,
! 															(unsigned char *)_sfx_sound,
! 															sound_data.mp3_cdmusic.size + not_decoded);
! 						if (mad_frame_decode
! 								(&sound_data.mp3_cdmusic.frame,
! 								 &sound_data.mp3_cdmusic.stream) == -1) {
! 							debug(1, "Error decoding after restream %d !",
! 										sound_data.mp3.stream.error);
! 						}
! 					} else if (!MAD_RECOVERABLE(sound_data.mp3.stream.error)) {
! 						error("MAD frame decode error in MP3 CDMUSIC !");
! 					}
! 				}
! 
! 				mad_synth_frame(&sound_data.mp3_cdmusic.synth,
! 												&sound_data.mp3_cdmusic.frame);
! 				sound_data.mp3_cdmusic.pos_in_frame = 0;
! 				sound_data.mp3_cdmusic.position =
! 					(unsigned char *)sound_data.mp3_cdmusic.stream.next_frame -
! 					(unsigned char *)_sfx_sound;
! 			}
! 		}
! 	}
! #endif
! }
! 
! void MixerChannel::clear()
! {
! 	free(_sfx_sound);
! 	_sfx_sound = NULL;
! 
! #ifdef COMPRESSED_SOUND_FILE
! 	if (type == MIXER_MP3) {
! 		mad_synth_finish(&sound_data.mp3.synth);
! 		mad_frame_finish(&sound_data.mp3.frame);
! 		mad_stream_finish(&sound_data.mp3.stream);
! 	}
! #endif
  }
  
- void Scumm::mixWaves(int16 * sounds, int len)
- {
- 	int i;
- 
- 	memset(sounds, 0, len * sizeof(int16));
- 
- 	if (_soundsPaused)
- 		return;
- 
- 	SoundEngine *se = (SoundEngine *)_soundEngine;
- 	if (se) {
- 		se->driver()->generate_samples(sounds, len);
- 	}
  
- 	for (i = NUM_MIXER - 1; i >= 0; i--) {
- 		_mixer_channel[i].mix(sounds, len);
- 	}
  
- 	if (_soundsPaused2)
- 		memset(sounds, 0x0, len * sizeof(int16));
- }
--- 583,589 ----
  void Scumm::playSfxSound(void *sound, uint32 size, uint rate)
  {
! 	_mixer->play_raw(NULL, sound, size, rate, SoundMixer::FLAG_AUTOFREE);
  }
  
  
  

Index: system.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/system.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** system.h	13 Apr 2002 21:06:47 -0000	1.5
--- system.h	14 Apr 2002 18:13:07 -0000	1.6
***************
*** 4,8 ****
  public:
  	typedef int ThreadProc(void *param);
! 	typedef void SoundProc(void *param, int16 *buf, int len);
  
  	struct Event {
--- 4,8 ----
  public:
  	typedef int ThreadProc(void *param);
! 	typedef void SoundProc(void *param, byte *buf, int len);
  
  	struct Event {
***************
*** 35,49 ****
  
  	enum {
! 		PARAM_TOGGLE_FULLSCREEN = 1,
! 		PARAM_WINDOW_CAPTION = 2,
! 		PARAM_OPEN_CD = 3,
! 		PARAM_HOTSWAP_GFX_MODE = 4,
! 		PARAM_SHOW_DEFAULT_CURSOR = 5,
  	};
  
  	enum {
! 		SOUND_NONE = 0,
! 		SOUND_8BIT = 1,
! 		SOUND_16BIT = 2,
  	};
  	
--- 35,49 ----
  
  	enum {
! 		PROP_TOGGLE_FULLSCREEN = 1,
! 		PROP_SET_WINDOW_CAPTION = 2,
! 		PROP_OPEN_CD = 3,
! 		PROP_SET_GFX_MODE = 4,
! 		PROP_SHOW_DEFAULT_CURSOR = 5,
! 		PROP_GET_SAMPLE_RATE = 6,
  	};
  
  	enum {
! 		SOUND_8BIT = 0,
! 		SOUND_16BIT = 1,
  	};
  	
***************
*** 53,57 ****
  	// Set the size of the video bitmap.
  	// Typically, 320x200
! 	virtual void init_size(uint w, uint h, byte sound) = 0;
  
  	// Draw a bitmap to screen.
--- 53,57 ----
  	// Set the size of the video bitmap.
  	// Typically, 320x200
! 	virtual void init_size(uint w, uint h) = 0;
  
  	// Draw a bitmap to screen.
***************
*** 88,94 ****
  
  	// Set the function to be invoked whenever samples need to be generated
! 	virtual void set_sound_proc(void *param, SoundProc *proc) = 0;
  	
! 	virtual uint32 set_param(int param, uint32 value) = 0;
  		
  	// Quit
--- 88,97 ----
  
  	// Set the function to be invoked whenever samples need to be generated
! 	// Format is the sample type format.
! 	// Only 16-bit signed mode is needed for simon & scumm
! 	virtual void set_sound_proc(void *param, SoundProc *proc, byte format) = 0;
  	
! 	// Get or set a property
! 	virtual uint32 property(int param, uint32 value) = 0;
  		
  	// Quit

Index: windows.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/windows.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** windows.cpp	12 Apr 2002 21:26:34 -0000	1.33
--- windows.cpp	14 Apr 2002 18:13:07 -0000	1.34
***************
*** 23,27 ****
  
  #include "scumm.h"
- #include "sound.h"
  #include "cdmusic.h"
  #include "gui.h"
--- 23,26 ----
***************
*** 109,113 ****
  ScummDebugger debugger;
  Gui gui;
! SoundEngine sound;
  SOUND_DRIVER_TYPE snd_driv;
  
--- 108,112 ----
  ScummDebugger debugger;
  Gui gui;
! IMuse sound;
  SOUND_DRIVER_TYPE snd_driv;
  

Index: x11.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/x11.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** x11.cpp	12 Apr 2002 21:26:34 -0000	1.11
--- x11.cpp	14 Apr 2002 18:13:07 -0000	1.12
***************
*** 25,29 ****
  #include "scumm.h"
  #include "gui.h"
- #include "sound.h"
  #include "cdmusic.h"
  #include "mp3_cd.h"
--- 25,28 ----
***************
*** 51,55 ****
  ScummDebugger debugger;
  Gui gui;
! SoundEngine sound;
  SOUND_DRIVER_TYPE snd_driv;
  static unsigned char *local_fb;
--- 50,54 ----
  ScummDebugger debugger;
  Gui gui;
! IMuse sound;
  SOUND_DRIVER_TYPE snd_driv;
  static unsigned char *local_fb;

--- sound.h DELETED ---





More information about the Scummvm-git-logs mailing list