* NAME: timer->set() * DESCRIPTION: set timer to specific (positive) value */
| 156 | * DESCRIPTION: set timer to specific (positive) value |
| 157 | */ |
| 158 | void mad_timer_set(mad_timer_t *timer, unsigned long seconds, |
| 159 | unsigned long numer, unsigned long denom) |
| 160 | { |
| 161 | timer->seconds = seconds; |
| 162 | if (numer >= denom && denom > 0) { |
| 163 | timer->seconds += numer / denom; |
| 164 | numer %= denom; |
| 165 | } |
| 166 | |
| 167 | switch (denom) { |
| 168 | case 0: |
| 169 | case 1: |
| 170 | timer->fraction = 0; |
| 171 | break; |
| 172 | |
| 173 | case MAD_TIMER_RESOLUTION: |
| 174 | timer->fraction = numer; |
| 175 | break; |
| 176 | |
| 177 | case 1000: |
| 178 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 1000); |
| 179 | break; |
| 180 | |
| 181 | case 8000: |
| 182 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 8000); |
| 183 | break; |
| 184 | |
| 185 | case 11025: |
| 186 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 11025); |
| 187 | break; |
| 188 | |
| 189 | case 12000: |
| 190 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 12000); |
| 191 | break; |
| 192 | |
| 193 | case 16000: |
| 194 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 16000); |
| 195 | break; |
| 196 | |
| 197 | case 22050: |
| 198 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 22050); |
| 199 | break; |
| 200 | |
| 201 | case 24000: |
| 202 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 24000); |
| 203 | break; |
| 204 | |
| 205 | case 32000: |
| 206 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 32000); |
| 207 | break; |
| 208 | |
| 209 | case 44100: |
| 210 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 44100); |
| 211 | break; |
| 212 | |
| 213 | case 48000: |
| 214 | timer->fraction = numer * (MAD_TIMER_RESOLUTION / 48000); |
| 215 | break; |
no test coverage detected