Smaxx's patch fixing openal sound issues with poor card drivers
authorkoda
Tue, 22 Sep 2009 21:58:08 +0000
changeset 2392 a55dbef5cf31
parent 2391 f7d15d9d643c
child 2393 068632066f80
Smaxx's patch fixing openal sound issues with poor card drivers
QTfrontend/SDLs.cpp
QTfrontend/SDLs.h
QTfrontend/game.cpp
QTfrontend/gameuiconfig.cpp
QTfrontend/gameuiconfig.h
QTfrontend/hwform.cpp
QTfrontend/pages.cpp
QTfrontend/pages.h
hedgewars/hwengine.pas
hedgewars/uMisc.pas
hedgewars/uSound.pas
openalbridge/openalbridge.c
openalbridge/openalbridge.h
--- a/QTfrontend/SDLs.cpp	Tue Sep 22 21:00:39 2009 +0000
+++ b/QTfrontend/SDLs.cpp	Tue Sep 22 21:58:08 2009 +0000
@@ -56,15 +56,16 @@
 	return result;
 }
 
-void SDLInteraction::StartMusic()
+void SDLInteraction::StartMusic(bool hardware)
 {
 	if (music < 0) {
-	    openal_init(5);
+		openal_init(hardware ? 1 : 0, 5);
 		music = openal_loadfile(QString(datadir->absolutePath() + "/Music/main theme.ogg").toLocal8Bit().constData());
 		openal_toggleloop(music);
+	
 	}
 	openal_setvolume(music, 60);
-	openal_fadein(music, 25);
+	openal_fadein(music, 30);
 }
 
 void SDLInteraction::StopMusic()
--- a/QTfrontend/SDLs.h	Tue Sep 22 21:00:39 2009 +0000
+++ b/QTfrontend/SDLs.h	Tue Sep 22 21:58:08 2009 +0000
@@ -21,7 +21,7 @@
 
 #include <QStringList>
 
-extern "C" bool openal_init		(unsigned int memorysize);
+extern "C" bool openal_init		(unsigned int usehardware, unsigned int memorysize);
 extern "C" bool openal_close		(void);
 extern "C" bool openal_ready		(void);
 extern "C" int  openal_loadfile		(const char *filename);
@@ -47,7 +47,7 @@
 	SDLInteraction();
 	~SDLInteraction();
 	QStringList getResolutions() const;
-	void StartMusic();
+	void StartMusic(bool);
 	void StopMusic();
 };
 
--- a/QTfrontend/game.cpp	Tue Sep 22 21:00:39 2009 +0000
+++ b/QTfrontend/game.cpp	Tue Sep 22 21:58:08 2009 +0000
@@ -276,6 +276,7 @@
 	arguments << QString("%1").arg(ipc_port);
 	arguments << (config->vid_Fullscreen() ? "1" : "0");
 	arguments << (config->isSoundEnabled() ? "1" : "0");
+	arguments << (config->isSoundHardware() ? "1" : "0");
 	arguments << tr("en.txt");
 	arguments << QString::number(config->volume()); // sound volume
 	arguments << QString::number(config->timerInterval());
--- a/QTfrontend/gameuiconfig.cpp	Tue Sep 22 21:00:39 2009 +0000
+++ b/QTfrontend/gameuiconfig.cpp	Tue Sep 22 21:58:08 2009 +0000
@@ -48,6 +48,7 @@
 	Form->ui.pageOptions->CBReduceQuality->setChecked(value("video/reducequality", false).toBool());
 	Form->ui.pageOptions->CBFrontendEffects->setChecked(frontendEffects);
 	Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
+	Form->ui.pageOptions->CBHardwareSound->setChecked(value("audio/hardware", false).toBool());
 	Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool());
 	Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt());
 
@@ -120,6 +121,7 @@
 	}
 
 	setValue("audio/sound", isSoundEnabled());
+	setValue("audio/hardware", isSoundHardware());
 	setValue("audio/music", isMusicEnabled());
 	setValue("audio/volume", Form->ui.pageOptions->volumeBox->value());
 
@@ -177,6 +179,11 @@
 	return Form->ui.pageOptions->CBEnableSound->isChecked();
 }
 
+bool GameUIConfig::isSoundHardware()
+{
+	return Form->ui.pageOptions->CBHardwareSound->isChecked();
+}
+
 bool GameUIConfig::isMusicEnabled()
 {
 	return Form->ui.pageOptions->CBEnableMusic->isChecked();
--- a/QTfrontend/gameuiconfig.h	Tue Sep 22 21:00:39 2009 +0000
+++ b/QTfrontend/gameuiconfig.h	Tue Sep 22 21:58:08 2009 +0000
@@ -36,6 +36,7 @@
 	QRect vid_Resolution();
 	bool vid_Fullscreen();
 	bool isSoundEnabled();
+	bool isSoundHardware();
 	bool isMusicEnabled();
 	bool isShowFPSEnabled();
 	bool isAltDamageEnabled();
--- a/QTfrontend/hwform.cpp	Tue Sep 22 21:00:39 2009 +0000
+++ b/QTfrontend/hwform.cpp	Tue Sep 22 21:58:08 2009 +0000
@@ -878,7 +878,7 @@
 void HWForm::Music(bool checked)
 {
 	if (checked)
-		sdli.StartMusic();
+		sdli.StartMusic(ui.pageOptions->CBHardwareSound->isChecked());
 	else
 		sdli.StopMusic();
 }
--- a/QTfrontend/pages.cpp	Tue Sep 22 21:00:39 2009 +0000
+++ b/QTfrontend/pages.cpp	Tue Sep 22 21:58:08 2009 +0000
@@ -425,6 +425,11 @@
 		CBFrontendFullscreen->setText(QCheckBox::tr("Frontend fullscreen"));
 		GBAlayout->addWidget(CBFrontendFullscreen);
 
+		CBHardwareSound = new QCheckBox(AGGroupBox);
+		CBHardwareSound->setText(QCheckBox::tr("Use hardware sound (if available; requires restart)"));
+		//CBHardwareSound->setEnabled(openal_ready());
+		GBAlayout->addWidget(CBHardwareSound);
+
 		CBEnableSound = new QCheckBox(AGGroupBox);
 		CBEnableSound->setText(QCheckBox::tr("Enable sound"));
 		//CBEnableSound->setEnabled(openal_ready());
@@ -443,7 +448,7 @@
 		volumeBox = new QSpinBox(AGGroupBox);
 		volumeBox->setRange(0, 100);
 		volumeBox->setSingleStep(5);
-		volumeBox->setEnabled(openal_ready());
+		//volumeBox->setEnabled(openal_ready());
 		GBAvollayout->addWidget(volumeBox);
 
 		CBShowFPS = new QCheckBox(AGGroupBox);
--- a/QTfrontend/pages.h	Tue Sep 22 21:00:39 2009 +0000
+++ b/QTfrontend/pages.h	Tue Sep 22 21:58:08 2009 +0000
@@ -215,6 +215,7 @@
 	IconedGroupBox *AGGroupBox;
 	QComboBox *CBResolution;
 	QCheckBox *CBEnableSound;
+	QCheckBox *CBHardwareSound;
 	QCheckBox *CBEnableMusic;
 	QCheckBox *CBFullscreen;
 	QCheckBox *CBFrontendFullscreen;
--- a/hedgewars/hwengine.pas	Tue Sep 22 21:00:39 2009 +0000
+++ b/hedgewars/hwengine.pas	Tue Sep 22 21:58:08 2009 +0000
@@ -227,7 +227,7 @@
 {$ENDIF}
 
 case ParamCount of
- 16: begin
+ 17: begin
      val(ParamStr(2), cScreenWidth);
      val(ParamStr(3), cScreenHeight);
      cInitWidth:= cScreenWidth;
@@ -237,15 +237,16 @@
      val(ParamStr(5), ipcPort);
      cFullScreen:= ParamStr(6) = '1';
      isSoundEnabled:= ParamStr(7) = '1';
-     cLocaleFName:= ParamStr(8);
-     val(ParamStr(9), cInitVolume);
-     val(ParamStr(10), cTimerInterval);
-     PathPrefix:= ParamStr(11);
-     cShowFPS:= ParamStr(12) = '1';
-     cAltDamage:= ParamStr(13) = '1';
-     UserNick:= DecodeBase64(ParamStr(14));
-     isMusicEnabled:= ParamStr(15) = '1';
-     cReducedQuality:= ParamStr(16) = '1';
+	 isSoundHardware:= ParamStr(8) = '1';
+     cLocaleFName:= ParamStr(9);
+     val(ParamStr(10), cInitVolume);
+     val(ParamStr(11), cTimerInterval);
+     PathPrefix:= ParamStr(12);
+     cShowFPS:= ParamStr(13) = '1';
+     cAltDamage:= ParamStr(14) = '1';
+     UserNick:= DecodeBase64(ParamStr(15));
+     isMusicEnabled:= ParamStr(16) = '1';
+     cReducedQuality:= ParamStr(17) = '1';
      for p:= Succ(Low(TPathType)) to High(TPathType) do
          if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
      end;
--- a/hedgewars/uMisc.pas	Tue Sep 22 21:00:39 2009 +0000
+++ b/hedgewars/uMisc.pas	Tue Sep 22 21:58:08 2009 +0000
@@ -32,6 +32,7 @@
 	isInLag         : boolean = false;
 	isPaused        : boolean = false;
 	isSoundEnabled  : boolean = true;
+	isSoundHardware : boolean = false;
 	isMusicEnabled  : boolean = false;
 	isSEBackup      : boolean = true;
 	isInMultiShoot  : boolean = false;
--- a/hedgewars/uSound.pas	Tue Sep 22 21:00:39 2009 +0000
+++ b/hedgewars/uSound.pas	Tue Sep 22 21:58:08 2009 +0000
@@ -59,7 +59,7 @@
 
 
 {*remember: LongInt = 32bit; integer = 16bit; byte = 8bit*}
-function openal_init		(memsize: LongInt)                      : boolean; cdecl; external OpenALBridge;
+function openal_init		(hardware: LongInt; memsize: LongInt): boolean; cdecl; external OpenALBridge;
 function openal_close							: boolean; cdecl; external OpenALBridge;
 function openal_loadfile	(const filename: PChar)			: LongInt; cdecl; external OpenALBridge;
 function openal_toggleloop	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
@@ -106,7 +106,7 @@
 {*sound works in ipodtouch only if LAND_WIDTH  = 1024;   LAND_HEIGHT = 512; 
 or if ogg are loaded in stream or if sound is loaded by demand*}
 WriteToConsole('Init OpenAL sound...');
-isSoundEnabled:= openal_init(numSounds);
+if isSoundHardware then isSoundEnabled:= openal_init(1, numSounds) else isSoundEnabled:= openal_init(0, numSounds);
 if isSoundEnabled then WriteLnToConsole(msgOK)
                   else WriteLnToConsole(msgFailed);
 
--- a/openalbridge/openalbridge.c	Tue Sep 22 21:00:39 2009 +0000
+++ b/openalbridge/openalbridge.c	Tue Sep 22 21:58:08 2009 +0000
@@ -68,7 +68,7 @@
         return openalReady;
     }
     
-    ALboolean openal_init(uint32_t memorysize) {	
+    ALboolean openal_init(uint32_t usehardware, uint32_t memorysize) {	
         /*Initialize an OpenAL contex and allocate memory space for data and buffers*/
         ALCcontext *context;
         ALCdevice *device;
@@ -85,14 +85,22 @@
             fprintf(stderr, "ERROR: OpenAL already initialized\n");
             return AL_FALSE;
         }
-        
-        default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
-        fprintf(stderr, "Using default device: %s\n", default_device);
-        
-        if ((device = alcOpenDevice(default_device)) == NULL) {
-            fprintf(stderr, "ERROR: Failed to open sound device\n");
-            return AL_FALSE;
-        }
+
+		if(usehardware)
+		{
+			if ((device = alcOpenDevice(NULL)) == NULL) {
+				fprintf(stderr, "ERROR: Failed to open sound device\n");
+				return AL_FALSE;
+			}
+		}
+		else
+		{
+			if ((device = alcOpenDevice("Generic Software")) == NULL) {
+				fprintf(stderr, "ERROR: Failed to open sound device\n");
+				return AL_FALSE;
+			}
+		}
+		fprintf(stderr, "Using default device: %s\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
         
         context = alcCreateContext(device, NULL);
         alcMakeContextCurrent(context);
--- a/openalbridge/openalbridge.h	Tue Sep 22 21:00:39 2009 +0000
+++ b/openalbridge/openalbridge.h	Tue Sep 22 21:58:08 2009 +0000
@@ -25,7 +25,7 @@
 extern "C" {
 #endif 
     
-    ALboolean openal_init		(unsigned int memorysize);
+    ALboolean openal_init		(unsigned int usehardware, unsigned int memorysize);
     ALboolean openal_close		(void);
     ALint     openal_loadfile           (const char *filename);
     ALboolean openal_toggleloop         (unsigned int index);