changeset 49:4b0268d86298

Fixed bug with seeking channels with predecoded samples. The OpenAL 1.1 spec specifies that a playing source should automatically jump when already playing. The code was unnecessarily recalling alPlaySource again which is not necessarily the correct thing to do. I think the previous code is another remnant of the Open 1.0 era. Also fixed bugs in the return codes for seek and rewind. For single channels, the return code was 0 channels processed in ALmixer which resulted in returning false to Lua. The implementation now should return 1/true for single channels, but 0/false for no channels. Errors will return -1/false.
author Eric Wing <ewing@anscamobile.com>
date Fri, 30 Sep 2011 17:48:23 -0700
parents 00b770b0d2aa
children db5bc1c80057
files ALmixer.c
diffstat 1 files changed, 24 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/ALmixer.c	Fri Sep 30 16:44:08 2011 -0700
+++ b/ALmixer.c	Fri Sep 30 17:48:23 2011 -0700
@@ -1695,7 +1695,6 @@
 static ALboolean Internal_DetachBuffersFromSource(ALuint source_id, ALboolean is_predecoded)
 {
 	ALboolean retval = AL_TRUE;
-	ALint buffers_processed;
 	ALenum error;
 	/* Here's the situation. My old method of using
 	 * alSourceUnqueueBuffers() seemed to be invalid in light
@@ -2225,7 +2224,7 @@
 		/* only need to process channel if in use */
 		if(ALmixer_Channel_List[channel].channel_in_use)
 		{
-
+			running_count = 1;
 			/* What should I do? Do I just rewind the channel
 			 * or also rewind the data? Since the data is
 			 * shared, let's make it the user's responsibility
@@ -2289,7 +2288,10 @@
 				 * much data is queued. Recommend users call Halt
 				 * before rewind if they want immediate results.
 				 */
-				retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data);
+				if(AL_FALSE == Internal_RewindData(ALmixer_Channel_List[channel].almixer_data))
+				{
+					retval = -1;
+				}
 			}
 		}
 	}
@@ -2302,6 +2304,7 @@
 			/* only need to process channel if in use */
 			if(ALmixer_Channel_List[i].channel_in_use)
 			{
+				running_count++;
 				/* What should I do? Do I just rewind the channel
 				 * or also rewind the data? Since the data is
 				 * shared, let's make it the user's responsibility
@@ -2365,7 +2368,10 @@
 					 * much data is queued. Recommend users call Halt
 					 * before rewind if they want immediate results.
 					 */
-					running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data);
+					if(AL_FALSE == Internal_RewindData(ALmixer_Channel_List[i].almixer_data))
+					{
+						retval = -1;
+					}
 				}
 			}
 		}
@@ -3337,18 +3343,8 @@
 									 alGetString(error) );
 					retval = -1;
 				}
-				/* Need to resume playback if it was originally playing */
-				if(AL_PLAYING == state)
-				{
-					alSourcePlay(ALmixer_Channel_List[channel].alsource);
-					if((error = alGetError()) != AL_NO_ERROR)
-					{
-						ALmixer_SetError("%s",
-										 alGetString(error) );
-						retval = -1;
-					}
-				}
-				else if(AL_PAUSED == state)
+				/* OpenAL 1.1 spec says if this succeeds on a playing source, it will automatically jump */
+				if(AL_PAUSED == state)
 				{
 					/* HACK: The problem is that when paused, after
 					 * the Rewind, I can't get it off the INITIAL
@@ -3377,8 +3373,12 @@
 				 * much data is queued. Recommend users call Halt
 				 * before rewind if they want immediate results.
 				 */
-				retval = Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec);
+				if(AL_FALSE == Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec))
+				{
+					retval = -1;
+				}
 			}
+			running_count = 1;
 		}
 	}
 	/* The user wants to rewind all channels */
@@ -3409,6 +3409,7 @@
 								alGetString(error));				
 					}
 
+					/* OpenAL 1.1 spec says if this succeeds on a playing source, it will automatically jump */
 					alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset);
 					if((error = alGetError()) != AL_NO_ERROR)
 					{
@@ -3416,18 +3417,7 @@
 										 alGetString(error) );
 						retval = -1;
 					}
-					/* Need to resume playback if it was originally playing */
-					if(AL_PLAYING == state)
-					{
-						alSourcePlay(ALmixer_Channel_List[i].alsource);
-						if((error = alGetError()) != AL_NO_ERROR)
-						{
-							ALmixer_SetError("%s",
-											 alGetString(error) );
-							retval = -1;
-						}
-					}
-					else if(AL_PAUSED == state)
+					if(AL_PAUSED == state)
 					{
 						/* HACK: The problem is that when paused, after
 						 * the Rewind, I can't get it off the INITIAL
@@ -3456,8 +3446,12 @@
 					 * much data is queued. Recommend users call Halt
 					 * before rewind if they want immediate results.
 					 */
-					running_count += Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec);
+					if(AL_FALSE == Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec))
+					{
+						retval = -1;
+					}
 				}
+				running_count++;
 			}
 		}
 	}