Mercurial > sdl-ios-xcode
annotate test/testtimer.c @ 1260:80f8c94b5199
Date: 10 Jun 2003 15:30:59 -0400
From: Mike Shal
Subject: [SDL] Bug in SDL_wave.c?
Hey everyone, I'm not sure if this is a bug in SDL, or if I just have
incorrect WAV files. The problem I'm having is loading multiple
concatenated WAVs from SDL_LoadWAV_RW. Some WAV files put comments at
the end of the file (which may be bad form), and SDL doesn't skip past
them when reading from the RWops. So the next WAV I try to load will
start at the comment section of the previous WAV, which obviously
doesn't work. If anyone else is having this problem, one quick fix you
can do is run sox on the bad WAVs, which strips out all of the comment
sections.
Eg:
$ sox sound.wav tmp.wav
$ mv -f tmp.wav sound.wav
The other fix is to patch SDL_wave.c, which is included with this email.
(Assuming I made the patch correctly :). All it does is calculate how
much remaining space there is in the WAV file after the data chunk, and
does SDL_RWseek to skip it. I don't think it should interfere with
anything else, but if someone could check it that would be nice :). If
the bug is really with SDL and not with my WAVs, can someone work this
into the next version of SDL? Thanks,
-Mike Shal
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 24 Jan 2006 07:20:18 +0000 |
parents | be9c9c8f6d53 |
children | b2b476a4a73c |
rev | line source |
---|---|
0 | 1 |
2 /* Test program to check the resolution of the SDL timer on the current | |
3 platform | |
4 */ | |
5 | |
6 #include <stdlib.h> | |
7 #include <stdio.h> | |
8 | |
9 #include "SDL.h" | |
10 | |
11 #define DEFAULT_RESOLUTION 1 | |
12 | |
13 static int ticks = 0; | |
14 | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
15 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
16 static void quit(int rc) |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
17 { |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
18 SDL_Quit(); |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
19 exit(rc); |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
20 } |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
21 |
0 | 22 static Uint32 ticktock(Uint32 interval) |
23 { | |
24 ++ticks; | |
25 return(interval); | |
26 } | |
27 | |
28 static Uint32 callback(Uint32 interval, void *param) | |
29 { | |
30 printf("Timer %d : param = %d\n", interval, (int) param); | |
31 return interval; | |
32 } | |
33 | |
34 int main(int argc, char *argv[]) | |
35 { | |
36 int desired; | |
37 SDL_TimerID t1, t2, t3; | |
38 | |
39 if ( SDL_Init(SDL_INIT_TIMER) < 0 ) { | |
40 fprintf(stderr, "Couldn't load SDL: %s\n", SDL_GetError()); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
41 return(1); |
0 | 42 } |
43 | |
44 /* Start the timer */ | |
45 desired = 0; | |
46 if ( argv[1] ) { | |
47 desired = atoi(argv[1]); | |
48 } | |
49 if ( desired == 0 ) { | |
50 desired = DEFAULT_RESOLUTION; | |
51 } | |
52 SDL_SetTimer(desired, ticktock); | |
53 | |
54 /* Wait 10 seconds */ | |
55 printf("Waiting 10 seconds\n"); | |
56 SDL_Delay(10*1000); | |
57 | |
58 /* Stop the timer */ | |
59 SDL_SetTimer(0, NULL); | |
60 | |
61 /* Print the results */ | |
62 if ( ticks ) { | |
63 fprintf(stderr, | |
64 "Timer resolution: desired = %d ms, actual = %f ms\n", | |
65 desired, (double)(10*1000)/ticks); | |
66 } | |
67 | |
68 /* Test multiple timers */ | |
69 printf("Testing multiple timers...\n"); | |
70 t1 = SDL_AddTimer(100, callback, (void*)1); | |
71 if(!t1) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
72 fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError()); |
0 | 73 t2 = SDL_AddTimer(50, callback, (void*)2); |
74 if(!t2) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
75 fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError()); |
0 | 76 t3 = SDL_AddTimer(233, callback, (void*)3); |
77 if(!t3) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
78 fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError()); |
0 | 79 |
80 /* Wait 10 seconds */ | |
81 printf("Waiting 10 seconds\n"); | |
82 SDL_Delay(10*1000); | |
83 | |
84 printf("Removing timer 1 and waiting 5 more seconds\n"); | |
85 SDL_RemoveTimer(t1); | |
86 | |
87 SDL_Delay(5*1000); | |
88 | |
89 SDL_RemoveTimer(t2); | |
90 SDL_RemoveTimer(t3); | |
91 | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
766
diff
changeset
|
92 SDL_Quit(); |
0 | 93 return(0); |
94 } |