revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources
authorkoda
Sat, 17 Oct 2009 01:28:49 +0000
changeset 2515 51d3f4b6293a
parent 2514 df9d0728c5bb
child 2516 effafd586a4e
revert audio to use SDL_mixer -- also frontend uses it, so it needs sdlmixer sources the button for voicepack preview is broken for unknown reasons
CMakeLists.txt
QTfrontend/CMakeLists.txt
QTfrontend/SDLs.cpp
QTfrontend/SDLs.h
QTfrontend/hwform.h
QTfrontend/pages.cpp
QTfrontend/pages.h
QTfrontend/ui_hwform.cpp
QTfrontend/ui_hwform.h
hedgewars/CMakeLists.txt
hedgewars/GSHandlers.inc
hedgewars/SDLh.pas
hedgewars/uSound.pas
openalbridge/wrappers.c
--- a/CMakeLists.txt	Fri Oct 16 22:46:58 2009 +0000
+++ b/CMakeLists.txt	Sat Oct 17 01:28:49 2009 +0000
@@ -79,7 +79,7 @@
 
 
 add_subdirectory(bin)
-add_subdirectory(openalbridge)
+#add_subdirectory(openalbridge)
 add_subdirectory(QTfrontend)
 add_subdirectory(hedgewars)
 add_subdirectory(share)
--- a/QTfrontend/CMakeLists.txt	Fri Oct 16 22:46:58 2009 +0000
+++ b/QTfrontend/CMakeLists.txt	Sat Oct 17 01:28:49 2009 +0000
@@ -17,12 +17,11 @@
 
 # Configure for SDL
 find_package(SDL REQUIRED)
+find_package(SDL_mixer REQUIRED)
 
 include_directories(.)
 include_directories(${SDL_INCLUDE_DIR})
-include_directories(${OPENAL_INCLUDE_DIR})
-include_directories(${PROJECT_SOURCE_DIR}/openalbridge/)
-
+include_directories(${SDLMIXER_INCLUDE_DIR})
 if(UNIX)
 	# HACK: in freebsd cannot find iconv.h included via SDL.h
 	include_directories("/usr/local/include")
@@ -176,25 +175,12 @@
 set(HW_LINK_LIBS 
 	${QT_LIBRARIES}
 	${SDL_LIBRARY}
-	openalbridge
+	${SDLMIXER_LIBRARY}
 )
 
-#remember that in windows library order counts
-if(NOT APPLE)
+if(APPLE)
 	set(HW_LINK_LIBS
 		${HW_LINK_LIBS}
-		${OPENAL_LIBRARY}
-		${OGG_LIBRARY}
-		${VORBIS_LIBRARY}
-		${VORBISFILE_LIBRARY}
-		)
-else()
-#no vorbisfile required for MacOS X
-	set(HW_LINK_LIBS
-		${OPENAL_LIBRARY}
-		${OGG_LIBRARY}
-		${VORBIS_LIBRARY}
-		${HW_LINK_LIBS}
 		IOKit
 		)
         if (SPARKLE_FOUND)
--- a/QTfrontend/SDLs.cpp	Fri Oct 16 22:46:58 2009 +0000
+++ b/QTfrontend/SDLs.cpp	Sat Oct 17 01:28:49 2009 +0000
@@ -19,29 +19,25 @@
 #include "SDLs.h"
 
 #include "SDL.h"
+#include "SDL_mixer.h"
 #include "hwconsts.h"
 
 #include <QApplication>
 
+
 extern char sdlkeys[1024][2][128];
 extern char xb360buttons[][128];
 extern char xb360dpad[128];
 extern char xbox360axes[][128];
 
-#ifdef _WIN32
-bool hardware;
-#endif
-extern char *programname;
 
 SDLInteraction::SDLInteraction()
 {
-	music = -1;
-#ifdef _WIN32
-	hardware = false;
-#endif
+
 	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
-
-
+	
+	musicInitialized = 0;
+	music = NULL;
 	if(SDL_NumJoysticks())
 		addGameControllerKeys();
 	SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
@@ -49,17 +45,14 @@
 
 SDLInteraction::~SDLInteraction()
 {
+	if (musicInitialized == 1) {
+		if (music != NULL)
+			Mix_FreeMusic(music);
+		Mix_CloseAudio();
+	}
 	SDL_Quit();
-	oalb_close();
 }
 
-#ifdef _WIN32
-void SDLInteraction::setHardwareSound(bool hardware_snd)
-{
-	hardware = hardware_snd;
-}
-#endif
-
 QStringList SDLInteraction::getResolutions() const
 {
 	QStringList result;
@@ -162,33 +155,35 @@
 	sdlkeys[i][1][0] = '\0';
 }
 
+void SDLInteraction::SDLMusicInit()
+{
+	if (musicInitialized == 0) {
+		SDL_Init(SDL_INIT_AUDIO);
+		Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
+		musicInitialized = 1;
+	}
+}
+
+
 void SDLInteraction::StartMusic()
 {
-	OpenAL_Init();
-	if (music < 0) {
-		music = oalb_loadfile(QString(datadir->absolutePath() + "/Music/main theme.ogg").toLocal8Bit().constData());
+	SDLMusicInit();
+
+	if (music == NULL) {
+		music = Mix_LoadMUS((datadir->absolutePath() + "/Music/main theme.ogg").toLocal8Bit().constData());
 	
 	}
-	oalb_playsound(music, 1);
-	oalb_setvolume(music, 60);
-	oalb_fadein(music, 50);	
+	Mix_VolumeMusic(MIX_MAX_VOLUME - 28);
+	Mix_FadeInMusic(music, -1, 1750);
 }
 
 void SDLInteraction::StopMusic()
 {
-	if (music >= 0) oalb_fadeout(music, 20);
-	oalb_stopsound(music);
+	if (music != NULL) {
+		// fade out music to finish 0,5 seconds from now
+		while(!Mix_FadeOutMusic(1000) && Mix_PlayingMusic()) {
+			SDL_Delay(100);
+		}
+	}
 }
 
-//we need thjs wrapper because of some issues with windows drivers
-//beware that this cause a slight delay when playing the first sound
-void OpenAL_Init()
-{
-	if (!oalb_ready())
-#ifdef _WIN32
-        	oalb_init(programname, hardware ? 1 : 0);
-#else
-		oalb_init(programname, 0);
-#endif
-}
-
--- a/QTfrontend/SDLs.h	Fri Oct 16 22:46:58 2009 +0000
+++ b/QTfrontend/SDLs.h	Sat Oct 17 01:28:49 2009 +0000
@@ -1,3 +1,5 @@
+
+
 /*
  * Hedgewars, a free turn based strategy game
  * Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com>
@@ -19,26 +21,29 @@
 #ifndef SDLS_H
 #define SDLS_H
 
+
 #include <QStringList>
-#include "openalbridge.h"
+#include "SDL_mixer.h"
+
 
 class SDLInteraction : public QObject
 {
 	Q_OBJECT
 
 private:
-	int music;
+	Mix_Music *music;
+	int musicInitialized;	
 
 public:
 	SDLInteraction();
 	~SDLInteraction();
-	void setHardwareSound(bool hardware_snd);
 	QStringList getResolutions() const;
 	void addGameControllerKeys() const;
 	void StartMusic();
 	void StopMusic();
+	void SDLMusicInit();	
 };
 
-void OpenAL_Init();
 
 #endif
+
--- a/QTfrontend/hwform.h	Fri Oct 16 22:46:58 2009 +0000
+++ b/QTfrontend/hwform.h	Sat Oct 17 01:28:49 2009 +0000
@@ -51,6 +51,7 @@
 public:
 	HWForm(QWidget *parent = 0);
 	Ui_HWForm ui;
+	SDLInteraction sdli;
 
 private slots:
 	void GoToMain();
@@ -148,7 +149,6 @@
 	AmmoSchemeModel * ammoSchemeModel;
 	QStack<quint8> PagesStack;
 	QTime eggTimer;
-	SDLInteraction sdli;
 	BGWidget * wBackground;
         
 #ifdef __APPLE__
--- a/QTfrontend/pages.cpp	Fri Oct 16 22:46:58 2009 +0000
+++ b/QTfrontend/pages.cpp	Sat Oct 17 01:28:49 2009 +0000
@@ -98,7 +98,7 @@
 	BtnExit = addButton(":/res/Exit.png", pageLayout, 4, 0, 1, 1, true);
 }
 
-PageEditTeam::PageEditTeam(QWidget* parent) :
+PageEditTeam::PageEditTeam(QWidget* parent, SDLInteraction & sdli) :
   AbstractPage(parent)
 {
 	QGridLayout * pageLayout = new QGridLayout(this);
@@ -195,9 +195,8 @@
 		}
 		hbox->addWidget(CBVoicepack, 100);
 		BtnTestSound = addButton(":/res/PlaySound.png", hbox, 1, true);
-		//BtnTestSound->setEnabled(oalb_ready());
 		hbox->setStretchFactor(BtnTestSound, 1);
-		connect(BtnTestSound, SIGNAL(clicked()), this, SLOT(testSound()));
+		connect(BtnTestSound, SIGNAL(clicked()), this, SLOT(testSound(sdli)));
 		GBTLayout->addLayout(hbox);
 	}
 
@@ -288,20 +287,19 @@
 	FortPreview->setPixmap(pix);
 }
 
-void PageEditTeam::testSound()
+void PageEditTeam::testSound(SDLInteraction &sdli)
 {
-	int sound;
+	Mix_Music *sound;
 	QDir tmpdir;
-
-	OpenAL_Init();
+	sdli.SDLMusicInit();
 	
 	tmpdir.cd(datadir->absolutePath());
 	tmpdir.cd("Sounds/voices");
 	tmpdir.cd(CBVoicepack->currentText());
 	QStringList list = tmpdir.entryList(QStringList() << "Illgetyou.ogg" << "Incoming.ogg" << "Stupid.ogg" << "Coward.ogg" << "Firstblood.ogg", QDir::Files);
 	if (list.size()) {
-		sound = oalb_loadfile(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData());
-		oalb_playsound(sound, 0);
+		sound = Mix_LoadMUS(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData());
+		Mix_PlayMusic(sound, 0);
 	}
 }
 
@@ -431,20 +429,11 @@
             CBReduceQuality->setText(QCheckBox::tr("Reduced quality"));
             GBAlayout->addWidget(CBReduceQuality);
 
-#ifdef _WIN32
-            CBHardwareSound = new QCheckBox(AGGroupBox);
-            CBHardwareSound->setText(QCheckBox::tr("Hardware sound (if available; requires restart)"));
-            //CBHardwareSound->setEnabled(oalb_ready());
-            GBAlayout->addWidget(CBHardwareSound);
-#endif
-
             CBEnableSound = new QCheckBox(AGGroupBox);
             CBEnableSound->setText(QCheckBox::tr("Enable sound"));
-            //CBEnableSound->setEnabled(oalb_ready());
             GBAlayout->addWidget(CBEnableSound);
             CBEnableMusic = new QCheckBox(AGGroupBox);
             CBEnableMusic->setText(QCheckBox::tr("Enable music"));
-            //CBEnableMusic->setEnabled(oalb_ready());
             GBAlayout->addWidget(CBEnableMusic);
 
             QHBoxLayout * GBAvollayout = new QHBoxLayout(0);
@@ -455,7 +444,6 @@
             volumeBox = new QSpinBox(AGGroupBox);
             volumeBox->setRange(0, 100);
             volumeBox->setSingleStep(5);
-            //volumeBox->setEnabled(oalb_ready());
             GBAvollayout->addWidget(volumeBox);
 
             CBShowFPS = new QCheckBox(AGGroupBox);
--- a/QTfrontend/pages.h	Fri Oct 16 22:46:58 2009 +0000
+++ b/QTfrontend/pages.h	Sat Oct 17 01:28:49 2009 +0000
@@ -26,6 +26,7 @@
 #include <QSignalMapper>
 
 #include "binds.h"
+#include "hwform.h"
 #include "mapContainer.h"
 #include "togglebutton.h"
 
@@ -147,7 +148,7 @@
 	Q_OBJECT
 
 public:
-	PageEditTeam(QWidget* parent = 0);
+	PageEditTeam(QWidget* parent, SDLInteraction & sdli);
 	QSignalMapper* signalMapper;
 	QGroupBox *GBoxHedgehogs;
 	QGroupBox *GBoxTeam;
@@ -173,7 +174,7 @@
 	void CBFort_activated(const QString & gravename);
 
 private slots:
-	void testSound();
+	void testSound(SDLInteraction & sdli);
 };
 
 class PageMultiplayer : public AbstractPage
--- a/QTfrontend/ui_hwform.cpp	Fri Oct 16 22:46:58 2009 +0000
+++ b/QTfrontend/ui_hwform.cpp	Sat Oct 17 01:28:49 2009 +0000
@@ -22,12 +22,13 @@
 #include <QStackedLayout>
 
 #include "ui_hwform.h"
+#include "hwform.h"
 #include "pages.h"
 #include "statsPage.h"
 #include "playrecordpage.h"
 #include "hwconsts.h"
 
-void Ui_HWForm::setupUi(QMainWindow *HWForm)
+void Ui_HWForm::setupUi(HWForm *HWForm)
 {
 	SetupFonts();
 
@@ -38,7 +39,7 @@
 	centralWidget = new QWidget(HWForm);
 	centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
 
-	SetupPages(centralWidget);
+	SetupPages(centralWidget, HWForm);
 
 	HWForm->setCentralWidget(centralWidget);
 
@@ -52,11 +53,11 @@
 	font14 = new QFont("MS Shell Dlg", 14);
 }
 
-void Ui_HWForm::SetupPages(QWidget *Parent)
+void Ui_HWForm::SetupPages(QWidget *Parent, HWForm *HWForm)
 {
 	Pages = new QStackedLayout(Parent);
 
-	pageEditTeam = new PageEditTeam();
+	pageEditTeam = new PageEditTeam(Parent, HWForm->sdli);
 	Pages->addWidget(pageEditTeam);
 
 	pageOptions = new PageOptions();
--- a/QTfrontend/ui_hwform.h	Fri Oct 16 22:46:58 2009 +0000
+++ b/QTfrontend/ui_hwform.h	Sat Oct 17 01:28:49 2009 +0000
@@ -43,6 +43,7 @@
 class QFont;
 class QWidget;
 class QMainWindow;
+class HWForm;
 
 class Ui_HWForm
 {
@@ -73,9 +74,9 @@
 	QStackedLayout *Pages;
 	QFont *font14;
 
-	void setupUi(QMainWindow *HWForm);
+	void setupUi(HWForm *HWForm);
 	void SetupFonts();
-	void SetupPages(QWidget *Parent);
+	void SetupPages(QWidget *Parent, HWForm *HWForm);
 	void SetupPageNetChat(QWidget *Parent);
 	void SetupPageNetGame(QWidget *Parent);
 };
--- a/hedgewars/CMakeLists.txt	Fri Oct 16 22:46:58 2009 +0000
+++ b/hedgewars/CMakeLists.txt	Sat Oct 17 01:28:49 2009 +0000
@@ -4,6 +4,7 @@
 find_package(SDL_image)
 find_package(SDL_net)
 find_package(SDL_ttf)
+find_package(SDL_mixer)
 
 
 #SOURCE AND PROGRAMS SECTION 
--- a/hedgewars/GSHandlers.inc	Fri Oct 16 22:46:58 2009 +0000
+++ b/hedgewars/GSHandlers.inc	Sat Oct 17 01:28:49 2009 +0000
@@ -1718,7 +1718,6 @@
 if (Gear^.State and gstCollision) <> 0 then
 	begin
 	doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 20, EXPLAutoSound);
-	soundFadeOut(sndMortar,10,nil);
 
 	Gear^.dX.isNegative:= not dxn;
 	Gear^.dY.isNegative:= not dyn;
--- a/hedgewars/SDLh.pas	Fri Oct 16 22:46:58 2009 +0000
+++ b/hedgewars/SDLh.pas	Sat Oct 17 01:28:49 2009 +0000
@@ -40,6 +40,7 @@
 	{$linkframework SDL_net}
 	{$linkframework SDL_image}
 	{$linkframework SDL_ttf}
+	{$linkframework SDL_mixer}
 	{$linklib openalbridge}
 	{$linklib SDLmain}
 	{$linklib gcc}
@@ -425,107 +426,7 @@
 {$ENDIF}
 {$ENDIF}
 
-(*  TTF  *)
 
-const {$IFDEF WIN32}
-      SDL_TTFLibName = 'SDL_ttf.dll';
-      {$ENDIF}
-      {$IFDEF UNIX}
-            {$IFDEF DARWIN}
-            SDL_TTFLibName = 'SDL_ttf';
-            {$ELSE}
-            SDL_TTFLibName = 'libSDL_ttf.so';
-            {$ENDIF}
-      {$ENDIF}
-      TTF_STYLE_NORMAL = 0;
-      TTF_STYLE_BOLD   = 1;
-      TTF_STYLE_ITALIC = 2;
-
-type PTTF_Font = ^TTTF_font;
-     TTTF_Font = record
-                 end;
-
-function  TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
-procedure TTF_Quit; cdecl; external SDL_TTFLibName;
-
-
-function  TTF_SizeUTF8(font: PTTF_Font; const text: PChar; var w, h: LongInt): LongInt; cdecl; external SDL_TTFLibName;
-(* TSDL_Color -> Longword conversion is workaround over freepascal bug.
-   See http://www.freepascal.org/mantis/view.php?id=7613 for details *)
-function  TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
-function  TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
-function  TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
-
-function  TTF_OpenFont(const filename: PChar; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
-procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
-
-
-(*  SDL_image  *)
-
-const {$IFDEF WIN32}
-      SDL_ImageLibName = 'SDL_image.dll';
-      {$ENDIF}
-      {$IFDEF UNIX}
-            {$IFDEF DARWIN}
-            SDL_ImageLibName = 'SDL_image';
-            {$ELSE}
-            SDL_ImageLibName = 'libSDL_image.so';
-            {$ENDIF}
-      {$ENDIF}
-
-function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
-
-(*  SDL_net  *)
-
-const {$IFDEF WIN32}
-      SDL_NetLibName = 'SDL_net.dll';
-      {$ENDIF}
-      {$IFDEF UNIX}
-            {$IFDEF DARWIN}
-	        SDL_NetLibName = 'SDL_net';
-            {$ELSE}
-            SDL_NetLibName = 'libSDL_net.so';
-            {$ENDIF}
-      {$ENDIF}
-
-type TIPAddress = record
-                  host: Longword;
-                  port: Word;
-                  end;
-
-     PTCPSocket = ^TTCPSocket;
-     TTCPSocket = record
-                  ready: LongInt;
-                  channel: LongInt;
-                  remoteAddress: TIPaddress;
-                  localAddress: TIPaddress;
-                  sflag: LongInt;
-                  end;
-     PSDLNet_SocketSet = ^TSDLNet_SocketSet;
-     TSDLNet_SocketSet = record
-                         numsockets,
-                         maxsockets: LongInt;
-                         sockets: PTCPSocket;
-                         end;
-
-function  SDLNet_Init: LongInt; cdecl; external SDL_NetLibName;
-procedure SDLNet_Quit; cdecl; external SDL_NetLibName;
-
-function  SDLNet_AllocSocketSet(maxsockets: LongInt): PSDLNet_SocketSet; cdecl; external SDL_NetLibName;
-function  SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): LongInt; cdecl; external SDL_NetLibName;
-function  SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName;
-function  SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName;
-function  SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName;
-function  SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName;
-procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName;
-procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName;
-function  SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName;
-function  SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName;
-
-procedure SDLNet_Write16(value: Word; buf: pointer);
-procedure SDLNet_Write32(value: LongWord; buf: pointer);
-function  SDLNet_Read16(buf: pointer): Word;
-function  SDLNet_Read32(buf: pointer): LongWord;
 
 // Joystick/Controller support
 type PSDLJoystick = ^TSDLJoystick;
@@ -558,6 +459,172 @@
 function SDL_JoystickGetButton(joy: PSDLJoystick; button: LongInt): Byte; cdecl; external SDLLibName;
 procedure SDL_JoystickClose(joy: PSDLJoystick); cdecl; external SDLLibName;
 
+(*  TTF  *)
+
+const {$IFDEF WIN32}
+      SDL_TTFLibName = 'SDL_ttf.dll';
+      {$ENDIF}
+      {$IFDEF UNIX}
+	{$IFDEF DARWIN}
+	  SDL_TTFLibName = 'SDL_ttf';
+	{$ELSE}
+          SDL_TTFLibName = 'libSDL_ttf.so';
+        {$ENDIF}
+      {$ENDIF}
+      TTF_STYLE_NORMAL = 0;
+      TTF_STYLE_BOLD   = 1;
+      TTF_STYLE_ITALIC = 2;
+
+type PTTF_Font = ^TTTF_font;
+     TTTF_Font = record
+                 end;
+
+function TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
+procedure TTF_Quit; cdecl; external SDL_TTFLibName;
+
+
+function TTF_SizeUTF8(font: PTTF_Font; const text: PChar; var w, h: LongInt): LongInt; cdecl; external SDL_TTFLibName;
+(* TSDL_Color -> Longword conversion is workaround over freepascal bug.
+   See http://www.freepascal.org/mantis/view.php?id=7613 for details *)
+function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
+function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
+function TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
+
+function TTF_OpenFont(const filename: PChar; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
+procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
+
+(*  SDL_mixer  *)
+
+const {$IFDEF WIN32}
+      SDL_MixerLibName = 'SDL_mixer.dll';
+      {$ENDIF}
+      {$IFDEF UNIX}
+	{$IFDEF DARWIN}
+	  SDL_MixerLibName = 'SDL_mixer';
+	{$ELSE}
+          SDL_MixerLibName = 'libSDL_mixer.so';
+	{$ENDIF}
+      {$ENDIF}
+
+const MIX_MAX_VOLUME = 128;
+
+type PMixChunk = ^TMixChunk;
+     TMixChunk = record
+                 allocated: Longword;
+                 abuf     : PByte;
+                 alen     : Longword;
+                 volume   : PByte;
+                 end;
+     TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3);
+     TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN);
+
+     TMidiSong = record
+               samples : LongInt;
+               events  : pointer;
+               end;
+
+     TMusicUnion = record
+        case Byte of
+             0: ( midi : TMidiSong );
+             1: ( ogg  : pointer);
+             end;
+
+     PMixMusic = ^TMixMusic;
+     TMixMusic = record
+                 end;
+
+function  Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName;
+
+function  Mix_Volume(channel: LongInt; volume: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_SetDistance(channel: LongInt; distance: Byte): LongInt;  cdecl; external SDL_MixerLibName;
+function  Mix_VolumeMusic(volume: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+
+function  Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName;
+procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName;
+
+function  Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName;
+function  Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName;
+
+function  Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_FadeInMusic(music: PMixMusic; loops: LongInt; ms: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+
+function  Mix_PlayChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_PlayMusic(music: PMixMusic; loops: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_PausedMusic(music: PMixMusic): LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_PauseMusic(music: PMixMusic): LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_ResumeMusic(music: PMixMusic): LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_HaltChannel(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName;
+
+(*  SDL_image  *)
+
+const {$IFDEF WIN32}
+      SDL_ImageLibName = 'SDL_image.dll';
+      {$ENDIF}
+      {$IFDEF UNIX}
+	{$IFDEF DARWIN}
+	  SDL_ImageLibName = 'SDL_image';
+	{$ELSE}
+           SDL_ImageLibName = 'libSDL_image.so';
+	{$ENDIF}
+      {$ENDIF}
+
+function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
+
+(*  SDL_net  *)
+
+const {$IFDEF WIN32}
+      SDL_NetLibName = 'SDL_net.dll';
+      {$ENDIF}
+      {$IFDEF UNIX}
+	{$IFDEF DARWIN}
+	  SDL_NetLibName = 'SDL_net';
+	{$ELSE}
+          SDL_NetLibName = 'libSDL_net.so';
+	{$ENDIF}
+      {$ENDIF}
+
+type TIPAddress = record
+                  host: Longword;
+                  port: Word;
+                  end;
+
+     PTCPSocket = ^TTCPSocket;
+     TTCPSocket = record
+                  ready: LongInt;
+                  channel: LongInt;
+                  remoteAddress: TIPaddress;
+                  localAddress: TIPaddress;
+                  sflag: LongInt;
+                  end;
+     PSDLNet_SocketSet = ^TSDLNet_SocketSet;
+     TSDLNet_SocketSet = record
+                         numsockets,
+                         maxsockets: LongInt;
+                         sockets: PTCPSocket;
+                         end;
+
+function SDLNet_Init: LongInt; cdecl; external SDL_NetLibName;
+procedure SDLNet_Quit; cdecl; external SDL_NetLibName;
+
+function SDLNet_AllocSocketSet(maxsockets: LongInt): PSDLNet_SocketSet; cdecl; external SDL_NetLibName;
+function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): LongInt; cdecl; external SDL_NetLibName;
+function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName;
+function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName;
+function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName;
+function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName;
+procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName;
+procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName;
+function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName;
+function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName;
+
+procedure SDLNet_Write16(value: Word; buf: pointer);
+procedure SDLNet_Write32(value: LongWord; buf: pointer);
+function SDLNet_Read16(buf: pointer): Word;
+function SDLNet_Read32(buf: pointer): LongWord;
+
 implementation
 
 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
--- a/hedgewars/uSound.pas	Fri Oct 16 22:46:58 2009 +0000
+++ b/hedgewars/uSound.pas	Sat Oct 17 01:28:49 2009 +0000
@@ -18,33 +18,15 @@
 
 unit uSound;
 interface
-
-
-{$IFDEF DARWIN}
-	{$linklib openalbridge}
-	{$linkframework OpenAL}
-	{$linkframework Ogg}
-	{$linkframework Vorbis}
-{$ELSE}
-{$IFNDEF WIN32}
-    {$linklib openal}
-    {$linklib ogg}
-    {$linklib vorbis}
-    {$linklib vorbisfile}
-{$ENDIF}
-{$ENDIF}
-
-uses uConsts;
+uses SDLh, uConsts;
 {$INCLUDE options.inc}
 
 type PVoicepack = ^TVoicepack;
 	TVoicepack = record
 		name: shortstring;
-		chunks: array [TSound] of LongInt;
+		chunks: array [TSound] of PMixChunk;
 		end;
 
-const OpenALBridge = 'libopenalbridge';
-
 procedure InitSound;
 procedure ReleaseSound;
 procedure SoundLoad;
@@ -53,39 +35,23 @@
 procedure PauseMusic;
 procedure ResumeMusic;
 procedure StopSound(snd: TSound);
-
-function ChangeVolume(voldelta: LongInt): LongInt;
-function AskForVoicepack(name: shortstring): PVoicepack;
-function soundFadeOut(snd: TSound; qt: LongInt; voicepack: PVoicepack): LongInt;
-
+function  ChangeVolume(voldelta: LongInt): LongInt;
 
-procedure oalb_close; cdecl; external OpenALBridge;
-function oalb_init		(const app: PChar; const usehardware: Byte): Byte; cdecl; external OpenALBridge;
-function oalb_loadfile		(const filename: PChar): LongInt; cdecl; external OpenALBridge;
-procedure oalb_playsound	(const idx: LongInt; const loop: Byte); cdecl; external OpenALBridge;
-procedure oalb_stopsound	(const idx: LongInt); cdecl; external OpenALBridge;
-procedure oalb_pausesound	(const idx: LongInt); cdecl; external OpenALBridge;
-procedure oalb_continuesound	(const idx: LongInt); cdecl; external OpenALBridge;
-procedure oalb_setvolume	(const idx: LongInt; const percentage: Byte); cdecl; external OpenALBridge;
-procedure oalb_setglobalvolume	(const percentage: Byte); cdecl; external OpenALBridge;
-procedure oalb_fadein		(const idx: LongInt; quantity: Integer); cdecl; external OpenALBridge;
-procedure oalb_fadeout		(const idx: LongInt; quantity: Integer); cdecl; external OpenALBridge;
-
+function  AskForVoicepack(name: shortstring): Pointer;
 
 var MusicFN: shortstring = '';
 
 implementation
-
 uses uMisc, uConsole;
 
 const chanTPU = 12;
-var	Volume: LongInt;
+var Volume: LongInt;
 	lastChan: array [TSound] of LongInt;
 	voicepacks: array[0..cMaxTeams] of TVoicepack;
 	defVoicepack: PVoicepack;
-	Mus: LongInt = 0;
+	Mus: PMixMusic = nil;
 
-function  AskForVoicepack(name: shortstring): PVoicepack;
+function  AskForVoicepack(name: shortstring): Pointer;
 var i: Longword;
 begin
 i:= 0;
@@ -102,22 +68,31 @@
 procedure InitSound;
 begin
 if not isSoundEnabled then exit;
-{*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:= oalb_init(str2PChar(ParamStr(0)), Byte(isSoundHardware)) = 1;
+WriteToConsole('Init sound...');
+isSoundEnabled:= SDL_Init(SDL_INIT_AUDIO) >= 0;
+if isSoundEnabled then
+   isSoundEnabled:= Mix_OpenAudio(44100, $8010, 2, 1024) = 0;
 if isSoundEnabled then WriteLnToConsole(msgOK)
                   else WriteLnToConsole(msgFailed);
+Mix_AllocateChannels(Succ(chanTPU));
+if isMusicEnabled then Mix_VolumeMusic(50);
 
-Volume:=0;
-ChangeVolume(cInitVolume);
+Volume:= 0;
+ChangeVolume(cInitVolume)
 end;
 
 procedure ReleaseSound;
+var i: TSound;
+	t: Longword;
 begin
-if isMusicEnabled then oalb_fadeout(Mus, 30);
-oalb_close();
+for t:= 0 to cMaxTeams do
+	if voicepacks[t].name <> '' then
+		for i:= Low(TSound) to High(TSound) do
+			if voicepacks[t].chunks[i] <> nil then
+				Mix_FreeChunk(voicepacks[t].chunks[i]);
+
+Mix_FreeMusic(Mus);
+Mix_CloseAudio
 end;
 
 procedure SoundLoad;
@@ -134,8 +109,8 @@
 		begin
 		s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName;
 		WriteToConsole(msgLoading + s + ' ');
-		defVoicepack^.chunks[i]:= oalb_loadfile(Str2PChar(s));
-		TryDo(defVoicepack^.chunks[i] >= 0, msgFailed, true);
+		defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
+		TryDo(defVoicepack^.chunks[i] <> nil, msgFailed, true);
 		WriteLnToConsole(msgOK);
 		end;
 
@@ -146,38 +121,34 @@
 				begin
 				s:= Pathz[Soundz[i].Path] + '/' + voicepacks[t].name + '/' + Soundz[i].FileName;
 				WriteToConsole(msgLoading + s + ' ');
-				voicepacks[t].chunks[i]:= oalb_loadfile(Str2PChar(s));
-				if voicepacks[t].chunks[i] < 0 then
+			//	{$IFNDEF IPHONEOS}
+				//broken for unknown reasons (most likely poor SDL_Mixer)
+				voicepacks[t].chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
+			//	{$ENDIF}
+				if voicepacks[t].chunks[i] = nil then
 					WriteLnToConsole(msgFailed)
 				else
 					WriteLnToConsole(msgOK)
 				end;
 end;
 
-function soundFadeOut(snd: TSound; qt: LongInt; voicepack: PVoicepack): LongInt;
-begin
-if not isSoundEnabled then exit(0);
-if (voicepack <> nil) and (voicepack^.chunks[snd] >= 0) then oalb_fadeout(defVoicepack^.chunks[snd], qt)
-else if (defVoicepack^.chunks[snd] >= 0) then oalb_fadeout(defVoicepack^.chunks[snd], qt);
-end;
-
 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
+var loops: LongInt;
 begin
 if (not isSoundEnabled) or fastUntilLag then exit;
-
-if voicepack = nil then voicepack:= defVoicepack;
+if infinite then loops:= -1 else loops:= 0;
 
-if voicepack^.chunks[snd] >= 0 then
-	begin
-	oalb_playsound(voicepack^.chunks[snd], Byte(infinite));
-	lastChan[snd]:=voicepack^.chunks[snd];
-	end
+if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then
+	lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], loops, -1)
+else
+	lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], loops, -1)
 end;
 
 procedure StopSound(snd: TSound);
 begin
-if isSoundEnabled then
-	oalb_stopsound(lastChan[snd])
+if not isSoundEnabled then exit;
+if Mix_Playing(lastChan[snd]) <> 0 then
+	Mix_HaltChannel(lastChan[snd])
 end;
 
 procedure PlayMusic;
@@ -190,47 +161,39 @@
 s:= PathPrefix + '/Music/' + MusicFN;
 WriteToConsole(msgLoading + s + ' ');
 
-Mus:= oalb_loadfile(Str2PChar(s));
-TryDo(Mus >= 0, msgFailed, false);
+Mus:= Mix_LoadMUS(Str2PChar(s));
+TryDo(Mus <> nil, msgFailed, false);
 WriteLnToConsole(msgOK);
 
-oalb_playsound(Mus, 1);
-oalb_fadein(Mus, 20);
+SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false)
 end;
 
 function ChangeVolume(voldelta: LongInt): LongInt;
 begin
-if not isSoundEnabled then exit(0);
+if not isSoundEnabled then
+	exit(0);
 
 inc(Volume, voldelta);
 if Volume < 0 then Volume:= 0;
-if Volume > 100 then Volume:= 100;
-
-oalb_setglobalvolume(Volume);
-if isMusicEnabled then oalb_setvolume(Mus, Volume shr 1);
-ChangeVolume:= Volume;
+Mix_Volume(-1, Volume);
+Volume:= Mix_Volume(-1, -1);
+if isMusicEnabled then Mix_VolumeMusic(Volume * 4 div 8);
+ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME
 end;
 
 procedure PauseMusic;
 begin
 if (MusicFN = '') or (not isMusicEnabled) then exit;
-oalb_stopsound(Mus)
+
+Mix_PauseMusic(Mus);
 end;
 
 procedure ResumeMusic;
 begin
 if (MusicFN = '') or (not isMusicEnabled) then exit;
-oalb_playsound(Mus, 0)
+
+Mix_ResumeMusic(Mus);
 end;
 
-
-var i: LongInt;
-	c: TSound;
+end.
 
-initialization
-for i:= 0 to cMaxTeams do
-	for c:= Low(TSound) to High(TSound) do
-		voicepacks[i].chunks[c]:= -1
-
-
-end.
--- a/openalbridge/wrappers.c	Fri Oct 16 22:46:58 2009 +0000
+++ b/openalbridge/wrappers.c	Sat Oct 17 01:28:49 2009 +0000
@@ -93,7 +93,7 @@
                 
                 /*save the volume desired after the fade*/
                 alGetSourcef(Sources[index], AL_GAIN, &target_gain);
-                if (target_gain > 1.0f || target_gain <= 0.0f)
+                if (target_gain > 1.0f || target_gain < 0.0f)
                         target_gain = 1.0f;
                 
                 alSourcePlay(Sources[index]);