comparison ALmixer.c @ 74:c112e4576832

Fixed remaining fading bug for pause/resume. My technique was wrong. I computed the amount of time remaining on pause and when I resumed, I grabbed the current time as the start and used the time remaining as the end. I think this is wrong because the volume curve may not be linear if I do this. Instead, I will try saving the time remaining, but preserve the original fade duration. Then I will adjust the start time for the amount already played. So I don't need to create another variable, I will overwrite the fade start.
author Eric Wing <ewing . public |-at-| gmail . com>
date Fri, 10 Aug 2012 23:38:56 -0700
parents 32757e494675
children 609d597b0dd9
comparison
equal deleted inserted replaced
73:32757e494675 74:c112e4576832
2940 } 2940 }
2941 /* Do the same as expire time for fading */ 2941 /* Do the same as expire time for fading */
2942 if(ALmixer_Channel_List[channel].fade_enabled) 2942 if(ALmixer_Channel_List[channel].fade_enabled)
2943 { 2943 {
2944 ALuint current_time = ALmixer_GetTicks(); 2944 ALuint current_time = ALmixer_GetTicks();
2945 ALuint diff_time; 2945 ALuint used_up_time;
2946 diff_time = current_time - 2946 used_up_time = current_time -
2947 ALmixer_Channel_List[channel].fade_start_time; 2947 ALmixer_Channel_List[channel].fade_start_time;
2948 /* When we unpause, we will want to reset 2948 /* When we unpause, we will want to reset
2949 * the start time so we can continue 2949 * the start time so we can continue
2950 * to base calculations off GetTicks(). 2950 * to base calculations off GetTicks().
2951 * This means we need to subtract the amount 2951 * I originally did this wrong. I computed the amount of time remaining
2952 * of time already used up from expire_ticks. 2952 * and when I resumed, I grabbed the current time as the start and used the time remaining as the end.
2953 * I think this is wrong because the volume curve may not be linear.
2954 * Instead, I will try saving the time remaining, but preserve the original fade duration.
2955 * Then I will adjust the start time for the amount already played.
2956 * So I don't need to create another variable, I will overwrite the start time with the remaining time.
2957 * (Resume needs to know this implementation detail.)
2953 */ 2958 */
2954 ALmixer_Channel_List[channel].fade_expire_ticks = 2959 ALmixer_Channel_List[channel].fade_start_time = used_up_time;
2955 ALmixer_Channel_List[channel].fade_expire_ticks -
2956 diff_time;
2957 /* Don't allow the time to go negative */
2958 if(ALmixer_Channel_List[channel].fade_expire_ticks < 0)
2959 {
2960 ALmixer_Channel_List[channel].fade_expire_ticks = 0;
2961 }
2962 } /* End fade check */ 2960 } /* End fade check */
2963 } /* End if PLAYING */ 2961 } /* End if PLAYING */
2964 } /* End If in use */ 2962 } /* End If in use */
2965 } /* End specific channel */ 2963 } /* End specific channel */
2966 /* The user wants to halt all channels */ 2964 /* The user wants to halt all channels */
3023 } 3021 }
3024 /* Do the same as expire time for fading */ 3022 /* Do the same as expire time for fading */
3025 if(ALmixer_Channel_List[i].fade_enabled) 3023 if(ALmixer_Channel_List[i].fade_enabled)
3026 { 3024 {
3027 ALuint current_time = ALmixer_GetTicks(); 3025 ALuint current_time = ALmixer_GetTicks();
3028 ALuint diff_time; 3026 ALuint used_up_time;
3029 diff_time = current_time - 3027 used_up_time = current_time -
3030 ALmixer_Channel_List[i].fade_start_time; 3028 ALmixer_Channel_List[i].fade_start_time;
3031 /* When we unpause, we will want to reset 3029 /* When we unpause, we will want to reset
3032 * the start time so we can continue 3030 * the start time so we can continue
3033 * to base calculations off GetTicks(). 3031 * to base calculations off GetTicks().
3034 * This means we need to subtract the amount 3032 * I originally did this wrong. I computed the amount of time remaining
3035 * of time already used up from expire_ticks. 3033 * and when I resumed, I grabbed the current time as the start and used the time remaining as the end.
3034 * I think this is wrong because the volume curve may not be linear.
3035 * Instead, I will try saving the time remaining, but preserve the original fade duration.
3036 * Then I will adjust the start time for the amount already played.
3037 * So I don't need to create another variable, I will overwrite the start time with the remaining time.
3038 * (Resume needs to know this implementation detail.)
3036 */ 3039 */
3037 ALmixer_Channel_List[i].fade_expire_ticks = 3040 ALmixer_Channel_List[i].fade_start_time = used_up_time;
3038 ALmixer_Channel_List[i].fade_expire_ticks -
3039 diff_time;
3040 /* Don't allow the time to go negative */
3041 if(ALmixer_Channel_List[i].fade_expire_ticks < 0)
3042 {
3043 ALmixer_Channel_List[i].fade_expire_ticks = 0;
3044 }
3045 } /* End fade check */ 3041 } /* End fade check */
3046 } /* End if PLAYING */ 3042 } /* End if PLAYING */
3047 } /* End channel in use */ 3043 } /* End channel in use */
3048 } /* End for-loop */ 3044 } /* End for-loop */
3049 } 3045 }
3121 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); 3117 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks();
3122 } 3118 }
3123 /* Do the same as expire time for fading */ 3119 /* Do the same as expire time for fading */
3124 if(ALmixer_Channel_List[channel].fade_enabled) 3120 if(ALmixer_Channel_List[channel].fade_enabled)
3125 { 3121 {
3126 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); 3122 /* I originally did this wrong. On pause, I computed the amount of time remaining
3127 } 3123 * and when I resumed, I grabbed the current time as the start and used the time remaining as the end.
3124 * I think this is wrong because the volume curve may not be linear.
3125 * Instead, I will try saving the time remaining, but preserve the original fade duration.
3126 * Then I will adjust the start time for the amount already played.
3127 * So I don't need to create another variable, I will overwrite the start time with the remaining time
3128 * (Resume needs to know this implementation detail.)
3129 */
3130 ALuint current_time = ALmixer_GetTicks();
3131 /* Recover the used_up_time from the overloaded fade_start_time variable */
3132 ALuint used_up_time = ALmixer_Channel_List[channel].fade_start_time;
3133 /* So the adjusted start time is: */
3134 ALmixer_Channel_List[channel].fade_start_time = current_time - used_up_time;
3135 }
3128 3136
3129 alSourcePlay(ALmixer_Channel_List[channel].alsource); 3137 alSourcePlay(ALmixer_Channel_List[channel].alsource);
3130 if((error = alGetError()) != AL_NO_ERROR) 3138 if((error = alGetError()) != AL_NO_ERROR)
3131 { 3139 {
3132 ALmixer_SetError("%s", 3140 ALmixer_SetError("%s",
3165 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); 3173 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks();
3166 } 3174 }
3167 /* Do the same as expire time for fading */ 3175 /* Do the same as expire time for fading */
3168 if(ALmixer_Channel_List[i].fade_enabled) 3176 if(ALmixer_Channel_List[i].fade_enabled)
3169 { 3177 {
3170 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); 3178 /* I originally did this wrong. On pause, I computed the amount of time remaining
3179 * and when I resumed, I grabbed the current time as the start and used the time remaining as the end.
3180 * I think this is wrong because the volume curve may not be linear.
3181 * Instead, I will try saving the time remaining, but preserve the original fade duration.
3182 * Then I will adjust the start time for the amount already played.
3183 * So I don't need to create another variable, I will overwrite the start time with the remaining time
3184 * (Resume needs to know this implementation detail.)
3185 */
3186 ALuint current_time = ALmixer_GetTicks();
3187 /* Recover the used_up_time from the overloaded fade_start_time variable */
3188 ALuint used_up_time = ALmixer_Channel_List[i].fade_start_time;
3189 /* So the adjusted start time is: */
3190 ALmixer_Channel_List[i].fade_start_time = current_time - used_up_time;
3171 } 3191 }
3172 3192
3173 alSourcePlay(ALmixer_Channel_List[i].alsource); 3193 alSourcePlay(ALmixer_Channel_List[i].alsource);
3174 if((error = alGetError()) != AL_NO_ERROR) 3194 if((error = alGetError()) != AL_NO_ERROR)
3175 { 3195 {