Index: sound.c
===================================================================
--- sound.c	(revision 111)
+++ sound.c	(revision 112)
@@ -10,6 +10,9 @@
 #include "headers/sound.h"
 #endif
 
+// There's way too much "#ifdef" in this file, but eh ... OpenAL becomes
+// complex when you comes to portability ...
+
 #ifndef ALUT_API_MAJOR_VERSION
 #warning You must use OpenAL 1.1 or greater ! See configure script.
 #endif
@@ -78,12 +81,12 @@
  ALenum format;
  ALvoid *data;
  FILE *fp;
-
-#ifndef WIN32
-#ifdef ALUT_API_MAJOR_VERSION
-#define ALUT_API_MAJOR_VERSION_BUT_WIN32
-#endif
-#endif
+
+#ifndef WIN32
+#ifdef ALUT_API_MAJOR_VERSION
+#define ALUT_API_MAJOR_VERSION_BUT_WIN32
+#endif
+#endif
     
 #ifndef ALUT_API_MAJOR_VERSION_BUT_WIN32
  ALboolean boolean;
@@ -113,7 +116,7 @@
  }
  fclose(fp);
 
-#ifdef ALUT_API_MAJOR_VERSION_BUT_WIN32
+#ifdef ALUT_API_MAJOR_VERSION_BUT_WIN32
  data=alutLoadMemoryFromFile(fname,&format,&size,&freq);
      raydium_sound_verify("alutLoadMemoryFromFile");
 
@@ -123,7 +126,7 @@
 
  if(data)
   free(data);
-
+
  #else
   alutLoadWAVFile((ALbyte *)fname,&format,&data,&size,&freq,&boolean);
      raydium_sound_verify("alutLoadWAVFile");
@@ -389,9 +392,9 @@
  alGetListenerfv(AL_VELOCITY,(ALfloat *)&(*Vel));
    raydium_sound_verify("getting listener velocity");
 }
-
-
-
+
+
+
 //INITIALISATION
 void raydium_sound_init(void)
 {
@@ -401,14 +404,15 @@
 // ALfloat back[] ={ 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
  ALfloat front[]={ 1.0f, 0.0f,  1.0f, 0.0f, 0.0f, 1.0f };
  const ALchar *tempString;
- ALCdevice* pDevice;
- ALCcontext* pContext;
- 
+ ALCdevice* pDevice;
+ ALCcontext* pContext;
+ 
 #ifdef NO_SOUND_DEBUG
 return;
 #endif
-
-/*
+
+#ifndef WIN32
+// I've noticed problems with "manual contexts" under Linux, so let's use ALUT
 #ifdef ALUT_API_MAJOR_VERSION
 if(!alutInit(&raydium_init_argc, raydium_init_argv))
     {
@@ -420,12 +424,14 @@
 #else
  alutInit(&raydium_init_argc, raydium_init_argv);
 #endif
-*/
- pDevice = alcOpenDevice("Generic Software"); // or any asked device name ?
- pContext=alcCreateContext(pDevice,NULL);
- alcMakeContextCurrent(pContext);
- alutInitWithoutContext(&raydium_init_argc, raydium_init_argv);
- 
+
+#else
+// With win32, alut may do "bad things" while chosing device ... let's force :
+ pDevice = alcOpenDevice("Generic Software"); // or any asked device name ?
+ pContext=alcCreateContext(pDevice,NULL);
+ alcMakeContextCurrent(pContext);
+ alutInitWithoutContext(&raydium_init_argc, raydium_init_argv);
+#endif
  
 //alutInit(0, NULL) ;
  alGetError();
@@ -464,29 +470,29 @@
 
  for(i=0;i<RAYDIUM_SOUND_NUM_BUFFERS;i++)
     raydium_sound_source_fade_factor[i]=0;
-
- pContext = alcGetCurrentContext();
- pDevice = alcGetContextsDevice(pContext);
+
+ pContext = alcGetCurrentContext();
+ pDevice = alcGetContextsDevice(pContext);
  tempString = alcGetString(pDevice, ALC_DEVICE_SPECIFIER);
- raydium_log("sound: OK, using '%s'",tempString);
-/* 
-{
-		const ALchar *tempString;
-
-		ALCcontext* pContext;
-		ALCdevice* pDevice;
-		pContext = alcGetCurrentContext();
-		pDevice = alcGetContextsDevice(pContext);
-		tempString = alcGetString(pDevice, ALC_DEVICE_SPECIFIER);
-		printf("OpenAL Context Device Specifier is '%s'\n", tempString);
-		tempString = alGetString(AL_RENDERER);
-		printf("OpenAL Renderer is '%s'\n", tempString);
-		tempString = alGetString(AL_VERSION);
-		printf("OpenAL Version is '%s'\n", tempString);
-		tempString = alGetString(AL_VENDOR);
-		printf("OpenAL Vendor is '%s'\n", tempString);
-		tempString = alGetString(AL_EXTENSIONS);
-		printf("OpenAL Extensions supported are :\n%s\n", tempString);
+ raydium_log("sound: OK, using '%s'",tempString);
+/* 
+{
+		const ALchar *tempString;
+
+		ALCcontext* pContext;
+		ALCdevice* pDevice;
+		pContext = alcGetCurrentContext();
+		pDevice = alcGetContextsDevice(pContext);
+		tempString = alcGetString(pDevice, ALC_DEVICE_SPECIFIER);
+		printf("OpenAL Context Device Specifier is '%s'\n", tempString);
+		tempString = alGetString(AL_RENDERER);
+		printf("OpenAL Renderer is '%s'\n", tempString);
+		tempString = alGetString(AL_VERSION);
+		printf("OpenAL Version is '%s'\n", tempString);
+		tempString = alGetString(AL_VENDOR);
+		printf("OpenAL Vendor is '%s'\n", tempString);
+		tempString = alGetString(AL_EXTENSIONS);
+		printf("OpenAL Extensions supported are :\n%s\n", tempString);
 }    
 */ 
 }
@@ -543,9 +549,11 @@
 //THINGS TO DO WHEN EXITING
 void raydium_sound_close(void)
 {
-int i;
-ALCdevice* pDevice;
-ALCcontext* pContext;
+int i;
+#ifdef WIN32
+ALCdevice* pDevice;
+ALCcontext* pContext;
+#endif
     
  if(raydium_sound==1) // WE DO THESE THINGS ONLY IF OPEN AL INIT WAS OK
  {
@@ -556,16 +564,17 @@
   raydium_log("sound: Deleting buffers");
    alDeleteBuffers(RAYDIUM_SOUND_NUM_BUFFERS,raydium_sound_buffer);
   raydium_log("sound: Releasing OpenAL");
-   
-  	//Get active context
-	pContext=alcGetCurrentContext();
-	//Get device for active context
-	pDevice=alcGetContextsDevice(pContext);
-	//Release context(s)
-	alcDestroyContext(pContext);
-	//Close device
-	alcCloseDevice(pDevice);
-  
+   
+#ifdef WIN32
+  	//Get active context
+	pContext=alcGetCurrentContext();
+	//Get device for active context
+	pDevice=alcGetContextsDevice(pContext);
+	//Release context(s)
+	alcDestroyContext(pContext);
+	//Close device
+	alcCloseDevice(pDevice);
+#endif
   alutExit();
  }
 }
@@ -601,23 +610,23 @@
     format=AL_FORMAT_STEREO16;
 
   alBufferData(buffer,format,raydium_sound_music_buf,count,ogginfo->rate);
-  //printf("buffered to %i buffer\n",buffer);
+  //printf("buffered to %i buffer\n",buffer);
   return 1;
 }
 
 void raydium_sound_internal_cleanstreambuffs(void)
 {
-    ALint lProcessed;
+    ALint lProcessed;
     ALuint TempBufferID;
-
-    alGetSourcei(raydium_sound_source[0], AL_BUFFERS_PROCESSED, &lProcessed);
-    //printf("%i -----\n",lProcessed);
-			while (lProcessed)
-			{
-                //printf(".");
-				alSourceUnqueueBuffers(raydium_sound_source[0], 1, &TempBufferID);
-                lProcessed--;
-			}
+
+    alGetSourcei(raydium_sound_source[0], AL_BUFFERS_PROCESSED, &lProcessed);
+    //printf("%i -----\n",lProcessed);
+			while (lProcessed)
+			{
+                //printf(".");
+				alSourceUnqueueBuffers(raydium_sound_source[0], 1, &TempBufferID);
+                lProcessed--;
+			}
 }
 
 
@@ -714,9 +723,9 @@
 
  alGetSourcei(raydium_sound_source[0],AL_BUFFERS_PROCESSED,&nprocessed);
  while(nprocessed)
- {
+ {
   static int last;
-     alSourceUnqueueBuffers(raydium_sound_source[0],1,&buffer);
+     alSourceUnqueueBuffers(raydium_sound_source[0],1,&buffer);
         //printf("%i, buff = %i\n",nprocessed,buffer);
   if(buffer==last)
     {
@@ -729,19 +738,19 @@
     alSourceQueueBuffers(raydium_sound_source[0],1,&buffer);
     nprocessed--;
     }
- alGetSourcei(raydium_sound_source[0],AL_BUFFERS_PROCESSED,&nprocessed);
+ alGetSourcei(raydium_sound_source[0],AL_BUFFERS_PROCESSED,&nprocessed);
  } 
 
  //restart playing if needed
  alGetSourcei(raydium_sound_source[0],AL_SOURCE_STATE,&sourcestate);
  if(sourcestate!=AL_PLAYING)
- {
-    raydium_sound_internal_cleanstreambuffs();
-    alSourcePlay(raydium_sound_source[0]);
-    alGetSourcei(raydium_sound_source[0],AL_SOURCE_STATE,&sourcestate);
-     if(sourcestate!=AL_PLAYING)
+ {
+    raydium_sound_internal_cleanstreambuffs();
+    alSourcePlay(raydium_sound_source[0]);
+    alGetSourcei(raydium_sound_source[0],AL_SOURCE_STATE,&sourcestate);
+     if(sourcestate!=AL_PLAYING)
         StartMusic(raydium_sound_source[0],raydium_sound_buffer,
-           &raydium_sound_vf,raydium_sound_ogginfo);         
+           &raydium_sound_vf,raydium_sound_ogginfo);         
  } 
 
 }