Mercurial > almixer_isolated
comparison ALmixer.c @ 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 |
comparison
equal
deleted
inserted
replaced
48:00b770b0d2aa | 49:4b0268d86298 |
---|---|
1693 | 1693 |
1694 | 1694 |
1695 static ALboolean Internal_DetachBuffersFromSource(ALuint source_id, ALboolean is_predecoded) | 1695 static ALboolean Internal_DetachBuffersFromSource(ALuint source_id, ALboolean is_predecoded) |
1696 { | 1696 { |
1697 ALboolean retval = AL_TRUE; | 1697 ALboolean retval = AL_TRUE; |
1698 ALint buffers_processed; | |
1699 ALenum error; | 1698 ALenum error; |
1700 /* Here's the situation. My old method of using | 1699 /* Here's the situation. My old method of using |
1701 * alSourceUnqueueBuffers() seemed to be invalid in light | 1700 * alSourceUnqueueBuffers() seemed to be invalid in light |
1702 * of all the problems I suffered through with getting | 1701 * of all the problems I suffered through with getting |
1703 * the CoreData backend to work with this code. | 1702 * the CoreData backend to work with this code. |
2223 if(channel >= 0) | 2222 if(channel >= 0) |
2224 { | 2223 { |
2225 /* only need to process channel if in use */ | 2224 /* only need to process channel if in use */ |
2226 if(ALmixer_Channel_List[channel].channel_in_use) | 2225 if(ALmixer_Channel_List[channel].channel_in_use) |
2227 { | 2226 { |
2228 | 2227 running_count = 1; |
2229 /* What should I do? Do I just rewind the channel | 2228 /* What should I do? Do I just rewind the channel |
2230 * or also rewind the data? Since the data is | 2229 * or also rewind the data? Since the data is |
2231 * shared, let's make it the user's responsibility | 2230 * shared, let's make it the user's responsibility |
2232 * to rewind the data. | 2231 * to rewind the data. |
2233 */ | 2232 */ |
2287 * does no good. Rewinding the data will have an | 2286 * does no good. Rewinding the data will have an |
2288 * effect, but it will be lagged based on how | 2287 * effect, but it will be lagged based on how |
2289 * much data is queued. Recommend users call Halt | 2288 * much data is queued. Recommend users call Halt |
2290 * before rewind if they want immediate results. | 2289 * before rewind if they want immediate results. |
2291 */ | 2290 */ |
2292 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | 2291 if(AL_FALSE == Internal_RewindData(ALmixer_Channel_List[channel].almixer_data)) |
2292 { | |
2293 retval = -1; | |
2294 } | |
2293 } | 2295 } |
2294 } | 2296 } |
2295 } | 2297 } |
2296 /* The user wants to rewind all channels */ | 2298 /* The user wants to rewind all channels */ |
2297 else | 2299 else |
2300 for(i=0; i<Number_of_Channels_global; i++) | 2302 for(i=0; i<Number_of_Channels_global; i++) |
2301 { | 2303 { |
2302 /* only need to process channel if in use */ | 2304 /* only need to process channel if in use */ |
2303 if(ALmixer_Channel_List[i].channel_in_use) | 2305 if(ALmixer_Channel_List[i].channel_in_use) |
2304 { | 2306 { |
2307 running_count++; | |
2305 /* What should I do? Do I just rewind the channel | 2308 /* What should I do? Do I just rewind the channel |
2306 * or also rewind the data? Since the data is | 2309 * or also rewind the data? Since the data is |
2307 * shared, let's make it the user's responsibility | 2310 * shared, let's make it the user's responsibility |
2308 * to rewind the data. | 2311 * to rewind the data. |
2309 */ | 2312 */ |
2363 * does no good. Rewinding the data will have an | 2366 * does no good. Rewinding the data will have an |
2364 * effect, but it will be lagged based on how | 2367 * effect, but it will be lagged based on how |
2365 * much data is queued. Recommend users call Halt | 2368 * much data is queued. Recommend users call Halt |
2366 * before rewind if they want immediate results. | 2369 * before rewind if they want immediate results. |
2367 */ | 2370 */ |
2368 running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data); | 2371 if(AL_FALSE == Internal_RewindData(ALmixer_Channel_List[i].almixer_data)) |
2372 { | |
2373 retval = -1; | |
2374 } | |
2369 } | 2375 } |
2370 } | 2376 } |
2371 } | 2377 } |
2372 } | 2378 } |
2373 if(-1 == retval) | 2379 if(-1 == retval) |
3335 { | 3341 { |
3336 ALmixer_SetError("%s", | 3342 ALmixer_SetError("%s", |
3337 alGetString(error) ); | 3343 alGetString(error) ); |
3338 retval = -1; | 3344 retval = -1; |
3339 } | 3345 } |
3340 /* Need to resume playback if it was originally playing */ | 3346 /* OpenAL 1.1 spec says if this succeeds on a playing source, it will automatically jump */ |
3341 if(AL_PLAYING == state) | 3347 if(AL_PAUSED == state) |
3342 { | |
3343 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3344 if((error = alGetError()) != AL_NO_ERROR) | |
3345 { | |
3346 ALmixer_SetError("%s", | |
3347 alGetString(error) ); | |
3348 retval = -1; | |
3349 } | |
3350 } | |
3351 else if(AL_PAUSED == state) | |
3352 { | 3348 { |
3353 /* HACK: The problem is that when paused, after | 3349 /* HACK: The problem is that when paused, after |
3354 * the Rewind, I can't get it off the INITIAL | 3350 * the Rewind, I can't get it off the INITIAL |
3355 * state without restarting | 3351 * state without restarting |
3356 */ | 3352 */ |
3375 * does no good. Rewinding the data will have an | 3371 * does no good. Rewinding the data will have an |
3376 * effect, but it will be lagged based on how | 3372 * effect, but it will be lagged based on how |
3377 * much data is queued. Recommend users call Halt | 3373 * much data is queued. Recommend users call Halt |
3378 * before rewind if they want immediate results. | 3374 * before rewind if they want immediate results. |
3379 */ | 3375 */ |
3380 retval = Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec); | 3376 if(AL_FALSE == Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec)) |
3377 { | |
3378 retval = -1; | |
3379 } | |
3381 } | 3380 } |
3381 running_count = 1; | |
3382 } | 3382 } |
3383 } | 3383 } |
3384 /* The user wants to rewind all channels */ | 3384 /* The user wants to rewind all channels */ |
3385 else | 3385 else |
3386 { | 3386 { |
3407 { | 3407 { |
3408 fprintf(stderr, "26Testing error: %s\n", | 3408 fprintf(stderr, "26Testing error: %s\n", |
3409 alGetString(error)); | 3409 alGetString(error)); |
3410 } | 3410 } |
3411 | 3411 |
3412 /* OpenAL 1.1 spec says if this succeeds on a playing source, it will automatically jump */ | |
3412 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); | 3413 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
3413 if((error = alGetError()) != AL_NO_ERROR) | 3414 if((error = alGetError()) != AL_NO_ERROR) |
3414 { | 3415 { |
3415 ALmixer_SetError("%s", | 3416 ALmixer_SetError("%s", |
3416 alGetString(error) ); | 3417 alGetString(error) ); |
3417 retval = -1; | 3418 retval = -1; |
3418 } | 3419 } |
3419 /* Need to resume playback if it was originally playing */ | 3420 if(AL_PAUSED == state) |
3420 if(AL_PLAYING == state) | |
3421 { | |
3422 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3423 if((error = alGetError()) != AL_NO_ERROR) | |
3424 { | |
3425 ALmixer_SetError("%s", | |
3426 alGetString(error) ); | |
3427 retval = -1; | |
3428 } | |
3429 } | |
3430 else if(AL_PAUSED == state) | |
3431 { | 3421 { |
3432 /* HACK: The problem is that when paused, after | 3422 /* HACK: The problem is that when paused, after |
3433 * the Rewind, I can't get it off the INITIAL | 3423 * the Rewind, I can't get it off the INITIAL |
3434 * state without restarting | 3424 * state without restarting |
3435 */ | 3425 */ |
3454 * does no good. Rewinding the data will have an | 3444 * does no good. Rewinding the data will have an |
3455 * effect, but it will be lagged based on how | 3445 * effect, but it will be lagged based on how |
3456 * much data is queued. Recommend users call Halt | 3446 * much data is queued. Recommend users call Halt |
3457 * before rewind if they want immediate results. | 3447 * before rewind if they want immediate results. |
3458 */ | 3448 */ |
3459 running_count += Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec); | 3449 if(AL_FALSE == Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec)) |
3450 { | |
3451 retval = -1; | |
3452 } | |
3460 } | 3453 } |
3454 running_count++; | |
3461 } | 3455 } |
3462 } | 3456 } |
3463 } | 3457 } |
3464 if(-1 == retval) | 3458 if(-1 == retval) |
3465 { | 3459 { |