changeset 12:bfe90b4f3d87

Bug fixes to FadeIn. Documentation fixes Minor API changes w.r.t. return types. (ALboolean instead of ALint)
author Eric Wing <ewing . public |-at-| gmail . com>
date Fri, 05 Nov 2010 20:59:13 -0700
parents eca6f008fad0
children 54aa96ae8912
files ALmixer.c ALmixer.h
diffstat 2 files changed, 76 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/ALmixer.c	Tue Nov 02 13:32:29 2010 -0700
+++ b/ALmixer.c	Fri Nov 05 20:59:13 2010 -0700
@@ -14,8 +14,13 @@
 	#include "SDL_sound.h"
 #endif
 
-#include "al.h" /* OpenAL */
-#include "alc.h" /* For creating OpenAL contexts */
+#ifdef ANDROID_NDK
+	#include <AL/al.h>
+	#include <AL/alc.h>
+#else
+	#include "al.h" /* OpenAL */
+	#include "alc.h" /* For creating OpenAL contexts */
+#endif
 
 #ifdef __APPLE__
 	/* For performance things like ALC_CONVERT_DATA_UPON_LOADING */
@@ -309,12 +314,13 @@
 			LARGE_INTEGER current_time;
 			QueryPerformanceCounter(&current_time);
 			return (ALuint)((current_time.QuadPart - s_ticksBaseTime.QuadPart) * 1000 * s_hiResSecondsPerTick);
+		#elif ANDROID_NDK
 
 		#else /* assuming POSIX */
 			/* clock_gettime is POSIX.1-2001 */
 			struct timespec current_time;
 			clock_gettime(CLOCK_MONOTONIC, &current_time);
-			return (ALuint)((current_time.tv_sec - s_ticksBaseTime.tv_sec)*1000.0 + (current_time.tv_nec - s_ticksBaseTime.tv_nsec) / 1000000);
+			return (ALuint)((current_time.tv_sec - s_ticksBaseTime.tv_sec)*1000.0 + (current_time.tv_nsec - s_ticksBaseTime.tv_nsec) / 1000000);
 		#endif
 	}
 	static void ALmixer_Delay(ALuint milliseconds_delay)
@@ -2016,7 +2022,7 @@
  * samples and start buffering up the data for the next
  * playback. This may require samples to be halted
  */
-static ALint Internal_RewindData(ALmixer_Data* data)
+static ALboolean Internal_RewindData(ALmixer_Data* data)
 {
 	ALint retval = 0;
 	/*
@@ -2026,7 +2032,7 @@
 	if(NULL == data)
 	{
 		ALmixer_SetError("Cannot rewind because data is NULL\n");
-		return -1;
+		return AL_FALSE;
 	}
 
 
@@ -2056,14 +2062,14 @@
 #if 0
 #if defined(DISABLE_PREDECODED_SEEK)
 		/* Since we can't seek predecoded stuff, it should be rewound */
-		return 0;
+		return AL_TRUE;
 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION)
 		/* This case is if the Sound_Sample has been deleted.
 		 * It assumes the data is already at the beginning.
 		 */
 		if(NULL == data->sample)
 		{
-			return 0;
+			return AL_TRUE;
 		}
 		/* Else, the sample has already been reallocated,
 		 * and we can fall to normal behavior
@@ -2077,7 +2083,7 @@
 		 */
 		if(NULL == data->sample)
 		{
-			return 0;
+			return AL_TRUE;
 		}
 		/* Else, the sample has already been reallocated,
 		 * and we can fall to normal behavior
@@ -2087,7 +2093,7 @@
 	/*
 		return data->total_bytes;
 	*/
-		return 0;
+		return AL_TRUE;
 	}
 	
 	/* Remaining stuff for streamed data */
@@ -2097,7 +2103,7 @@
 	if(0 == retval)
 	{
 		ALmixer_SetError( Sound_GetError() );
-		return -1;
+		return AL_FALSE;
 	}
 #if 0
 	/* Clear error */
@@ -2107,11 +2113,11 @@
 		bytes_returned = GetMoreData(data, data->buffer[i]);
 		if(-1 == bytes_returned)
 		{
-			return -1;
+			return AL_FALSE;
 		}
 		else if(0 == bytes_returned)
 		{
-			return -1;
+			return AL_FALSE;
 		}
 		retval += bytes_returned;
 		
@@ -2120,7 +2126,7 @@
 
 	
 	
-	return retval;
+	return AL_TRUE;
 }
 
 
@@ -2131,6 +2137,7 @@
 	ALint retval = 0;
 	ALenum error;
 	ALint state;
+	ALint running_count = 0;
 
 	if(channel >= Number_of_Channels_global)
 	{
@@ -2292,12 +2299,20 @@
 					 * much data is queued. Recommend users call Halt
 					 * before rewind if they want immediate results.
 					 */
-					retval = Internal_RewindData(ALmixer_Channel_List[i].almixer_data);
+					running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data);
 				}
 			}
 		}
 	}
-	return retval;
+	if(-1 == retval)
+	{
+		return -1;
+	}
+	else
+	{
+		return running_count;
+	}
+
 }
 
 
@@ -3098,14 +3113,14 @@
 /* Might consider setting eof to 0 as a "feature"
  * This will allow seek to end to stay there because
  * Play automatically rewinds if at the end */
-static ALint Internal_SeekData(ALmixer_Data* data, ALuint msec)
+static ALboolean Internal_SeekData(ALmixer_Data* data, ALuint msec)
 {
 	ALint retval;
 	
 	if(NULL == data)
 	{
 		ALmixer_SetError("Cannot Seek because data is NULL");
-		return -1;
+		return AL_FALSE;
 	}
 	
 	/* Seek for predecoded files involves moving the chunk pointer around */
@@ -3122,12 +3137,12 @@
 		if(data->in_use)
 		{
 			ALmixer_SetError("Cannot seek on predecoded data while instances are playing");
-			return -1;
+			return AL_FALSE;
 		}
 #if 0
 #if defined(DISABLE_PREDECODED_SEEK)
 		ALmixer_SetError("Seek support for predecoded samples was not compiled in");
-		return -1;
+		return AL_FALSE;
 
 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION)
 		/* By default, ALmixer frees the Sound_Sample for predecoded
@@ -3143,7 +3158,7 @@
 		{
 			if( -1 == Reconstruct_Sound_Sample(data) )
 			{
-				return -1;
+				return AL_FALSE;
 			}
 		}
 #endif
@@ -3158,11 +3173,20 @@
 		if(NULL == data->sample)
 		{
 			ALmixer_SetError("Cannot seek because access_data flag was set false when data was initialized");
-			return -1;
+			return AL_FALSE;
 		}
 		
 		byte_position = Convert_Msec_To_Byte_Pos(&data->sample->desired, msec);
-		return( Set_Predecoded_Seek_Position(data, byte_position) );
+		retval = Set_Predecoded_Seek_Position(data, byte_position);
+		if(-1 == retval)
+		{
+			return AL_FALSE;
+		}
+		else
+		{
+			return AL_TRUE;
+		}
+
 	}
 	else
 	{
@@ -3178,12 +3202,12 @@
 /*
 			Internal_RewindData(data);
 */
-			return -1;
-		}
-		return 0;
-	}
-
-	return 0;
+			return AL_FALSE;
+		}
+		return AL_TRUE;
+	}
+
+	return AL_TRUE;
 }			
 		
 
@@ -4666,13 +4690,13 @@
 					 */
 					delta_time = current_time - ALmixer_Channel_List[i].fade_start_time;
 					t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time;
-
 					current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume 
 						+ t * ALmixer_Channel_List[i].fade_end_volume;
+					fprintf(stderr, "start_vol=%f, end_vol:%f, current_volume: %f\n", ALmixer_Channel_List[i].fade_start_volume, ALmixer_Channel_List[i].fade_end_volume, current_volume);
 
 					/* Set the volume */
 					alSourcef(ALmixer_Channel_List[i].alsource,
-						AL_MAX_GAIN, current_volume);
+						AL_GAIN, current_volume);
 					if((error = alGetError()) != AL_NO_ERROR)
 					{
 						fprintf(stderr, "04Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
@@ -8305,9 +8329,9 @@
  * samples and start buffering up the data for the next
  * playback. This may require samples to be halted
  */
-ALint ALmixer_RewindData(ALmixer_Data* data)
-{
-	ALint retval;
+ALboolean ALmixer_RewindData(ALmixer_Data* data)
+{
+	ALboolean retval;
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8399,9 +8423,9 @@
 /* Might consider setting eof to 0 as a "feature"
  * This will allow seek to end to stay there because
  * Play automatically rewinds if at the end */
-ALint ALmixer_SeekData(ALmixer_Data* data, ALuint msec)
-{
-	ALint retval;
+ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec)
+{
+	ALboolean retval;
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
--- a/ALmixer.h	Tue Nov 02 13:32:29 2010 -0700
+++ b/ALmixer.h	Fri Nov 05 20:59:13 2010 -0700
@@ -168,7 +168,11 @@
 
 
 /* Needed for OpenAL types since altypes.h was removed in 1.1 */
-#include "al.h"
+#ifdef ANDROID_NDK
+	#include <AL/al.h>
+#else
+	#include "al.h"
+#endif
 
 /* Set up for C function definitions, even when using C++ */
 #ifdef __cplusplus
@@ -939,7 +943,7 @@
 /**
  * This function will look up the channel for the corresponding source.
  * @param al_source The source id you want to find the corresponding channel number for.
- * If -1 is supplied, it will try to return the first channel not in use. 
+ * If 0 is supplied, it will try to return the first channel not in use. 
  * Returns -1 on error, or the channel.
  */
 extern ALMIXER_DECLSPEC ALint ALMIXER_CALL ALmixer_GetChannel(ALuint al_source);
@@ -1037,9 +1041,9 @@
  * Rewinds the actual data, but the effect
  * may not be noticed until the currently buffered data is played.
  * @param almixer_data The data to rewind.
- * @returns 0 on success or -1 on error.
+ * @returns true on success or false on error.
  */
-extern ALMIXER_DECLSPEC ALint ALMIXER_CALL ALmixer_RewindData(ALmixer_Data* almixer_data);
+extern ALMIXER_DECLSPEC ALboolean ALMIXER_CALL ALmixer_RewindData(ALmixer_Data* almixer_data);
 
 /**
  * Rewinds the sound to the beginning that is playing on a specific channel.
@@ -1048,7 +1052,7 @@
  * Streamed data will rewind the actual data, but the effect
  * may not be noticed until the currently buffered data is played.
  * @param which_channel The channel to rewind or -1 to rewind all channels.
- * @returns 0 on success or -1 on error.
+ * @return The actual number of channels rewound on success or -1 on error.
  */
 extern ALMIXER_DECLSPEC ALint ALMIXER_CALL ALmixer_RewindChannel(ALint which_channel);
 /**
@@ -1058,7 +1062,7 @@
  * Streamed data will rewind the actual data, but the effect
  * may not be noticed until the currently buffered data is played.
  * @param al_source The source to rewind or 0 to rewind all sources.
- * @returns 1 on success or 0 on error.
+ * @return The actual number of sources rewound on success or -1 on error.
  */
 extern ALMIXER_DECLSPEC ALint ALMIXER_CALL ALmixer_RewindSource(ALuint al_source);
 
@@ -1066,11 +1070,11 @@
  * Seek the sound for a given data.
  * Seeks the actual data to the given millisecond. It
  * may not be noticed until the currently buffered data is played.
- * @param almixer_data
+ * @param almixer_data The data to seek on.
  * @param msec_pos The time position to seek to in the audio in milliseconds.
- * @returns 0 on success or -1 on error.
+ * @returns true on success or false on error.
  */
-extern ALMIXER_DECLSPEC ALint ALMIXER_CALL ALmixer_SeekData(ALmixer_Data* almixer_data, ALuint msec_pos);
+extern ALMIXER_DECLSPEC ALboolean ALMIXER_CALL ALmixer_SeekData(ALmixer_Data* almixer_data, ALuint msec_pos);
 
 /**
  * Pauses playback on a channel.
@@ -1458,7 +1462,7 @@
  * This is just a convenience alias to ALmixer_AllocateChannels(-1).
  * @see ALmixer_AllocateChannels
  */ 
-ALint ALmixer_CountTotalChannels(void);
+ALuint ALmixer_CountTotalChannels(void);
 #else
 #define ALmixer_CountTotalChannels() ALmixer_AllocateChannels(-1)
 #endif
@@ -1468,11 +1472,11 @@
 
 #ifdef DOXYGEN_ONLY
 /**
- * Returns the number of allocated channels.
+ * Returns the number of reserved channels.
  * This is just a convenience alias to ALmixer_ReserveChannels(-1).
  * @see ALmixer_ReserveChannels
  */ 
-ALint ALmixer_CountReservedChannels(void);
+ALuint ALmixer_CountReservedChannels(void);
 #else
 #define ALmixer_CountReservedChannels() ALmixer_ReserveChannels(-1)
 #endif