comparison ALmixer.c @ 47:9b772c81b550

Added addition query to get the current number of buffers processed in the new inner buffer decoupling loop because I've been seeing a lot of 59TestingError warnings. I think it is possible the value may become stale after the first iteration of the loop resulting in assumption failures which result in triggering this error. Also changed some // comments to /* */ for C89 compliance.
author Eric Wing <ewing@anscamobile.com>
date Thu, 29 Sep 2011 11:33:34 -0700
parents 56855942fdc6
children 00b770b0d2aa
comparison
equal deleted inserted replaced
44:56855942fdc6 47:9b772c81b550
2687 { 2687 {
2688 ALuint k; 2688 ALuint k;
2689 ALuint queue_ret_flag; 2689 ALuint queue_ret_flag;
2690 for(k=0; k<data->num_buffers_in_use; k++) 2690 for(k=0; k<data->num_buffers_in_use; k++)
2691 { 2691 {
2692 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); 2692 /* fprintf(stderr, "56c: CircularQueue_PushBack.\n"); */
2693 queue_ret_flag = CircularQueueUnsignedInt_PushBack(data->circular_buffer_queue, data->buffer[k]); 2693 queue_ret_flag = CircularQueueUnsignedInt_PushBack(data->circular_buffer_queue, data->buffer[k]);
2694 if(0 == queue_ret_flag) 2694 if(0 == queue_ret_flag)
2695 { 2695 {
2696 fprintf(stderr, "Serious internal error: CircularQueue could not push into queue.\n"); 2696 fprintf(stderr, "Serious internal error: CircularQueue could not push into queue.\n");
2697 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); 2697 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue");
5274 * so we know if we need to refill 5274 * so we know if we need to refill
5275 */ 5275 */
5276 /* WARNING: It looks like Snow Leopard some times crashes on this call under x86_64 5276 /* WARNING: It looks like Snow Leopard some times crashes on this call under x86_64
5277 * typically when I suffer a lot of buffer underruns. 5277 * typically when I suffer a lot of buffer underruns.
5278 */ 5278 */
5279 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); 5279 /* fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); */
5280 alGetSourcei( 5280 alGetSourcei(
5281 ALmixer_Channel_List[i].alsource, 5281 ALmixer_Channel_List[i].alsource,
5282 AL_BUFFERS_PROCESSED, &buffers_processed 5282 AL_BUFFERS_PROCESSED, &buffers_processed
5283 ); 5283 );
5284 if((error = alGetError()) != AL_NO_ERROR) 5284 if((error = alGetError()) != AL_NO_ERROR)
5285 { 5285 {
5286 fprintf(stderr, "52Testing error: %s\n", 5286 fprintf(stderr, "52Testing error: %s\n",
5287 alGetString(error)); 5287 alGetString(error));
5288 } 5288 }
5289 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); 5289 /* fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); */
5290 5290
5291 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. 5291 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call.
5292 * I need this call to figure out which buffer OpenAL is currently playing. 5292 * I need this call to figure out which buffer OpenAL is currently playing.
5293 * It keeps returning an "Invalid Enum" error. 5293 * It keeps returning an "Invalid Enum" error.
5294 * This is totally inane! It's a basic query. 5294 * This is totally inane! It's a basic query.
5481 * If in an underrun, queue up at least startup_buffers. 5481 * If in an underrun, queue up at least startup_buffers.
5482 */ 5482 */
5483 if(AL_STOPPED == state) 5483 if(AL_STOPPED == state)
5484 { 5484 {
5485 number_of_buffers_to_queue_this_pass = ALmixer_Channel_List[i].almixer_data->num_startup_buffers; 5485 number_of_buffers_to_queue_this_pass = ALmixer_Channel_List[i].almixer_data->num_startup_buffers;
5486 // fprintf(stderr, "assuming underrun condition, using num_startup_buffers=%d\n", number_of_buffers_to_queue_this_pass); 5486 /* fprintf(stderr, "assuming underrun condition, using num_startup_buffers=%d\n", number_of_buffers_to_queue_this_pass); */
5487 } 5487 }
5488 5488
5489 /* Don't bother to check to make sure the number_of_buffers_to_queue_this_pass does not exceed the maximum number of buffers because of the logic hack bug. */ 5489 /* Don't bother to check to make sure the number_of_buffers_to_queue_this_pass does not exceed the maximum number of buffers because of the logic hack bug. */
5490 /* Logic Hack/Bug: In adding the number_of_buffers_to_queue_this_pass, I discovered the for-loop needs to be more decoupled. 5490 /* Logic Hack/Bug: In adding the number_of_buffers_to_queue_this_pass, I discovered the for-loop needs to be more decoupled.
5491 * The loop still needs to be entered because unqueuing and completion callbacks and possibly other state processing are also done. 5491 * The loop still needs to be entered because unqueuing and completion callbacks and possibly other state processing are also done.
5495 { 5495 {
5496 number_of_buffers_to_queue_this_pass = 1; 5496 number_of_buffers_to_queue_this_pass = 1;
5497 } 5497 }
5498 for(current_count_of_buffer_queue_passes=0; current_count_of_buffer_queue_passes<number_of_buffers_to_queue_this_pass; current_count_of_buffer_queue_passes++) 5498 for(current_count_of_buffer_queue_passes=0; current_count_of_buffer_queue_passes<number_of_buffers_to_queue_this_pass; current_count_of_buffer_queue_passes++)
5499 { 5499 {
5500 // fprintf(stderr, "current_count_of_buffer_queue_passes:%d\n", current_count_of_buffer_queue_passes); 5500 /* fprintf(stderr, "current_count_of_buffer_queue_passes:%d\n", current_count_of_buffer_queue_passes); */
5501
5502 /* Because I introduced this for-loop, I think I need to regrab the number of processed buffers because
5503 * the number may now be stale from previous iterations. I suppose I could do it at the end of the loop,
5504 * but the logic flow is already too complicated to ensure that the block is being hit.
5505 */
5506 /* Get the number of buffers processed
5507 */
5508 alGetSourcei(
5509 ALmixer_Channel_List[i].alsource,
5510 AL_BUFFERS_PROCESSED,
5511 &buffers_processed
5512 );
5513 if((error = alGetError()) != AL_NO_ERROR)
5514 {
5515 fprintf(stderr, "59aTestingError, Can't get buffers_processed: %s\n",
5516 alGetString(error));
5517 }
5518
5501 5519
5502 /* For this to work, we must rely on EVERYTHING 5520 /* For this to work, we must rely on EVERYTHING
5503 * else to unset the EOF if there is looping. 5521 * else to unset the EOF if there is looping.
5504 * Remember, even Play() must do this 5522 * Remember, even Play() must do this
5505 */ 5523 */
5916 * "access_data" was set, indicated by whether the queue is NULL. 5934 * "access_data" was set, indicated by whether the queue is NULL.
5917 */ 5935 */
5918 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) 5936 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL)
5919 { 5937 {
5920 ALuint queue_ret_flag; 5938 ALuint queue_ret_flag;
5921 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); 5939 /* fprintf(stderr, "56d: CircularQueue_PushBack.\n"); */
5922 queue_ret_flag = CircularQueueUnsignedInt_PushBack( 5940 queue_ret_flag = CircularQueueUnsignedInt_PushBack(
5923 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, 5941 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue,
5924 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] 5942 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use]
5925 ); 5943 );
5926 if(0 == queue_ret_flag) 5944 if(0 == queue_ret_flag)
5964 * "access_data" was set, indicated by whether the queue is NULL. 5982 * "access_data" was set, indicated by whether the queue is NULL.
5965 */ 5983 */
5966 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) 5984 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL)
5967 { 5985 {
5968 ALuint queue_ret_flag; 5986 ALuint queue_ret_flag;
5969 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); 5987 /* fprintf(stderr, "56e: CircularQueue_PushBack.\n"); */
5970 queue_ret_flag = CircularQueueUnsignedInt_PushBack( 5988 queue_ret_flag = CircularQueueUnsignedInt_PushBack(
5971 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, 5989 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue,
5972 unqueued_buffer_id 5990 unqueued_buffer_id
5973 ); 5991 );
5974 if(0 == queue_ret_flag) 5992 if(0 == queue_ret_flag)
7735 fprintf(stderr, "Error: You should not call ALmixer_SetError while ALmixer is not initialized\n"); 7753 fprintf(stderr, "Error: You should not call ALmixer_SetError while ALmixer is not initialized\n");
7736 return; 7754 return;
7737 } 7755 }
7738 va_list argp; 7756 va_list argp;
7739 va_start(argp, err_str); 7757 va_start(argp, err_str);
7740 // SDL_SetError which I'm emulating has no number parameter. 7758 /* SDL_SetError which I'm emulating has no number parameter. */
7741 TError_SetErrorv(s_ALmixerErrorPool, 1, err_str, argp); 7759 TError_SetErrorv(s_ALmixerErrorPool, 1, err_str, argp);
7742 va_end(argp); 7760 va_end(argp);
7743 } 7761 }
7744 7762
7745 #endif 7763 #endif
8266 while(j>0) 8284 while(j>0)
8267 { 8285 {
8268 free(ret_data->buffer_map_list[j].data); 8286 free(ret_data->buffer_map_list[j].data);
8269 j--; 8287 j--;
8270 } 8288 }
8271 // Delete for j=0 because the while loop misses the last one 8289 /* Delete for j=0 because the while loop misses the last one */
8272 free(ret_data->buffer_map_list[j].data); 8290 free(ret_data->buffer_map_list[j].data);
8273 8291
8274 free(ret_data->buffer_map_list); 8292 free(ret_data->buffer_map_list);
8275 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); 8293 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue);
8276 Sound_FreeSample(sample); 8294 Sound_FreeSample(sample);