Crackle-free audio playback.
[SDL.s60v3.git] / test / testtimer.c
blob95608c1206371a34614d350f4bb6f8e949d0f9aa
2 /* Test program to check the resolution of the SDL timer on the current
3 platform
4 */
6 #include <stdlib.h>
7 #include <stdio.h>
9 #include "SDL.h"
11 #define DEFAULT_RESOLUTION 1
13 static int ticks = 0;
15 static Uint32 SDLCALL ticktock(Uint32 interval)
17 ++ticks;
18 return(interval);
21 static Uint32 SDLCALL callback(Uint32 interval, void *param)
23 printf("Timer %d : param = %d\n", interval, (int)(uintptr_t)param);
24 return interval;
27 int main(int argc, char *argv[])
29 int desired;
30 SDL_TimerID t1, t2, t3;
32 if ( SDL_Init(SDL_INIT_TIMER) < 0 ) {
33 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
34 return(1);
37 /* Start the timer */
38 desired = 0;
39 if ( argv[1] ) {
40 desired = atoi(argv[1]);
42 if ( desired == 0 ) {
43 desired = DEFAULT_RESOLUTION;
45 SDL_SetTimer(desired, ticktock);
47 /* Wait 10 seconds */
48 printf("Waiting 10 seconds\n");
49 SDL_Delay(10*1000);
51 /* Stop the timer */
52 SDL_SetTimer(0, NULL);
54 /* Print the results */
55 if ( ticks ) {
56 fprintf(stderr,
57 "Timer resolution: desired = %d ms, actual = %f ms\n",
58 desired, (double)(10*1000)/ticks);
61 /* Test multiple timers */
62 printf("Testing multiple timers...\n");
63 t1 = SDL_AddTimer(100, callback, (void*)1);
64 if(!t1)
65 fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError());
66 t2 = SDL_AddTimer(50, callback, (void*)2);
67 if(!t2)
68 fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError());
69 t3 = SDL_AddTimer(233, callback, (void*)3);
70 if(!t3)
71 fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError());
73 /* Wait 10 seconds */
74 printf("Waiting 10 seconds\n");
75 SDL_Delay(10*1000);
77 printf("Removing timer 1 and waiting 5 more seconds\n");
78 SDL_RemoveTimer(t1);
80 SDL_Delay(5*1000);
82 SDL_RemoveTimer(t2);
83 SDL_RemoveTimer(t3);
85 SDL_Quit();
86 return(0);