annotate playsound/physfsrwops.h @ 474:c66080364dff

Most decoders now report total sample play time, now. Technically, this breaks binary compatibility with the 1.0 branch, since it extends the Sound_Sample struct, but most (all?) programs are just passing pointers allocated by SDL_sound around, and might be okay. Source-level compatibility is not broken...yet! :) --ryan. -------- Original Message -------- Subject: SDL_sound patch: Finding total length of time of sound file. Date: Sun, 26 Jan 2003 09:31:17 -0800 (PST) Hi Ryan, I am working with Eric Wing and helping him modify SDL_sound. AS part of our efforts in improving and enhancing SDL_sound, we like to submit this patch. We modified the codecs to find the total time of a sound file. Below is the explanation of the patch. The patch is appended as an attachment to this email. * MOTIVATION: We needed the ability to get the total play time of a sample (And we noticed that we're not the only ones). Since SDL_sound blocks direct access to the specific decoders, there is no way for a user to know this information short of decoding the whole thing. Because of this, we believe this will be a useful addition, even though the accuracy may not be perfect (subject to each decoder) or the information may not always be available. * CONTRIBUTORS: Wesley Leong (modified the majority of the codecs and verified the results) Eric Wing (showed everyone how to do modify codec, modified mikmod) Wang Lam (modified a handful of codecs, researched into specs and int overflow) Ahilan Anantha (modified a few codecs and helped with integer math) * GENERAL ISSUES: We chose the value to be milliseconds as an Sint32. Milliseconds because that's what Sound_Seek takes as a parameter and -1 to allow for instances/codecs where the value could not be determined. We are not sure if this is the final convention you want, so we are willing to work with you on this. We also expect the total_time field to be set on open and never again modified by SDL_sound. Users may access it directly much like the sample buffer and buffer_size. We thought about recomputing the time on DecodeAll, but since users may seek or decode small chunks first, not all the data may be there. So this is better done by the user. This may be good information to document. Currently, all the main codecs are implemented except for QuickTime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 08 May 2004 08:19:50 +0000
parents d8c0315deba9
children 50bb9a6cebfe
rev   line source
286
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * This code provides a glue layer between PhysicsFS and Simple Directmedia
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Layer's (SDL) RWops i/o abstraction.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * License: this code is public domain. I make no warranty that it is useful,
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * correct, harmless, or environmentally safe.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * This particular file may be used however you like, including copying it
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 * verbatim into a closed-source project, exploiting it commercially, and
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * removing any trace of my name from the source (although I hope you won't
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * do that). I welcome enhancements and corrections to this file, but I do
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * not require you to send me patches if you make changes.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 * Unless otherwise stated, the rest of PhysicsFS falls under the GNU Lesser
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * General Public License: http://www.gnu.org/licenses/lgpl.txt
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * SDL falls under the LGPL, too. You can get SDL at http://www.libsdl.org/
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 * This file was written by Ryan C. Gordon. (icculus@clutteredmind.org).
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 #ifndef _INCLUDE_PHYSFSRWOPS_H_
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 #define _INCLUDE_PHYSFSRWOPS_H_
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 #include "physfs.h"
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 #include "SDL.h"
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #ifdef __cplusplus
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 extern "C" {
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #endif
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 /**
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 * Open a platform-independent filename for reading, and make it accessible
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 * RWops is closed. PhysicsFS should be configured to your liking before
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 * opening files through this method.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 * @param filename File to open in platform-independent notation.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 * @return A valid SDL_RWops structure on success, NULL on error. Specifics
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 * of the error can be gleaned from PHYSFS_getLastError().
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 __EXPORT__ SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 /**
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 * Open a platform-independent filename for writing, and make it accessible
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 * RWops is closed. PhysicsFS should be configured to your liking before
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 * opening files through this method.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 * @param filename File to open in platform-independent notation.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 * @return A valid SDL_RWops structure on success, NULL on error. Specifics
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 * of the error can be gleaned from PHYSFS_getLastError().
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 __EXPORT__ SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 /**
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 * Open a platform-independent filename for appending, and make it accessible
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 * via an SDL_RWops structure. The file will be closed in PhysicsFS when the
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 * RWops is closed. PhysicsFS should be configured to your liking before
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 * opening files through this method.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 * @param filename File to open in platform-independent notation.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 * @return A valid SDL_RWops structure on success, NULL on error. Specifics
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 * of the error can be gleaned from PHYSFS_getLastError().
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 __EXPORT__ SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 /**
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 * Make a SDL_RWops from an existing PhysicsFS file handle. You should
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 * dispose of any references to the handle after successful creation of
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 * the RWops. The actual PhysicsFS handle will be destroyed when the
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 * RWops is closed.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 *
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 * @param handle a valid PhysicsFS file handle.
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 * @return A valid SDL_RWops structure on success, NULL on error. Specifics
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 * of the error can be gleaned from PHYSFS_getLastError().
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 __EXPORT__ SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle);
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 #ifdef __cplusplus
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 }
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 #endif
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 #endif /* include-once blocker */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 /* end of physfsrwops.h ... */
a6453cae7512 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87