changeset 27:9cf93a099f75

Added initialization checks to all API functions.
author Eric Wing <ewing . public |-at-| gmail . com>
date Fri, 04 Mar 2011 11:29:05 -0800
parents 884cce2515eb
children 60500a33735a
files ALmixer.c
diffstat 1 files changed, 234 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ALmixer.c	Fri Dec 24 13:58:04 2010 -0800
+++ b/ALmixer.c	Fri Mar 04 11:29:05 2011 -0800
@@ -7678,6 +7678,11 @@
 
 ALint ALmixer_AllocateChannels(ALint numchans)
 {
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
+
 	ALint retval;
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
@@ -7692,6 +7697,11 @@
 	
 ALint ALmixer_ReserveChannels(ALint num)
 {
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
+	
 	ALint retval;
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
@@ -8251,6 +8261,11 @@
 	Sound_Sample* sample = NULL;
 	Sound_AudioInfo target;
 	
+	if(0 == ALmixer_Initialized)
+	{
+		return NULL;
+	}
+
 	/* Initialize target values to defaults 
 	 * 0 tells SDL_sound to use the "actual" values
 	 */
@@ -8297,6 +8312,11 @@
 	Sound_Sample* sample = NULL;
 	Sound_AudioInfo target;
 	
+	if(0 == ALmixer_Initialized)
+	{
+		return NULL;
+	}
+	
 	/* Initialize target values to defaults 
 	 * 0 tells SDL_sound to use the "actual" values
 	 */
@@ -8398,6 +8418,12 @@
 {
 	Sound_Sample* sample = NULL;
 	Sound_AudioInfo sound_desired;
+
+	if(0 == ALmixer_Initialized)
+	{
+		return NULL;
+	}
+	
 	/* Rather than copying the data from struct to struct, I could just
 	 * cast the thing since the structs are meant to be identical. 
 	 * But if SDL_sound changes it's implementation, bad things
@@ -8434,6 +8460,12 @@
 {
 	Sound_Sample* sample = NULL;
 	Sound_AudioInfo sound_desired;
+
+	if(0 == ALmixer_Initialized)
+	{
+		return;
+	}
+	
 	/* Rather than copying the data from struct to struct, I could just
 	 * cast the thing since the structs are meant to be identical. 
 	 * But if SDL_sound changes it's implementation, bad things
@@ -8472,6 +8504,11 @@
 		return;
 	}
 
+	if(0 == ALmixer_Initialized)
+	{
+		return;
+	}
+
 	/* Bypass if in interruption event */
 	if(NULL == alcGetCurrentContext())
 	{
@@ -8543,6 +8580,10 @@
 ALuint ALmixer_GetSource(ALint channel)
 {
 	ALuint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8557,6 +8598,10 @@
 ALint ALmixer_GetChannel(ALuint source)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8570,6 +8615,10 @@
 ALint ALmixer_FindFreeChannel(ALint start_channel)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8642,6 +8691,10 @@
 ALint ALmixer_PlayChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALint ticks)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}		
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8668,6 +8721,10 @@
 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks)
 {
 	ALuint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8680,11 +8737,15 @@
 
 
 /* Will return the number of channels halted
- * or 0 for error
+ * or -1 for error
  */
 ALint ALmixer_HaltChannel(ALint channel)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8701,6 +8762,10 @@
 ALint ALmixer_HaltSource(ALuint source)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8719,6 +8784,10 @@
 ALboolean ALmixer_RewindData(ALmixer_Data* data)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return AL_FALSE;
+	}	
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8732,6 +8801,10 @@
 ALint ALmixer_RewindChannel(ALint channel)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8745,6 +8818,10 @@
 ALint ALmixer_RewindSource(ALuint source)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}	
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8758,6 +8835,10 @@
 ALint ALmixer_PauseChannel(ALint channel)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8771,6 +8852,10 @@
 ALint ALmixer_PauseSource(ALuint source)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8784,6 +8869,10 @@
 ALint ALmixer_ResumeChannel(ALint channel)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8797,6 +8886,10 @@
 ALint ALmixer_ResumeSource(ALuint source)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8813,6 +8906,10 @@
 ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8826,6 +8923,10 @@
 ALint ALmixer_SeekChannel(ALint channel, ALuint msec)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8839,6 +8940,10 @@
 ALint ALmixer_SeekSource(ALuint source, ALuint msec)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8852,6 +8957,10 @@
 ALint ALmixer_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8865,6 +8974,10 @@
 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks)
 {
 	ALuint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8878,6 +8991,10 @@
 ALint ALmixer_FadeOutChannel(ALint channel, ALuint ticks)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8891,6 +9008,10 @@
 ALint ALmixer_FadeOutSource(ALuint source, ALuint ticks)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8904,6 +9025,10 @@
 ALint ALmixer_FadeChannel(ALint channel, ALuint ticks, ALfloat volume)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8917,6 +9042,10 @@
 ALint ALmixer_FadeSource(ALuint source, ALuint ticks, ALfloat volume)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8931,6 +9060,10 @@
 ALboolean ALmixer_SetVolumeChannel(ALint channel, ALfloat volume)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return AL_FALSE;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8944,6 +9077,10 @@
 ALboolean ALmixer_SetVolumeSource(ALuint source, ALfloat volume)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return AL_FALSE;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8957,6 +9094,10 @@
 ALfloat ALmixer_GetVolumeChannel(ALint channel)
 {
 	ALfloat retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1.0f;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8970,6 +9111,10 @@
 ALfloat ALmixer_GetVolumeSource(ALuint source)
 {
 	ALfloat retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1.0f;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8983,6 +9128,10 @@
 ALboolean ALmixer_SetMaxVolumeChannel(ALint channel, ALfloat volume)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return AL_FALSE;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -8996,6 +9145,10 @@
 ALboolean ALmixer_SetMaxVolumeSource(ALuint source, ALfloat volume)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return AL_FALSE;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9009,6 +9162,10 @@
 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel)
 {
 	ALfloat retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1.0f;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9022,6 +9179,10 @@
 ALfloat ALmixer_GetMaxVolumeSource(ALuint source)
 {
 	ALfloat retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1.0f;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9036,6 +9197,10 @@
 ALboolean ALmixer_SetMinVolumeChannel(ALint channel, ALfloat volume)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return AL_FALSE;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9049,6 +9214,10 @@
 ALboolean ALmixer_SetMinVolumeSource(ALuint source, ALfloat volume)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return AL_FALSE;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9062,6 +9231,10 @@
 ALfloat ALmixer_GetMinVolumeChannel(ALint channel)
 {
 	ALfloat retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1.0f;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9075,6 +9248,10 @@
 ALfloat ALmixer_GetMinVolumeSource(ALuint source)
 {
 	ALfloat retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1.0f;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9090,6 +9267,10 @@
 ALboolean ALmixer_SetMasterVolume(ALfloat volume)
 {
 	ALboolean retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return AL_FALSE;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9103,6 +9284,10 @@
 ALfloat ALmixer_GetMasterVolume()
 {
 	ALfloat retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1.0f;
+	}		
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9116,6 +9301,10 @@
 ALint ALmixer_ExpireChannel(ALint channel, ALint ticks)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9129,6 +9318,10 @@
 ALint ALmixer_ExpireSource(ALuint source, ALint ticks)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9142,6 +9335,10 @@
 ALint ALmixer_IsActiveChannel(ALint channel)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9155,6 +9352,10 @@
 ALint ALmixer_IsActiveSource(ALuint source)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9169,6 +9370,10 @@
 ALint ALmixer_IsPlayingChannel(ALint channel)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9182,6 +9387,10 @@
 ALint ALmixer_IsPlayingSource(ALuint source)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9196,6 +9405,10 @@
 ALint ALmixer_IsPausedChannel(ALint channel)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9209,6 +9422,10 @@
 ALint ALmixer_IsPausedSource(ALuint source)
 {
 	ALint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return -1;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9223,6 +9440,10 @@
 ALuint ALmixer_CountAllFreeChannels()
 {
 	ALuint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9236,6 +9457,10 @@
 ALuint ALmixer_CountUnreservedFreeChannels()
 {
 	ALuint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9249,6 +9474,10 @@
 ALuint ALmixer_CountAllUsedChannels()
 {
 	ALuint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif
@@ -9262,6 +9491,10 @@
 ALuint ALmixer_CountUnreservedUsedChannels()
 {
 	ALuint retval;
+	if(0 == ALmixer_Initialized)
+	{
+		return 0;
+	}
 #ifdef ENABLE_ALMIXER_THREADS
 	SDL_LockMutex(s_simpleLock);
 #endif