[Scummvm-cvs-logs] CVS: residual driver.h,1.18,1.19 driver_sdl.h,1.1,1.2 driver_sdl.cpp,1.1,1.2

Marcus Comstedt marcus_c at users.sourceforge.net
Sun Feb 5 09:49:02 CET 2006


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6094

Modified Files:
	driver.h driver_sdl.h driver_sdl.cpp 
Log Message:
SDL sound code moved to DriverSDL.

Index: driver.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- driver.h	5 Feb 2006 17:19:44 -0000	1.18
+++ driver.h	5 Feb 2006 17:48:19 -0000	1.19
@@ -136,6 +136,36 @@
 
 	//@}
 
+	/** @name Sound */
+	//@{
+	typedef void (*SoundProc)(void *param, byte *buf, int len);
+
+	/**
+	 * Set the audio callback which is invoked whenever samples need to be generated.
+	 * Currently, only the 16-bit signed mode is ever used for GF
+	 * @param proc		pointer to the callback.
+	 * @param param		an arbitrary parameter which is stored and passed to proc.
+	 */
+	virtual bool setSoundCallback(SoundProc proc, void *param) = 0;
+
+	/**
+	 * Remove any audio callback previously set via setSoundCallback, thus effectively
+	 * stopping all audio output immediately.
+	 * @see setSoundCallback
+	 */
+	virtual void clearSoundCallback() = 0;
+
+	/**
+	 * Determine the output sample rate. Audio data provided by the sound
+	 * callback will be played using this rate.
+	 * @note Client code other than the sound mixer should _not_ use this
+	 *       method. Instead, call Mixer::getOutputRate()!
+	 * @return the output sample rate
+	 */
+	virtual int getOutputSampleRate() const = 0;
+
+	//@}
+
 protected:
 	int _screenWidth, _screenHeight, _screenBPP;
 	bool _isFullscreen;

Index: driver_sdl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_sdl.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- driver_sdl.h	5 Feb 2006 17:19:44 -0000	1.1
+++ driver_sdl.h	5 Feb 2006 17:48:19 -0000	1.2
@@ -33,12 +33,19 @@
 
 class DriverSDL : public Driver {
 public:
-	DriverSDL() { ; }
+	DriverSDL() : _samplesPerSec(22050) { ; }
 	virtual ~DriverSDL() { ; }
 
 	uint32 getMillis();
 	void delayMillis(uint msecs);
 	void setTimerCallback(TimerProc callback, int interval);
+
+	bool setSoundCallback(SoundProc proc, void *param);
+	void clearSoundCallback();
+	int getOutputSampleRate() const;
+
+private:
+	int _samplesPerSec;
 };
 
 #endif

Index: driver_sdl.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_sdl.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- driver_sdl.cpp	5 Feb 2006 17:19:44 -0000	1.1
+++ driver_sdl.cpp	5 Feb 2006 17:48:19 -0000	1.2
@@ -33,3 +33,31 @@
 	SDL_SetTimer(timer, (SDL_TimerCallback) callback);
 }
 
+bool DriverSDL::setSoundCallback(SoundProc proc, void *param) {
+	SDL_AudioSpec desired;
+
+	memset(&desired, 0, sizeof(desired));
+
+	desired.freq = 22050;
+	desired.format = AUDIO_S16SYS;
+	desired.channels = 2;
+	desired.samples = 2048;
+	desired.callback = proc;
+	desired.userdata = param;
+
+	if (SDL_OpenAudio(&desired, NULL) != 0) {
+		return false;
+	}
+
+	SDL_PauseAudio(0);
+	return true;
+}
+
+void DriverSDL::clearSoundCallback() {
+	SDL_CloseAudio();
+}
+
+int DriverSDL::getOutputSampleRate() const {
+	return _samplesPerSec;
+}
+





More information about the Scummvm-git-logs mailing list