Mercurial > sdl-ios-xcode
annotate docs/html/sdljoystickopen.html @ 773:da0a2ad35bf4
Date: Sun, 4 Jan 2004 23:48:19 +0100
From: Max Horn
Subject: Re: Again Audio CD patch
Am 04.01.2004 um 22:38 schrieb Sam Lantinga:
>
> Okay, I fixed the buffering problems by simply using a 4 second buffer
> instead of a 1 second buffer. However, using your code I can't play an
> entire CD - the playback stops after the first song.
>
Found the problem: FSReadFork returns eofErr when the file is finished.
However, we check its return value for errors, and if anything but
noErr occurs, the reader thread aborts its current iteration. That is
bad, because it aborts before it can ever set the flag which tells that
the file is over (also, any remaining data which FSRead did return is
lost - so you'd not hear about to 4 seconds from the end of the file.
Furthermore, the computed data size was 8 bytes to high (I forgot to
account for the fact that the size of an (A)IFF chunk always contains
the chunk header & size fields, too). This is enough to make it work.
However, the end condition is rather fragile, so I tuned some other
things to be pessimistic (check for <= 0 instead of == 0, when eofErr
is encountered enforce mReadFilePosition == mFileLength). You never
know...
The attached patch fixes the issue for me.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 05 Jan 2004 00:57:51 +0000 |
parents | e5bc29de3f0a |
children | 355632dca928 |
rev | line source |
---|---|
0 | 1 <HTML |
2 ><HEAD | |
3 ><TITLE | |
4 >SDL_JoystickOpen</TITLE | |
5 ><META | |
6 NAME="GENERATOR" | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.64 |
0 | 8 "><LINK |
9 REL="HOME" | |
10 TITLE="SDL Library Documentation" | |
11 HREF="index.html"><LINK | |
12 REL="UP" | |
13 TITLE="Joystick" | |
14 HREF="joystick.html"><LINK | |
15 REL="PREVIOUS" | |
16 TITLE="SDL_JoystickName" | |
17 HREF="sdljoystickname.html"><LINK | |
18 REL="NEXT" | |
19 TITLE="SDL_JoystickOpened" | |
20 HREF="sdljoystickopened.html"></HEAD | |
21 ><BODY | |
22 CLASS="REFENTRY" | |
23 BGCOLOR="#FFF8DC" | |
24 TEXT="#000000" | |
25 LINK="#0000ee" | |
26 VLINK="#551a8b" | |
27 ALINK="#ff0000" | |
28 ><DIV | |
29 CLASS="NAVHEADER" | |
30 ><TABLE | |
31 WIDTH="100%" | |
32 BORDER="0" | |
33 CELLPADDING="0" | |
34 CELLSPACING="0" | |
35 ><TR | |
36 ><TH | |
37 COLSPAN="3" | |
38 ALIGN="center" | |
39 >SDL Library Documentation</TH | |
40 ></TR | |
41 ><TR | |
42 ><TD | |
43 WIDTH="10%" | |
44 ALIGN="left" | |
45 VALIGN="bottom" | |
46 ><A | |
47 HREF="sdljoystickname.html" | |
48 >Prev</A | |
49 ></TD | |
50 ><TD | |
51 WIDTH="80%" | |
52 ALIGN="center" | |
53 VALIGN="bottom" | |
54 ></TD | |
55 ><TD | |
56 WIDTH="10%" | |
57 ALIGN="right" | |
58 VALIGN="bottom" | |
59 ><A | |
60 HREF="sdljoystickopened.html" | |
61 >Next</A | |
62 ></TD | |
63 ></TR | |
64 ></TABLE | |
65 ><HR | |
66 ALIGN="LEFT" | |
67 WIDTH="100%"></DIV | |
68 ><H1 | |
69 ><A | |
70 NAME="SDLJOYSTICKOPEN" | |
71 >SDL_JoystickOpen</A | |
72 ></H1 | |
73 ><DIV | |
74 CLASS="REFNAMEDIV" | |
75 ><A | |
181
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
76 NAME="AEN5708" |
0 | 77 ></A |
78 ><H2 | |
79 >Name</H2 | |
80 >SDL_JoystickOpen -- Opens a joystick for use.</DIV | |
81 ><DIV | |
82 CLASS="REFSYNOPSISDIV" | |
83 ><A | |
181
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
84 NAME="AEN5711" |
0 | 85 ></A |
86 ><H2 | |
87 >Synopsis</H2 | |
88 ><DIV | |
89 CLASS="FUNCSYNOPSIS" | |
90 ><A | |
181
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
91 NAME="AEN5712" |
0 | 92 ></A |
93 ><P | |
94 ></P | |
95 ><PRE | |
96 CLASS="FUNCSYNOPSISINFO" | |
97 >#include "SDL.h"</PRE | |
98 ><P | |
99 ><CODE | |
100 ><CODE | |
101 CLASS="FUNCDEF" | |
102 >SDL_Joystick *<B | |
103 CLASS="FSFUNC" | |
104 >SDL_JoystickOpen</B | |
105 ></CODE | |
106 >(int index);</CODE | |
107 ></P | |
108 ><P | |
109 ></P | |
110 ></DIV | |
111 ></DIV | |
112 ><DIV | |
113 CLASS="REFSECT1" | |
114 ><A | |
181
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
115 NAME="AEN5718" |
0 | 116 ></A |
117 ><H2 | |
118 >Description</H2 | |
119 ><P | |
120 >Opens a joystick for use within SDL. The <TT | |
121 CLASS="PARAMETER" | |
122 ><I | |
123 >index</I | |
124 ></TT | |
125 > refers to the N'th joystick in the system. A joystick must be opened before it game be used.</P | |
126 ></DIV | |
127 ><DIV | |
128 CLASS="REFSECT1" | |
129 ><A | |
181
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
130 NAME="AEN5722" |
0 | 131 ></A |
132 ><H2 | |
133 >Return Value</H2 | |
134 ><P | |
135 >Returns a <SPAN | |
136 CLASS="STRUCTNAME" | |
137 >SDL_Joystick</SPAN | |
138 > structure on success. <SPAN | |
139 CLASS="RETURNVALUE" | |
140 >NULL</SPAN | |
141 > on failure.</P | |
142 ></DIV | |
143 ><DIV | |
144 CLASS="REFSECT1" | |
145 ><A | |
181
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
146 NAME="AEN5727" |
0 | 147 ></A |
148 ><H2 | |
149 >Examples</H2 | |
150 ><P | |
151 ><PRE | |
152 CLASS="PROGRAMLISTING" | |
153 >SDL_Joystick *joy; | |
154 // Check for joystick | |
155 if(SDL_NumJoysticks()>0){ | |
156 // Open joystick | |
157 joy=SDL_JoystickOpen(0); | |
158 | |
159 if(joy) | |
160 { | |
161 printf("Opened Joystick 0\n"); | |
162 printf("Name: %s\n", SDL_JoystickName(0)); | |
181
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
163 printf("Number of Axes: %d\n", SDL_JoystickNumAxes(joy)); |
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
164 printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(joy)); |
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
165 printf("Number of Balls: %d\n", SDL_JoystickNumBalls(joy)); |
0 | 166 } |
167 else | |
168 printf("Couldn't open Joystick 0\n"); | |
169 | |
170 // Close if opened | |
171 if(SDL_JoystickOpened(0)) | |
172 SDL_JoystickClose(joy); | |
173 }</PRE | |
174 ></P | |
175 ></DIV | |
176 ><DIV | |
177 CLASS="REFSECT1" | |
178 ><A | |
181
e5bc29de3f0a
Updated from the SDL Documentation Project
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
179 NAME="AEN5731" |
0 | 180 ></A |
181 ><H2 | |
182 >See Also</H2 | |
183 ><P | |
184 ><A | |
185 HREF="sdljoystickclose.html" | |
186 ><TT | |
187 CLASS="FUNCTION" | |
188 >SDL_JoystickClose</TT | |
189 ></A | |
190 ></P | |
191 ></DIV | |
192 ><DIV | |
193 CLASS="NAVFOOTER" | |
194 ><HR | |
195 ALIGN="LEFT" | |
196 WIDTH="100%"><TABLE | |
197 WIDTH="100%" | |
198 BORDER="0" | |
199 CELLPADDING="0" | |
200 CELLSPACING="0" | |
201 ><TR | |
202 ><TD | |
203 WIDTH="33%" | |
204 ALIGN="left" | |
205 VALIGN="top" | |
206 ><A | |
207 HREF="sdljoystickname.html" | |
208 >Prev</A | |
209 ></TD | |
210 ><TD | |
211 WIDTH="34%" | |
212 ALIGN="center" | |
213 VALIGN="top" | |
214 ><A | |
215 HREF="index.html" | |
216 >Home</A | |
217 ></TD | |
218 ><TD | |
219 WIDTH="33%" | |
220 ALIGN="right" | |
221 VALIGN="top" | |
222 ><A | |
223 HREF="sdljoystickopened.html" | |
224 >Next</A | |
225 ></TD | |
226 ></TR | |
227 ><TR | |
228 ><TD | |
229 WIDTH="33%" | |
230 ALIGN="left" | |
231 VALIGN="top" | |
232 >SDL_JoystickName</TD | |
233 ><TD | |
234 WIDTH="34%" | |
235 ALIGN="center" | |
236 VALIGN="top" | |
237 ><A | |
238 HREF="joystick.html" | |
239 >Up</A | |
240 ></TD | |
241 ><TD | |
242 WIDTH="33%" | |
243 ALIGN="right" | |
244 VALIGN="top" | |
245 >SDL_JoystickOpened</TD | |
246 ></TR | |
247 ></TABLE | |
248 ></DIV | |
249 ></BODY | |
250 ></HTML | |
251 > |