comparison ALmixer.c @ 6:4b1048af7e55

Disabled some of the debugging printfs
author Eric Wing <ewing . public |-at-| gmail . com>
date Thu, 28 Oct 2010 02:32:46 -0700
parents a929285e1db0
children c808684660a7
comparison
equal deleted inserted replaced
5:8cb13d89451a 6:4b1048af7e55
504 { 504 {
505 fprintf(stderr, "Error in PrintQueueStatus, Can't get buffers_processed: %s\n", 505 fprintf(stderr, "Error in PrintQueueStatus, Can't get buffers_processed: %s\n",
506 alGetString(error)); 506 alGetString(error));
507 } 507 }
508 508
509 /*
509 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", 510 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n",
510 source, 511 source,
511 buffers_queued, 512 buffers_queued,
512 buffers_processed); 513 buffers_processed);
513 514 */
514 } 515 }
515 516
516 517
517 518
518 static void Init_Channel(ALint channel) 519 static void Init_Channel(ALint channel)
519 { 520 {
520
521 fprintf(stderr, "Init channel %d\n", channel);
522 ALmixer_Channel_List[channel].channel_in_use = 0; 521 ALmixer_Channel_List[channel].channel_in_use = 0;
523 ALmixer_Channel_List[channel].callback_update = 0; 522 ALmixer_Channel_List[channel].callback_update = 0;
524 ALmixer_Channel_List[channel].needs_stream = 0; 523 ALmixer_Channel_List[channel].needs_stream = 0;
525 ALmixer_Channel_List[channel].paused = 0; 524 ALmixer_Channel_List[channel].paused = 0;
526 ALmixer_Channel_List[channel].halted = 0; 525 ALmixer_Channel_List[channel].halted = 0;
1122 data->sample->desired.format, 1121 data->sample->desired.format,
1123 AL_FALSE 1122 AL_FALSE
1124 ); 1123 );
1125 } 1124 }
1126 1125
1127 /* From SDL_Sound's playsound. Converts milliseconds to byte positions. 1126 /* Converts milliseconds to byte positions.
1128 * This is needed for seeking on predecoded samples 1127 * This is needed for seeking on predecoded samples
1129 */ 1128 */
1130 static ALuint Convert_Msec_To_Byte_Pos(Sound_AudioInfo *info, ALuint ms) 1129 static ALuint Convert_Msec_To_Byte_Pos(Sound_AudioInfo *info, ALuint ms)
1131 { 1130 {
1132 float frames_per_ms; 1131 float frames_per_ms;
1133 ALuint frame_offset; 1132 ALuint frame_offset;
1134 ALuint frame_size; 1133 ALuint frame_size;
1135 fprintf(stderr, "In convert\n" );
1136 if(info == NULL) 1134 if(info == NULL)
1137 { 1135 {
1138 fprintf(stderr, "Error, info is NULL\n"); 1136 fprintf(stderr, "Error, info is NULL\n");
1139 } 1137 }
1140 else
1141 {
1142 fprintf(stderr, "Not an error: info is not NULL\n");
1143 }
1144 fprintf(stderr, "The rate=%d\n", info->rate);
1145 1138
1146 /* "frames" == "sample frames" */ 1139 /* "frames" == "sample frames" */
1147 frames_per_ms = ((float) info->rate) / 1000.0f; 1140 frames_per_ms = ((float) info->rate) / 1000.0f;
1148 fprintf(stderr, "%f\n", frames_per_ms);
1149 frame_offset = (ALuint) (frames_per_ms * ((float) ms)); 1141 frame_offset = (ALuint) (frames_per_ms * ((float) ms));
1150 fprintf(stderr, "%d\n", frame_offset);
1151 frame_size = (ALuint) ((info->format & 0xFF) / 8) * info->channels; 1142 frame_size = (ALuint) ((info->format & 0xFF) / 8) * info->channels;
1152 fprintf(stderr, "%d\n", frame_size); 1143 return frame_offset * frame_size;
1153 return(frame_offset * frame_size); 1144 }
1154 } /* cvtMsToBytePos */
1155 1145
1156 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) 1146 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position)
1157 { 1147 {
1158 ALenum error; 1148 ALenum error;
1159 /* clear error */ 1149 /* clear error */
1161 1151
1162 /* Is it greater than, or greater-than or equal to ?? */ 1152 /* Is it greater than, or greater-than or equal to ?? */
1163 if(byte_position > data->total_bytes) 1153 if(byte_position > data->total_bytes)
1164 { 1154 {
1165 /* We can't go past the end, so set to end? */ 1155 /* We can't go past the end, so set to end? */
1156 /*
1166 fprintf(stderr, "Error, can't seek past end\n"); 1157 fprintf(stderr, "Error, can't seek past end\n");
1167 1158 */
1159
1168 /* In case the below thing doesn't work, 1160 /* In case the below thing doesn't work,
1169 * just rewind the whole thing. 1161 * just rewind the whole thing.
1170 * 1162 *
1171 alBufferData(data->buffer[0], 1163 alBufferData(data->buffer[0],
1172 TranslateFormat(&data->sample->desired), 1164 TranslateFormat(&data->sample->desired),
1242 return -1; 1234 return -1;
1243 } 1235 }
1244 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); 1236 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers);
1245 if(-1 == index) 1237 if(-1 == index)
1246 { 1238 {
1239 /*
1247 fprintf(stderr, ">>>>>>>CopyData catch, albuffer=%d\n",buffer); 1240 fprintf(stderr, ">>>>>>>CopyData catch, albuffer=%d\n",buffer);
1241 */
1248 return -1; 1242 return -1;
1249 } 1243 }
1250 /* Copy the data to the access buffer */ 1244 /* Copy the data to the access buffer */
1251 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); 1245 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes);
1252 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; 1246 data->buffer_map_list[index].num_bytes = data->sample->buffer_size;
1380 */ 1374 */
1381 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); 1375 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded);
1382 /* Now reset the bytes_decoded to reflect the entire 1376 /* Now reset the bytes_decoded to reflect the entire
1383 * buffer to tell alBufferData what our full size is. 1377 * buffer to tell alBufferData what our full size is.
1384 */ 1378 */
1379 /*
1385 fprintf(stderr, "ALTERED bytes decoded for silence: Original end was %d\n", bytes_decoded); 1380 fprintf(stderr, "ALTERED bytes decoded for silence: Original end was %d\n", bytes_decoded);
1381 */
1386 bytes_decoded = data->sample->buffer_size; 1382 bytes_decoded = data->sample->buffer_size;
1387 } 1383 }
1388 /*********** END EXPERIMENT ******************************/ 1384 /*********** END EXPERIMENT ******************************/
1389 /******* END REMOVE ME ********************************/ 1385 /******* END REMOVE ME ********************************/
1390 #endif 1386 #endif
1688 return -1; 1684 return -1;
1689 } 1685 }
1690 /* If the user specified a specific channel */ 1686 /* If the user specified a specific channel */
1691 if(channel >= 0) 1687 if(channel >= 0)
1692 { 1688 {
1693 fprintf(stderr, "Halt on channel %d\n", channel);
1694 /* only need to process channel if in use */ 1689 /* only need to process channel if in use */
1695 if(ALmixer_Channel_List[channel].channel_in_use) 1690 if(ALmixer_Channel_List[channel].channel_in_use)
1696 { 1691 {
1697 alSourceStop(ALmixer_Channel_List[channel].alsource); 1692 alSourceStop(ALmixer_Channel_List[channel].alsource);
1698 if((error = alGetError()) != AL_NO_ERROR) 1693 if((error = alGetError()) != AL_NO_ERROR)
1710 * Creative Windows, and CoreAudio seem to leave the 1705 * Creative Windows, and CoreAudio seem to leave the
1711 * buffer queued (Old Mac didn't.) For queued, we need to 1706 * buffer queued (Old Mac didn't.) For queued, we need to
1712 * remove the processed buffers and force remove the 1707 * remove the processed buffers and force remove the
1713 * still-queued buffers. 1708 * still-queued buffers.
1714 */ 1709 */
1715 fprintf(stderr, "Halt on channel %d, channel in use\n", channel);
1716 alGetSourcei( 1710 alGetSourcei(
1717 ALmixer_Channel_List[channel].alsource, 1711 ALmixer_Channel_List[channel].alsource,
1718 AL_BUFFERS_QUEUED, &buffers_still_queued 1712 AL_BUFFERS_QUEUED, &buffers_still_queued
1719 ); 1713 );
1720 if((error = alGetError()) != AL_NO_ERROR) 1714 if((error = alGetError()) != AL_NO_ERROR)
1768 else 1762 else
1769 { 1763 {
1770 ALint i; 1764 ALint i;
1771 for(i=0; i<Number_of_Channels_global; i++) 1765 for(i=0; i<Number_of_Channels_global; i++)
1772 { 1766 {
1773 fprintf(stderr, "Halting channel %d\n", i);
1774 fprintf(stderr, "in use %d\n", ALmixer_Channel_List[i].channel_in_use );
1775 /* only need to process channel if in use */ 1767 /* only need to process channel if in use */
1776 if(ALmixer_Channel_List[i].channel_in_use) 1768 if(ALmixer_Channel_List[i].channel_in_use)
1777 { 1769 {
1778 fprintf(stderr, "SourceStop %d\n", i);
1779 alSourceStop(ALmixer_Channel_List[i].alsource); 1770 alSourceStop(ALmixer_Channel_List[i].alsource);
1780 if((error = alGetError()) != AL_NO_ERROR) 1771 if((error = alGetError()) != AL_NO_ERROR)
1781 { 1772 {
1782 fprintf(stderr, "19Testing error: %s\n", 1773 fprintf(stderr, "19Testing error: %s\n",
1783 alGetString(error)); 1774 alGetString(error));
1793 * Creative Windows, and CoreAudio seem to leave the 1784 * Creative Windows, and CoreAudio seem to leave the
1794 * buffer queued (Old Mac didn't.) For queued, we need to 1785 * buffer queued (Old Mac didn't.) For queued, we need to
1795 * remove the processed buffers and force remove the 1786 * remove the processed buffers and force remove the
1796 * still-queued buffers. 1787 * still-queued buffers.
1797 */ 1788 */
1798 fprintf(stderr, "Halt on channel %d, channel in use\n", channel);
1799 alGetSourcei( 1789 alGetSourcei(
1800 ALmixer_Channel_List[i].alsource, 1790 ALmixer_Channel_List[i].alsource,
1801 AL_BUFFERS_QUEUED, &buffers_still_queued 1791 AL_BUFFERS_QUEUED, &buffers_still_queued
1802 ); 1792 );
1803 if((error = alGetError()) != AL_NO_ERROR) 1793 if((error = alGetError()) != AL_NO_ERROR)
1838 } 1828 }
1839 } 1829 }
1840 1830
1841 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; 1831 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0;
1842 1832
1843 fprintf(stderr, "Clean channel %d\n", i);
1844 Clean_Channel(i); 1833 Clean_Channel(i);
1845 Is_Playing_global--; 1834 Is_Playing_global--;
1846 /* Launch callback for consistency? */ 1835 /* Launch callback for consistency? */
1847 fprintf(stderr, "Callback%d\n", i);
1848 Invoke_Channel_Done_Callback(i, did_finish_naturally); 1836 Invoke_Channel_Done_Callback(i, did_finish_naturally);
1849 1837
1850 /* Increment the counter */ 1838 /* Increment the counter */
1851 counter++; 1839 counter++;
1852 } 1840 }
2044 /* Okay, we assume Halt or natural stop has already 2032 /* Okay, we assume Halt or natural stop has already
2045 * cleared the data buffers 2033 * cleared the data buffers
2046 */ 2034 */
2047 if(data->in_use) 2035 if(data->in_use)
2048 { 2036 {
2037 /*
2049 fprintf(stderr, "Warning sample is in use. May not be able to rewind\n"); 2038 fprintf(stderr, "Warning sample is in use. May not be able to rewind\n");
2039 */
2050 /* 2040 /*
2051 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); 2041 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n");
2052 return -1; 2042 return -1;
2053 */ 2043 */
2054 } 2044 }
2098 return 0; 2088 return 0;
2099 } 2089 }
2100 2090
2101 /* Remaining stuff for streamed data */ 2091 /* Remaining stuff for streamed data */
2102 2092
2103 fprintf(stderr, "Rewinding for stream\n");
2104 data->eof = 0; 2093 data->eof = 0;
2105 retval = Sound_Rewind(data->sample); 2094 retval = Sound_Rewind(data->sample);
2106 if(0 == retval) 2095 if(0 == retval)
2107 { 2096 {
2108 ALmixer_SetError( Sound_GetError() ); 2097 ALmixer_SetError( Sound_GetError() );
2109 return -1; 2098 return -1;
2110 } 2099 }
2111 fprintf(stderr, "Rewinding succeeded\n");
2112 fprintf(stderr, "calling GetMoreData for Rewinding for stream\n");
2113 #if 0 2100 #if 0
2114 /* Clear error */ 2101 /* Clear error */
2115 alGetError(); 2102 alGetError();
2116 for(i=0; i<data->num_buffers; i++) 2103 for(i=0; i<data->num_buffers; i++)
2117 { 2104 {
2128 2115
2129 } 2116 }
2130 #endif 2117 #endif
2131 2118
2132 2119
2133 fprintf(stderr, "end Rewinding for stream\n");
2134 2120
2135 return retval; 2121 return retval;
2136 } 2122 }
2137 2123
2138 2124
2236 else 2222 else
2237 { 2223 {
2238 ALint i; 2224 ALint i;
2239 for(i=0; i<Number_of_Channels_global; i++) 2225 for(i=0; i<Number_of_Channels_global; i++)
2240 { 2226 {
2241 fprintf(stderr, "in use %d\n", ALmixer_Channel_List[i].channel_in_use );
2242 /* only need to process channel if in use */ 2227 /* only need to process channel if in use */
2243 if(ALmixer_Channel_List[i].channel_in_use) 2228 if(ALmixer_Channel_List[i].channel_in_use)
2244 { 2229 {
2245 /* What should I do? Do I just rewind the channel 2230 /* What should I do? Do I just rewind the channel
2246 * or also rewind the data? Since the data is 2231 * or also rewind the data? Since the data is
2556 * before the last buffer is filled. 2541 * before the last buffer is filled.
2557 * Stop conditions are we run out of 2542 * Stop conditions are we run out of
2558 * data or we max out our preload buffers. 2543 * data or we max out our preload buffers.
2559 */ 2544 */
2560 2545
2546 /*
2561 fprintf(stderr, "Filling buffer #%d (AL id is %d)\n", 0, data->buffer[0]); 2547 fprintf(stderr, "Filling buffer #%d (AL id is %d)\n", 0, data->buffer[0]);
2548 */
2562 for(j=1; j<data->num_startup_buffers; j++) 2549 for(j=1; j<data->num_startup_buffers; j++)
2563 { 2550 {
2551 /*
2564 fprintf(stderr, "Filling buffer #%d (AL id is %d)\n", j, data->buffer[j]); 2552 fprintf(stderr, "Filling buffer #%d (AL id is %d)\n", j, data->buffer[j]);
2565 /*
2566 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); 2553 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n");
2567 */ 2554 */
2568 bytes_returned = GetMoreData( 2555 bytes_returned = GetMoreData(
2569 data, 2556 data,
2570 data->buffer[j]); 2557 data->buffer[j]);
2589 { 2576 {
2590 /* No more data to buffer */ 2577 /* No more data to buffer */
2591 /* Check for loops */ 2578 /* Check for loops */
2592 if( ALmixer_Channel_List[channel].loops != 0 ) 2579 if( ALmixer_Channel_List[channel].loops != 0 )
2593 { 2580 {
2581 /*
2594 fprintf(stderr, "Need to rewind. In RAMPUP, handling loop\n"); 2582 fprintf(stderr, "Need to rewind. In RAMPUP, handling loop\n");
2583 */
2595 if(0 == Sound_Rewind(data->sample)) 2584 if(0 == Sound_Rewind(data->sample))
2596 { 2585 {
2597 fprintf(stderr, "error in rewind\n"); 2586 fprintf(stderr, "error in rewind\n");
2598 ALmixer_SetError( Sound_GetError() ); 2587 ALmixer_SetError( Sound_GetError() );
2599 ALmixer_Channel_List[channel].loops = 0; 2588 ALmixer_Channel_List[channel].loops = 0;
2604 /* Remember to reset the data->eof flag */ 2593 /* Remember to reset the data->eof flag */
2605 data->eof = 0; 2594 data->eof = 0;
2606 if(ALmixer_Channel_List[channel].loops > 0) 2595 if(ALmixer_Channel_List[channel].loops > 0)
2607 { 2596 {
2608 ALmixer_Channel_List[channel].loops--; 2597 ALmixer_Channel_List[channel].loops--;
2598 /*
2609 fprintf(stderr, "Inside 000 >>>>>>>>>>Loops=%d\n", ALmixer_Channel_List[channel].loops); 2599 fprintf(stderr, "Inside 000 >>>>>>>>>>Loops=%d\n", ALmixer_Channel_List[channel].loops);
2600 */
2610 } 2601 }
2611 /* Would like to redo the loop, but due to 2602 /* Would like to redo the loop, but due to
2612 * Sound_Rewind() bugs, we would risk falling 2603 * Sound_Rewind() bugs, we would risk falling
2613 * into an infinite loop 2604 * into an infinite loop
2614 */ 2605 */
2779 alGetError(); 2770 alGetError();
2780 2771
2781 /* If the user specified a specific channel */ 2772 /* If the user specified a specific channel */
2782 if(channel >= 0) 2773 if(channel >= 0)
2783 { 2774 {
2784 fprintf(stderr, "Pause on channel %d\n", channel);
2785 /* only need to process channel if in use */ 2775 /* only need to process channel if in use */
2786 if(ALmixer_Channel_List[channel].channel_in_use) 2776 if(ALmixer_Channel_List[channel].channel_in_use)
2787 { 2777 {
2788 /* We don't want to repause if already 2778 /* We don't want to repause if already
2789 * paused because the fadeout/expire 2779 * paused because the fadeout/expire
2863 else 2853 else
2864 { 2854 {
2865 ALint i; 2855 ALint i;
2866 for(i=0; i<Number_of_Channels_global; i++) 2856 for(i=0; i<Number_of_Channels_global; i++)
2867 { 2857 {
2868 fprintf(stderr, "Pausing channel %d\n", i);
2869 fprintf(stderr, "in use %d\n", ALmixer_Channel_List[i].channel_in_use );
2870 /* only need to process channel if in use */ 2858 /* only need to process channel if in use */
2871 if(ALmixer_Channel_List[i].channel_in_use) 2859 if(ALmixer_Channel_List[i].channel_in_use)
2872 { 2860 {
2873 /* We don't want to repause if already 2861 /* We don't want to repause if already
2874 * paused because the fadeout/expire 2862 * paused because the fadeout/expire
2886 if(AL_PLAYING == state) 2874 if(AL_PLAYING == state)
2887 { 2875 {
2888 /* Count the actual number of channels being paused */ 2876 /* Count the actual number of channels being paused */
2889 counter++; 2877 counter++;
2890 2878
2891 fprintf(stderr, "SourcePause %d\n", i);
2892 alSourcePause(ALmixer_Channel_List[i].alsource); 2879 alSourcePause(ALmixer_Channel_List[i].alsource);
2893 if((error = alGetError()) != AL_NO_ERROR) 2880 if((error = alGetError()) != AL_NO_ERROR)
2894 { 2881 {
2895 ALmixer_SetError("%s", 2882 ALmixer_SetError("%s",
2896 alGetString(error) ); 2883 alGetString(error) );
2995 alGetError(); 2982 alGetError();
2996 2983
2997 /* If the user specified a specific channel */ 2984 /* If the user specified a specific channel */
2998 if(channel >= 0) 2985 if(channel >= 0)
2999 { 2986 {
3000 fprintf(stderr, "Pause on channel %d\n", channel);
3001 /* only need to process channel if in use */ 2987 /* only need to process channel if in use */
3002 if(ALmixer_Channel_List[channel].channel_in_use) 2988 if(ALmixer_Channel_List[channel].channel_in_use)
3003 { 2989 {
3004 alGetSourcei( 2990 alGetSourcei(
3005 ALmixer_Channel_List[channel].alsource, 2991 ALmixer_Channel_List[channel].alsource,
3032 ALmixer_SetError("%s", 3018 ALmixer_SetError("%s",
3033 alGetString(error) ); 3019 alGetString(error) );
3034 retval = -1; 3020 retval = -1;
3035 } 3021 }
3036 } 3022 }
3037 fprintf(stderr, "Pause on channel %d, channel in use\n", channel);
3038 } 3023 }
3039 } 3024 }
3040 /* The user wants to halt all channels */ 3025 /* The user wants to halt all channels */
3041 else 3026 else
3042 { 3027 {
3043 ALint i; 3028 ALint i;
3044 for(i=0; i<Number_of_Channels_global; i++) 3029 for(i=0; i<Number_of_Channels_global; i++)
3045 { 3030 {
3046 fprintf(stderr, "Pausing channel %d\n", i);
3047 fprintf(stderr, "in use %d\n", ALmixer_Channel_List[i].channel_in_use );
3048 /* only need to process channel if in use */ 3031 /* only need to process channel if in use */
3049 if(ALmixer_Channel_List[i].channel_in_use) 3032 if(ALmixer_Channel_List[i].channel_in_use)
3050 { 3033 {
3051 fprintf(stderr, "SourcePause %d\n", i);
3052 alGetSourcei( 3034 alGetSourcei(
3053 ALmixer_Channel_List[i].alsource, 3035 ALmixer_Channel_List[i].alsource,
3054 AL_SOURCE_STATE, &state 3036 AL_SOURCE_STATE, &state
3055 ); 3037 );
3056 if((error = alGetError()) != AL_NO_ERROR) 3038 if((error = alGetError()) != AL_NO_ERROR)
3175 { 3157 {
3176 ALmixer_SetError("Cannot seek because access_data flag was set false when data was initialized"); 3158 ALmixer_SetError("Cannot seek because access_data flag was set false when data was initialized");
3177 return -1; 3159 return -1;
3178 } 3160 }
3179 3161
3180 fprintf(stderr, "Calling convert\n");
3181 byte_position = Convert_Msec_To_Byte_Pos(&data->sample->desired, msec); 3162 byte_position = Convert_Msec_To_Byte_Pos(&data->sample->desired, msec);
3182 fprintf(stderr, "Calling Set_Predecoded_Seek...%d\n", byte_position);
3183 return( Set_Predecoded_Seek_Position(data, byte_position) ); 3163 return( Set_Predecoded_Seek_Position(data, byte_position) );
3184 } 3164 }
3185 else 3165 else
3186 { 3166 {
3187 /* Reset eof flag?? */ 3167 /* Reset eof flag?? */
3266 { 3246 {
3267 fprintf(stderr, "36Testing error: %s\n", 3247 fprintf(stderr, "36Testing error: %s\n",
3268 alGetString(error)); 3248 alGetString(error));
3269 } 3249 }
3270 ALmixer_Channel_List[channel].fade_start_volume = value; 3250 ALmixer_Channel_List[channel].fade_start_volume = value;
3271 fprintf(stderr, "MIN gain: %f\n", value);
3272 3251
3273 /* Set the actual volume */ 3252 /* Set the actual volume */
3274 alSourcef(ALmixer_Channel_List[channel].alsource, 3253 alSourcef(ALmixer_Channel_List[channel].alsource,
3275 AL_GAIN, value); 3254 AL_GAIN, value);
3276 if((error = alGetError()) != AL_NO_ERROR) 3255 if((error = alGetError()) != AL_NO_ERROR)
3323 /* Enable fading effects via the flag */ 3302 /* Enable fading effects via the flag */
3324 ALmixer_Channel_List[channel].fade_enabled = 1; 3303 ALmixer_Channel_List[channel].fade_enabled = 1;
3325 /* Set fade start time */ 3304 /* Set fade start time */
3326 ALmixer_Channel_List[channel].fade_start_time 3305 ALmixer_Channel_List[channel].fade_start_time
3327 = ALmixer_Channel_List[channel].start_time; 3306 = ALmixer_Channel_List[channel].start_time;
3328 fprintf(stderr, "Current time =%d\n", current_time);
3329 /* Set the fade expire ticks */ 3307 /* Set the fade expire ticks */
3330 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; 3308 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks;
3331 3309
3332 /* Set 1/(endtime-starttime) or 1/deltaT */ 3310 /* Set 1/(endtime-starttime) or 1/deltaT */
3333 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; 3311 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks;
3422 { 3400 {
3423 fprintf(stderr, "41Testing error: %s\n", 3401 fprintf(stderr, "41Testing error: %s\n",
3424 alGetString(error)); 3402 alGetString(error));
3425 } 3403 }
3426 ALmixer_Channel_List[channel].fade_end_volume = value; 3404 ALmixer_Channel_List[channel].fade_end_volume = value;
3427 fprintf(stderr, "MIN gain: %f\n", value);
3428 3405
3429 /* Set expire start time */ 3406 /* Set expire start time */
3430 ALmixer_Channel_List[channel].start_time = current_time; 3407 ALmixer_Channel_List[channel].start_time = current_time;
3431 /* Set the expire ticks */ 3408 /* Set the expire ticks */
3432 ALmixer_Channel_List[channel].expire_ticks = ticks; 3409 ALmixer_Channel_List[channel].expire_ticks = ticks;
3468 { 3445 {
3469 fprintf(stderr, "43Testing error: %s\n", 3446 fprintf(stderr, "43Testing error: %s\n",
3470 alGetString(error)); 3447 alGetString(error));
3471 } 3448 }
3472 ALmixer_Channel_List[i].fade_end_volume = value; 3449 ALmixer_Channel_List[i].fade_end_volume = value;
3473 fprintf(stderr, "MIN gain: %f\n", value);
3474 3450
3475 /* Set expire start time */ 3451 /* Set expire start time */
3476 ALmixer_Channel_List[i].start_time = current_time; 3452 ALmixer_Channel_List[i].start_time = current_time;
3477 /* Set the expire ticks */ 3453 /* Set the expire ticks */
3478 ALmixer_Channel_List[i].expire_ticks = ticks; 3454 ALmixer_Channel_List[i].expire_ticks = ticks;
5436 #if 0 5412 #if 0
5437 else if(0 == bytes_returned) 5413 else if(0 == bytes_returned)
5438 #endif 5414 #endif
5439 if(0 == bytes_returned) 5415 if(0 == bytes_returned)
5440 { 5416 {
5417 /*
5441 fprintf(stderr, "We got 0 bytes from reading. Checking for loops\n"); 5418 fprintf(stderr, "We got 0 bytes from reading. Checking for loops\n");
5419 */
5442 /* Check for loops */ 5420 /* Check for loops */
5443 if( ALmixer_Channel_List[i].loops != 0 ) 5421 if( ALmixer_Channel_List[i].loops != 0 )
5444 { 5422 {
5445 /* We have to loop, so rewind 5423 /* We have to loop, so rewind
5446 * and fetch more data 5424 * and fetch more data
5447 */ 5425 */
5426 /*
5448 fprintf(stderr, "Rewinding data\n"); 5427 fprintf(stderr, "Rewinding data\n");
5428 */
5449 if(0 == Sound_Rewind( 5429 if(0 == Sound_Rewind(
5450 ALmixer_Channel_List[i].almixer_data->sample)) 5430 ALmixer_Channel_List[i].almixer_data->sample))
5451 { 5431 {
5452 fprintf(stderr, "Rewinding failed\n"); 5432 fprintf(stderr, "Rewinding failed\n");
5453 ALmixer_SetError( Sound_GetError() ); 5433 ALmixer_SetError( Sound_GetError() );
5467 * buffer, we don't want to lose it. 5447 * buffer, we don't want to lose it.
5468 */ 5448 */
5469 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use 5449 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use
5470 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) 5450 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers)
5471 { 5451 {
5452 /*
5472 fprintf(stderr, "We got %d bytes from reading loop. Filling unused packet\n", bytes_returned); 5453 fprintf(stderr, "We got %d bytes from reading loop. Filling unused packet\n", bytes_returned);
5454 */
5473 /* Grab next packet */ 5455 /* Grab next packet */
5474 bytes_returned = GetMoreData( 5456 bytes_returned = GetMoreData(
5475 ALmixer_Channel_List[i].almixer_data, 5457 ALmixer_Channel_List[i].almixer_data,
5476 ALmixer_Channel_List[i].almixer_data->buffer[ 5458 ALmixer_Channel_List[i].almixer_data->buffer[
5477 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] 5459 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use]
5478 ); 5460 );
5461 /*
5479 fprintf(stderr, "We reread %d bytes into unused packet\n", bytes_returned); 5462 fprintf(stderr, "We reread %d bytes into unused packet\n", bytes_returned);
5463 */
5480 } 5464 }
5481 /* Refilling unqueued packet */ 5465 /* Refilling unqueued packet */
5482 else 5466 else
5483 { 5467 {
5468 /*
5484 fprintf(stderr, "We got %d bytes from reading loop. Filling unqueued packet\n", bytes_returned); 5469 fprintf(stderr, "We got %d bytes from reading loop. Filling unqueued packet\n", bytes_returned);
5470 */
5485 /* Grab next packet */ 5471 /* Grab next packet */
5486 bytes_returned = GetMoreData( 5472 bytes_returned = GetMoreData(
5487 ALmixer_Channel_List[i].almixer_data, 5473 ALmixer_Channel_List[i].almixer_data,
5488 unqueued_buffer_id); 5474 unqueued_buffer_id);
5475 /*
5489 fprintf(stderr, "We reread %d bytes into unqueued packet\n", bytes_returned); 5476 fprintf(stderr, "We reread %d bytes into unqueued packet\n", bytes_returned);
5477 */
5490 } 5478 }
5491 /* Another error check */ 5479 /* Another error check */
5492 /* 5480 /*
5493 if(bytes_returned <= 0) 5481 if(bytes_returned <= 0)
5494 */ 5482 */
5745 * to have to create an array for the 5733 * to have to create an array for the
5746 * unqueued_buffer_id's 5734 * unqueued_buffer_id's
5747 */ 5735 */
5748 for(temp_count=0; temp_count<buffers_processed; temp_count++) 5736 for(temp_count=0; temp_count<buffers_processed; temp_count++)
5749 { 5737 {
5738 /*
5750 fprintf(stderr, "unqueuing remainder, %d\n", temp_count); 5739 fprintf(stderr, "unqueuing remainder, %d\n", temp_count);
5740 */
5751 alSourceUnqueueBuffers( 5741 alSourceUnqueueBuffers(
5752 ALmixer_Channel_List[i].alsource, 5742 ALmixer_Channel_List[i].alsource,
5753 1, &unqueued_buffer_id 5743 1, &unqueued_buffer_id
5754 ); 5744 );
5755 if((error = alGetError()) != AL_NO_ERROR) 5745 if((error = alGetError()) != AL_NO_ERROR)
5756 { 5746 {
5757 fprintf(stderr, "59Testing error: %s\n", 5747 fprintf(stderr, "59Testing error: %s\n",
5758 alGetString(error)); 5748 alGetString(error));
5759 } 5749 }
5760 } 5750 }
5751 /*
5761 fprintf(stderr, "done unqueuing remainder for this loop, %d\n", temp_count); 5752 fprintf(stderr, "done unqueuing remainder for this loop, %d\n", temp_count);
5762 5753 */
5754
5763 /* Need to update counts since we removed everything. 5755 /* Need to update counts since we removed everything.
5764 * If we don't update the counts here, we end up in the 5756 * If we don't update the counts here, we end up in the
5765 * "Shouldn't be here section, but maybe it's okay due to race conditions" 5757 * "Shouldn't be here section, but maybe it's okay due to race conditions"
5766 */ 5758 */
5767 alGetSourcei( 5759 alGetSourcei(
5847 fprintf(stderr, "61Testing error: %s\n", 5839 fprintf(stderr, "61Testing error: %s\n",
5848 alGetString(error)); 5840 alGetString(error));
5849 } 5841 }
5850 if(AL_STOPPED == state) 5842 if(AL_STOPPED == state)
5851 { 5843 {
5844 /*
5852 fprintf(stderr, "Shouldn't be here. %d Buffers still in queue, but play stopped. This might be correct though because race conditions could have caused the STOP to happen right after our other tests...Checking queue status...\n", buffers_still_queued); 5845 fprintf(stderr, "Shouldn't be here. %d Buffers still in queue, but play stopped. This might be correct though because race conditions could have caused the STOP to happen right after our other tests...Checking queue status...\n", buffers_still_queued);
5846 */
5853 /* 5847 /*
5854 PrintQueueStatus(ALmixer_Channel_List[i].alsource); 5848 PrintQueueStatus(ALmixer_Channel_List[i].alsource);
5855 */ 5849 */
5856 /* Rather than force unqueuing the buffer, let's see if 5850 /* Rather than force unqueuing the buffer, let's see if
5857 * setting the buffer to none works (the OpenAL 1.0 5851 * setting the buffer to none works (the OpenAL 1.0
5942 { 5936 {
5943 /* should I also be sleeping/yielding here? */ 5937 /* should I also be sleeping/yielding here? */
5944 ALmixer_Delay(0); 5938 ALmixer_Delay(0);
5945 } 5939 }
5946 } 5940 }
5941 /*
5947 fprintf(stderr, "Thread is closing\n"); 5942 fprintf(stderr, "Thread is closing\n");
5943 */
5948 return 0; 5944 return 0;
5949 } 5945 }
5950 #endif /* End of ENABLE_ALMIXER_THREADS */ 5946 #endif /* End of ENABLE_ALMIXER_THREADS */
5951 5947
5952 5948
6070 /* Make sure ALmixer isn't already initialized */ 6066 /* Make sure ALmixer isn't already initialized */
6071 if(ALmixer_Initialized) 6067 if(ALmixer_Initialized)
6072 { 6068 {
6073 return AL_FALSE; 6069 return AL_FALSE;
6074 } 6070 }
6075 #ifdef USING_LOKI_AL_DIST
6076 fprintf(stderr, "Found Loki dist\n");
6077 #elif defined(USING_CREATIVE_AL_DIST)
6078 fprintf(stderr, "Found Creative dist\n");
6079
6080 #elif defined(USING_NVIDIA_AL_DIST)
6081 fprintf(stderr, "Found Nvidia dist\n");
6082 #endif
6083 6071
6084 #ifdef ALMIXER_COMPILE_WITHOUT_SDL 6072 #ifdef ALMIXER_COMPILE_WITHOUT_SDL
6085 ALmixer_InitTime(); 6073 ALmixer_InitTime();
6086 6074
6087 /* Note: The pool may have been created on previous Init's */ 6075 /* Note: The pool may have been created on previous Init's */
6095 } 6083 }
6096 if(NULL == s_ALmixerErrorPool) 6084 if(NULL == s_ALmixerErrorPool)
6097 { 6085 {
6098 return AL_FALSE; 6086 return AL_FALSE;
6099 } 6087 }
6088 /*
6100 fprintf(stderr, "tError Test0\n"); 6089 fprintf(stderr, "tError Test0\n");
6101 ALmixer_SetError("Initing (and testing SetError)"); 6090 ALmixer_SetError("Initing (and testing SetError)");
6102 fprintf(stderr, "tError Test1: %s\n", ALmixer_GetError()); 6091 fprintf(stderr, "tError Test1: %s\n", ALmixer_GetError());
6103 fprintf(stderr, "tError Test2: %s\n", ALmixer_GetError()); 6092 fprintf(stderr, "tError Test2: %s\n", ALmixer_GetError());
6093 */
6104 #endif 6094 #endif
6105 6095
6106 6096
6107 /* Set the defaults */ 6097 /* Set the defaults */
6108 /* 6098 /*
6181 else 6171 else
6182 { 6172 {
6183 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; 6173 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8;
6184 } 6174 }
6185 SDL_CloseAudio(); 6175 SDL_CloseAudio();
6186 fprintf(stderr, "Obtained format = %d", obtained.format);
6187 } 6176 }
6188 else 6177 else
6189 { 6178 {
6190 /* Well, I guess I'm in trouble. I guess it's my best guess 6179 /* Well, I guess I'm in trouble. I guess it's my best guess
6191 */ 6180 */
6226 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); 6215 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]);
6227 dev = alcOpenDevice( (const ALubyte *) device_string ); 6216 dev = alcOpenDevice( (const ALubyte *) device_string );
6228 #else 6217 #else
6229 dev = alcOpenDevice( NULL ); 6218 dev = alcOpenDevice( NULL );
6230 #endif 6219 #endif
6231 fprintf(stderr,"sampling-rate is %d\n", attrlist[1]);
6232 if(NULL == dev) 6220 if(NULL == dev)
6233 { 6221 {
6234 ALmixer_SetError("Cannot open sound device for OpenAL"); 6222 ALmixer_SetError("Cannot open sound device for OpenAL");
6235 return AL_FALSE; 6223 return AL_FALSE;
6236 } 6224 }
6241 if(0 != frequency) 6229 if(0 != frequency)
6242 { 6230 {
6243 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); 6231 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency);
6244 } 6232 }
6245 ALmixer_Frequency_global = (ALuint)Internal_alcMacOSXGetMixerOutputRate(); 6233 ALmixer_Frequency_global = (ALuint)Internal_alcMacOSXGetMixerOutputRate();
6234 /*
6246 fprintf(stderr, "Internal_alcMacOSXMixerOutputRate is: %lf", Internal_alcMacOSXGetMixerOutputRate()); 6235 fprintf(stderr, "Internal_alcMacOSXMixerOutputRate is: %lf", Internal_alcMacOSXGetMixerOutputRate());
6236 */
6247 #endif 6237 #endif
6248 6238
6249 context = alcCreateContext(dev, attrlist); 6239 context = alcCreateContext(dev, attrlist);
6250 if(NULL == context) 6240 if(NULL == context)
6251 { 6241 {
6252 ALmixer_SetError("Cannot create a context OpenAL"); 6242 ALmixer_SetError("Cannot create a context OpenAL");
6253 alcCloseDevice(dev); 6243 alcCloseDevice(dev);
6254 return AL_FALSE; 6244 return AL_FALSE;
6255 } 6245 }
6256 fprintf(stderr, "Context checking...\n");
6257 6246
6258 6247
6259 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, 6248 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent,
6260 * but ALC_NO_ERROR is defined to ALC_FALSE. 6249 * but ALC_NO_ERROR is defined to ALC_FALSE.
6261 * According to Garin Hiebert, this is actually an inconsistency 6250 * According to Garin Hiebert, this is actually an inconsistency
6286 /* 6275 /*
6287 ALmixer_Frequency_global = frequency; 6276 ALmixer_Frequency_global = frequency;
6288 */ 6277 */
6289 #ifndef __APPLE__ 6278 #ifndef __APPLE__
6290 alcGetIntegerv(dev, ALC_FREQUENCY, 1, &ALmixer_Frequency_global); 6279 alcGetIntegerv(dev, ALC_FREQUENCY, 1, &ALmixer_Frequency_global);
6280 /*
6291 fprintf(stderr, "alcGetIntegerv ALC_FREQUENCY is: %d", ALmixer_Frequency_global); 6281 fprintf(stderr, "alcGetIntegerv ALC_FREQUENCY is: %d", ALmixer_Frequency_global);
6282 */
6292 #endif 6283 #endif
6293 6284
6294 6285
6295 #if 0 6286 #if 0
6296 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ 6287 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */
6317 } 6308 }
6318 #endif 6309 #endif
6319 6310
6320 6311
6321 /* #endif */ 6312 /* #endif */
6322 fprintf(stderr, "done Context\n");
6323 /* Saw this in the README with the OS X OpenAL distribution. 6313 /* Saw this in the README with the OS X OpenAL distribution.
6324 * It looked interesting and simple, so I thought I might 6314 * It looked interesting and simple, so I thought I might
6325 * try it out. 6315 * try it out.
6326 * ***** ALC_CONVERT_DATA_UPON_LOADING 6316 * ***** ALC_CONVERT_DATA_UPON_LOADING
6327 * This extension allows the caller to tell OpenAL to preconvert to the native Core 6317 * This extension allows the caller to tell OpenAL to preconvert to the native Core
6340 6330
6341 #else 6331 #else
6342 #endif 6332 #endif
6343 */ 6333 */
6344 ALenum convert_data_enum = alcGetEnumValue(dev, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING"); 6334 ALenum convert_data_enum = alcGetEnumValue(dev, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING");
6335 /*
6345 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING=0x%x", convert_data_enum); 6336 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING=0x%x", convert_data_enum);
6337 */
6346 if(0 != convert_data_enum) 6338 if(0 != convert_data_enum)
6347 { 6339 {
6348 alEnable(convert_data_enum); 6340 alEnable(convert_data_enum);
6349 } 6341 }
6350 if( (AL_NO_ERROR != alGetError()) ) 6342 if( (AL_NO_ERROR != alGetError()) )
6351 { 6343 {
6344 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed");
6352 ALmixer_SetError("ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); 6345 ALmixer_SetError("ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed");
6353 } 6346 }
6354 6347
6355 #endif 6348 #endif
6356 6349
6458 6451
6459 /* The Source_Map_List must be sorted by source for binary searches 6452 /* The Source_Map_List must be sorted by source for binary searches
6460 */ 6453 */
6461 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); 6454 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map);
6462 6455
6463 fprintf(stderr, "Sorted Source_Map_List is:\n"); 6456 /*
6464 for(i=0; i<Number_of_Channels_global; i++)
6465 {
6466 fprintf(stderr, "Source: %d, Channel: %d\n", Source_Map_List[i].source, Source_Map_List[i].channel);
6467 }
6468 fprintf(stderr, "\n");
6469 ALmixer_OutputDecoders(); 6457 ALmixer_OutputDecoders();
6470 6458 */
6471 #ifdef ENABLE_ALMIXER_THREADS 6459 #ifdef ENABLE_ALMIXER_THREADS
6472 s_simpleLock = SDL_CreateMutex(); 6460 s_simpleLock = SDL_CreateMutex();
6473 if(NULL == s_simpleLock) 6461 if(NULL == s_simpleLock)
6474 { 6462 {
6475 /* SDL sets the error message already? */ 6463 /* SDL sets the error message already? */
6497 ALmixer_Initialized = 0; 6485 ALmixer_Initialized = 0;
6498 Number_of_Channels_global = 0; 6486 Number_of_Channels_global = 0;
6499 return AL_FALSE; 6487 return AL_FALSE;
6500 } 6488 }
6501 6489
6490 /*
6502 fprintf(stderr, "Using threads\n"); 6491 fprintf(stderr, "Using threads\n");
6492 */
6503 #endif /* End of ENABLE_ALMIXER_THREADS */ 6493 #endif /* End of ENABLE_ALMIXER_THREADS */
6504 6494
6505 /* We don't need this array any more because all the sources 6495 /* We don't need this array any more because all the sources
6506 * are connected to channels 6496 * are connected to channels
6507 */ 6497 */
6621 /* Make sure ALmixer isn't already initialized */ 6611 /* Make sure ALmixer isn't already initialized */
6622 if(ALmixer_Initialized) 6612 if(ALmixer_Initialized)
6623 { 6613 {
6624 return AL_FALSE; 6614 return AL_FALSE;
6625 } 6615 }
6626 #ifdef USING_LOKI_AL_DIST
6627 fprintf(stderr, "Found Loki dist\n");
6628 #elif defined(USING_CREATIVE_AL_DIST)
6629 fprintf(stderr, "Found Creative dist\n");
6630
6631 #elif defined(USING_NVIDIA_AL_DIST)
6632 fprintf(stderr, "Found Nvidia dist\n");
6633 #endif
6634 6616
6635 /* Set the defaults */ 6617 /* Set the defaults */
6636 attrlist[0] = ALC_FREQUENCY; 6618 attrlist[0] = ALC_FREQUENCY;
6637 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; 6619 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY;
6638 attrlist[2] = ALC_SYNC; 6620 attrlist[2] = ALC_SYNC;
6708 else 6690 else
6709 { 6691 {
6710 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; 6692 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8;
6711 } 6693 }
6712 SDL_CloseAudio(); 6694 SDL_CloseAudio();
6713 fprintf(stderr, "Obtained format = %d", obtained.format);
6714 } 6695 }
6715 else 6696 else
6716 { 6697 {
6717 /* Well, I guess I'm in trouble. I guess it's my best guess 6698 /* Well, I guess I'm in trouble. I guess it's my best guess
6718 */ 6699 */
6753 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); 6734 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]);
6754 dev = alcOpenDevice( (const ALubyte *) device_string ); 6735 dev = alcOpenDevice( (const ALubyte *) device_string );
6755 #else 6736 #else
6756 dev = alcOpenDevice( NULL ); 6737 dev = alcOpenDevice( NULL );
6757 #endif 6738 #endif
6758 fprintf(stderr,"sampling-rate is %d\n", attrlist[1]);
6759 if(NULL == dev) 6739 if(NULL == dev)
6760 { 6740 {
6761 ALmixer_SetError("Cannot open sound device for OpenAL"); 6741 ALmixer_SetError("Cannot open sound device for OpenAL");
6762 return AL_FALSE; 6742 return AL_FALSE;
6763 } 6743 }
6768 if(0 != frequency) 6748 if(0 != frequency)
6769 { 6749 {
6770 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); 6750 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency);
6771 } 6751 }
6772 ALmixer_Frequency_global = (ALuint)Internal_alcMacOSXGetMixerOutputRate(); 6752 ALmixer_Frequency_global = (ALuint)Internal_alcMacOSXGetMixerOutputRate();
6753 /*
6773 fprintf(stderr, "Internal_alcMacOSXMixerOutputRate is: %lf", Internal_alcMacOSXGetMixerOutputRate()); 6754 fprintf(stderr, "Internal_alcMacOSXMixerOutputRate is: %lf", Internal_alcMacOSXGetMixerOutputRate());
6755 */
6774 #endif 6756 #endif
6775 6757
6776 6758
6777 context = alcCreateContext(dev, attrlist); 6759 context = alcCreateContext(dev, attrlist);
6778 if(NULL == context) 6760 if(NULL == context)
6837 * dist (2003/01/02) to handle this. 6819 * dist (2003/01/02) to handle this.
6838 * The demo is in testattrib.c. 6820 * The demo is in testattrib.c.
6839 */ 6821 */
6840 #ifndef __APPLE__ 6822 #ifndef __APPLE__
6841 alcGetIntegerv(dev, ALC_FREQUENCY, 1, &ALmixer_Frequency_global); 6823 alcGetIntegerv(dev, ALC_FREQUENCY, 1, &ALmixer_Frequency_global);
6824 /*
6842 fprintf(stderr, "alcGetIntegerv ALC_FREQUENCY is: %d", ALmixer_Frequency_global); 6825 fprintf(stderr, "alcGetIntegerv ALC_FREQUENCY is: %d", ALmixer_Frequency_global);
6843 #endif 6826 */
6844 6827 #endif
6845 6828
6846 fprintf(stderr, "done Context\n"); 6829
6847 6830
6848 /* Saw this in the README with the OS X OpenAL distribution. 6831 /* Saw this in the README with the OS X OpenAL distribution.
6849 * It looked interesting and simple, so I thought I might 6832 * It looked interesting and simple, so I thought I might
6850 * try it out. 6833 * try it out.
6851 * ***** ALC_CONVERT_DATA_UPON_LOADING 6834 * ***** ALC_CONVERT_DATA_UPON_LOADING
6865 6848
6866 #else 6849 #else
6867 #endif 6850 #endif
6868 */ 6851 */
6869 ALenum convert_data_enum = alcGetEnumValue(dev, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING"); 6852 ALenum convert_data_enum = alcGetEnumValue(dev, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING");
6853 /*
6870 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING=0x%x", convert_data_enum); 6854 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING=0x%x", convert_data_enum);
6855 */
6871 if(0 != convert_data_enum) 6856 if(0 != convert_data_enum)
6872 { 6857 {
6873 alEnable(convert_data_enum); 6858 alEnable(convert_data_enum);
6874 } 6859 }
6875 if( (AL_NO_ERROR != alGetError()) ) 6860 if( (AL_NO_ERROR != alGetError()) )
6876 { 6861 {
6862 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed");
6877 ALmixer_SetError("ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); 6863 ALmixer_SetError("ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed");
6878 } 6864 }
6879 #endif 6865 #endif
6880 6866
6881 return AL_TRUE; 6867 return AL_TRUE;
7002 6988
7003 /* The Source_Map_List must be sorted by source for binary searches 6989 /* The Source_Map_List must be sorted by source for binary searches
7004 */ 6990 */
7005 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); 6991 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map);
7006 6992
7007 fprintf(stderr, "Sorted Source_Map_List is:\n");
7008 for(i=0; i<Number_of_Channels_global; i++)
7009 {
7010 fprintf(stderr, "Source: %d, Channel: %d\n", Source_Map_List[i].source, Source_Map_List[i].channel);
7011 }
7012 fprintf(stderr, "\n");
7013
7014
7015 6993
7016 #ifdef ENABLE_ALMIXER_THREADS 6994 #ifdef ENABLE_ALMIXER_THREADS
7017 s_simpleLock = SDL_CreateMutex(); 6995 s_simpleLock = SDL_CreateMutex();
7018 if(NULL == s_simpleLock) 6996 if(NULL == s_simpleLock)
7019 { 6997 {
7038 ALmixer_Initialized = 0; 7016 ALmixer_Initialized = 0;
7039 Number_of_Channels_global = 0; 7017 Number_of_Channels_global = 0;
7040 return AL_FALSE; 7018 return AL_FALSE;
7041 } 7019 }
7042 7020
7021 /*
7043 fprintf(stderr, "Using threads\n"); 7022 fprintf(stderr, "Using threads\n");
7023 */
7044 #endif /* End of ENABLE_ALMIXER_THREADS */ 7024 #endif /* End of ENABLE_ALMIXER_THREADS */
7045 7025
7046 /* We don't need this array any more because all the sources 7026 /* We don't need this array any more because all the sources
7047 * are connected to channels 7027 * are connected to channels
7048 */ 7028 */
7067 } 7047 }
7068 #ifdef ENABLE_ALMIXER_THREADS 7048 #ifdef ENABLE_ALMIXER_THREADS
7069 SDL_LockMutex(s_simpleLock); 7049 SDL_LockMutex(s_simpleLock);
7070 #endif 7050 #endif
7071 /* Shutdown everything before closing context */ 7051 /* Shutdown everything before closing context */
7072 fprintf(stderr, "Halting channels\n");
7073 Internal_HaltChannel(-1, AL_FALSE); 7052 Internal_HaltChannel(-1, AL_FALSE);
7074 7053
7075 /* This flag will cause the thread to terminate */ 7054 /* This flag will cause the thread to terminate */
7076 ALmixer_Initialized = 0; 7055 ALmixer_Initialized = 0;
7077 #ifdef ENABLE_ALMIXER_THREADS 7056 #ifdef ENABLE_ALMIXER_THREADS
7078 SDL_UnlockMutex(s_simpleLock); 7057 SDL_UnlockMutex(s_simpleLock);
7079 fprintf(stderr, "Closing thread\n");
7080 SDL_WaitThread(Stream_Thread_global, NULL); 7058 SDL_WaitThread(Stream_Thread_global, NULL);
7081 7059
7082 fprintf(stderr, "Destroying mutex\n");
7083 SDL_DestroyMutex(s_simpleLock); 7060 SDL_DestroyMutex(s_simpleLock);
7084 #endif 7061 #endif
7085 7062
7086 fprintf(stderr, "Deleting OpenAL sources\n");
7087 /* Delete all the OpenAL sources */ 7063 /* Delete all the OpenAL sources */
7088 for(i=0; i<Number_of_Channels_global; i++) 7064 for(i=0; i<Number_of_Channels_global; i++)
7089 { 7065 {
7090 fprintf(stderr, "Deleting OpenAL source: %d\n", ALmixer_Channel_List[i].alsource);
7091 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); 7066 alDeleteSources(1, &ALmixer_Channel_List[i].alsource);
7092 } 7067 }
7093 /* Delete all the channels */ 7068 /* Delete all the channels */
7094 free(ALmixer_Channel_List); 7069 free(ALmixer_Channel_List);
7095 free(Source_Map_List); 7070 free(Source_Map_List);
7443 * decoded, so we can treat it like one. 7418 * decoded, so we can treat it like one.
7444 */ 7419 */
7445 7420
7446 if(sample->flags & SOUND_SAMPLEFLAG_EOF) 7421 if(sample->flags & SOUND_SAMPLEFLAG_EOF)
7447 { 7422 {
7423 /*
7448 fprintf(stderr, "We got LUCKY! File is predecoded even though STREAM was requested\n"); 7424 fprintf(stderr, "We got LUCKY! File is predecoded even though STREAM was requested\n");
7449 7425 */
7450 ret_data->decoded_all = 1; 7426 ret_data->decoded_all = 1;
7451 /* Need to keep this information around for 7427 /* Need to keep this information around for
7452 * seek and rewind abilities. 7428 * seek and rewind abilities.
7453 */ 7429 */
7454 ret_data->total_bytes = bytes_decoded; 7430 ret_data->total_bytes = bytes_decoded;
7552 } 7528 }
7553 /* Else, we need to stream the data, so we'll 7529 /* Else, we need to stream the data, so we'll
7554 * create multple buffers for queuing */ 7530 * create multple buffers for queuing */
7555 else 7531 else
7556 { 7532 {
7533 /*
7557 fprintf(stderr, "Loading streamed data (not lucky)\n"); 7534 fprintf(stderr, "Loading streamed data (not lucky)\n");
7535 */
7558 ret_data->decoded_all = 0; 7536 ret_data->decoded_all = 0;
7559 7537
7560 /* This information is for predecoded. 7538 /* This information is for predecoded.
7561 * Set to 0, since we don't know. 7539 * Set to 0, since we don't know.
7562 */ 7540 */
7692 } /* End of do stream */ 7670 } /* End of do stream */
7693 } /* end of DECODE_STREAM */ 7671 } /* end of DECODE_STREAM */
7694 /* User requested decode all (easy, nothing to figure out) */ 7672 /* User requested decode all (easy, nothing to figure out) */
7695 else if(AL_TRUE == decode_mode_is_predecoded) 7673 else if(AL_TRUE == decode_mode_is_predecoded)
7696 { 7674 {
7697 #ifndef ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION 7675 #ifdef ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION
7698 /* SDL_sound (behind the scenes) seems to loop on buffer_size chunks 7676 /* SDL_sound (behind the scenes) seems to loop on buffer_size chunks
7699 * until the buffer is filled. It seems like we can 7677 * until the buffer is filled. It seems like we can
7700 * do much better and precompute the size of the buffer 7678 * do much better and precompute the size of the buffer
7701 * so looping isn't needed. 7679 * so looping isn't needed.
7702 * WARNING: Due to the way SDL_sound is currently implemented, 7680 * WARNING: Due to the way SDL_sound is currently implemented,
7775 Sound_FreeSample(sample); 7753 Sound_FreeSample(sample);
7776 free(ret_data->buffer); 7754 free(ret_data->buffer);
7777 free(ret_data); 7755 free(ret_data);
7778 return NULL; 7756 return NULL;
7779 } 7757 }
7758 /*
7780 fprintf(stderr, "Actual rate=%d, desired=%d\n", sample->actual.rate, sample->desired.rate); 7759 fprintf(stderr, "Actual rate=%d, desired=%d\n", sample->actual.rate, sample->desired.rate);
7781 7760 */
7782 /* Now copy the data to the OpenAL buffer */ 7761 /* Now copy the data to the OpenAL buffer */
7783 /* We can't just set a pointer because the API needs 7762 /* We can't just set a pointer because the API needs
7784 * its own copy to assist hardware acceleration */ 7763 * its own copy to assist hardware acceleration */
7785 alBufferData(ret_data->buffer[0], 7764 alBufferData(ret_data->buffer[0],
7786 TranslateFormat(&sample->desired), 7765 TranslateFormat(&sample->desired),
7835 * so don't do anything. 7814 * so don't do anything.
7836 */ 7815 */
7837 #endif 7816 #endif
7838 #endif 7817 #endif
7839 7818
7840 fprintf(stderr, "Made it\n");
7841 /* okay we're done here */ 7819 /* okay we're done here */
7842 } 7820 }
7843 else 7821 else
7844 { 7822 {
7845 /* Shouldn't get here */ 7823 /* Shouldn't get here */
7847 Sound_FreeSample(sample); 7825 Sound_FreeSample(sample);
7848 free(ret_data); 7826 free(ret_data);
7849 return NULL; 7827 return NULL;
7850 } 7828 }
7851 7829
7852 fprintf(stderr, "Returning data\n");
7853 return ret_data; 7830 return ret_data;
7854 } 7831 }
7855 7832
7856 7833
7857 /* This will load a sample for us. Most of the uglyness is 7834 /* This will load a sample for us. Most of the uglyness is
7998 { 7975 {
7999 ALmixer_SetError(Sound_GetError()); 7976 ALmixer_SetError(Sound_GetError());
8000 return NULL; 7977 return NULL;
8001 } 7978 }
8002 7979
7980 /*
8003 fprintf(stderr, "Correction test: Actual rate=%d, desired=%d, actual format=%d, desired format=%d\n", sample->actual.rate, sample->desired.rate, sample->actual.format, sample->desired.format); 7981 fprintf(stderr, "Correction test: Actual rate=%d, desired=%d, actual format=%d, desired format=%d\n", sample->actual.rate, sample->desired.rate, sample->actual.format, sample->desired.format);
8004 7982 */
8005 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); 7983 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data));
8006 } 7984 }
8007 7985
8008 7986
8009 /* This is a back door for RAW samples or if you need the 7987 /* This is a back door for RAW samples or if you need the