Mercurial > SDL_sound_CoreAudio
annotate decoders/mpglib/mpg123_sdlsound.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 | c42ac9ee2ce4 |
children |
rev | line source |
---|---|
261 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 | |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
4 #if !defined(WIN32) && !defined(macintosh) && !defined(_WIN32_WCE) |
261 | 5 #include <unistd.h> |
6 #endif | |
7 | |
8 #include <math.h> | |
9 | |
322 | 10 #if defined(_WIN32) |
261 | 11 # undef WIN32 |
12 # define WIN32 | |
322 | 13 #endif |
14 | |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
15 #if defined(WIN32) || defined(macintosh) || defined(_WIN32_WCE) |
261 | 16 |
17 # define M_PI 3.14159265358979323846 | |
18 # define M_SQRT2 1.41421356237309504880 | |
19 # define REAL_IS_FLOAT | |
20 # define NEW_DCT9 | |
21 | |
22 # define random rand | |
23 # define srandom srand | |
24 | |
25 #endif | |
26 | |
27 #ifdef REAL_IS_FLOAT | |
28 # define real float | |
29 #elif defined(REAL_IS_LONG_DOUBLE) | |
30 # define real long double | |
31 #else | |
32 # define real double | |
33 #endif | |
34 | |
35 #ifdef __GNUC__ | |
36 #define INLINE inline | |
401
c42ac9ee2ce4
Fixed "inline" keyword to compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
37 #elif ((defined _MSC_VER) || (defined __inline__)) |
299
7b1df7526915
Patches for Visual C compatibility.
Ryan C. Gordon <icculus@icculus.org>
parents:
292
diff
changeset
|
38 #define INLINE __inline__ |
261 | 39 #else |
40 #define INLINE | |
41 #endif | |
42 | |
43 /* AUDIOBUFSIZE = n*64 with n=1,2,3 ... */ | |
44 #define AUDIOBUFSIZE 16384 | |
45 | |
46 #ifndef FALSE | |
47 #define FALSE 0 | |
48 #endif | |
49 #ifndef FALSE | |
50 #define TRUE 1 | |
51 #endif | |
52 | |
53 #define SBLIMIT 32 | |
54 #define SSLIMIT 18 | |
55 | |
56 #define SCALE_BLOCK 12 | |
57 | |
58 | |
59 #define MPG_MD_STEREO 0 | |
60 #define MPG_MD_JOINT_STEREO 1 | |
61 #define MPG_MD_DUAL_CHANNEL 2 | |
62 #define MPG_MD_MONO 3 | |
63 | |
64 #define MAXFRAMESIZE 1792 | |
65 | |
66 | |
67 /* Pre Shift fo 16 to 8 bit converter table */ | |
68 #define AUSHIFT (3) | |
69 | |
70 struct frame { | |
71 int stereo; | |
72 int jsbound; | |
73 int single; | |
74 int lsf; | |
75 int mpeg25; | |
76 int header_change; | |
77 int lay; | |
78 int error_protection; | |
79 int bitrate_index; | |
80 int sampling_frequency; | |
81 int padding; | |
82 int extension; | |
83 int mode; | |
84 int mode_ext; | |
85 int copyright; | |
86 int original; | |
87 int emphasis; | |
88 int framesize; /* computed framesize */ | |
89 | |
90 /* layer2 stuff */ | |
91 int II_sblimit; | |
92 void *alloc; | |
474
c66080364dff
Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
93 |
c66080364dff
Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
94 int bitrate; |
261 | 95 }; |
96 | |
97 struct parameter { | |
98 int quiet; /* shut up! */ | |
99 int tryresync; /* resync stream after error */ | |
100 int verbose; /* verbose level */ | |
101 int checkrange; | |
102 }; | |
103 | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
104 struct mpstr; /* forward declaration. */ |
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
105 |
261 | 106 extern unsigned int get1bit(void); |
107 extern unsigned int getbits(int); | |
108 extern unsigned int getbits_fast(int); | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
109 extern int set_pointer(long,struct mpstr *); |
261 | 110 |
111 extern unsigned char *wordpointer; | |
112 extern int bitindex; | |
113 | |
114 extern void make_decode_tables(long scaleval); | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
115 extern int do_layer3(struct frame *fr,unsigned char *,int *,struct mpstr *); |
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
116 extern int do_layer2(struct frame *fr,unsigned char *,int *,struct mpstr *); |
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
117 extern int do_layer1(struct frame *fr,unsigned char *,int *,struct mpstr *); |
261 | 118 extern int decode_header(struct frame *fr,unsigned long newhead); |
119 | |
120 | |
121 | |
122 struct gr_info_s { | |
123 int scfsi; | |
124 unsigned part2_3_length; | |
125 unsigned big_values; | |
126 unsigned scalefac_compress; | |
127 unsigned block_type; | |
128 unsigned mixed_block_flag; | |
129 unsigned table_select[3]; | |
130 unsigned subblock_gain[3]; | |
131 unsigned maxband[3]; | |
132 unsigned maxbandl; | |
133 unsigned maxb; | |
134 unsigned region1start; | |
135 unsigned region2start; | |
136 unsigned preflag; | |
137 unsigned scalefac_scale; | |
138 unsigned count1table_select; | |
139 real *full_gain[3]; | |
140 real *pow2gain; | |
141 }; | |
142 | |
143 struct III_sideinfo | |
144 { | |
145 unsigned main_data_begin; | |
146 unsigned private_bits; | |
147 struct { | |
148 struct gr_info_s gr[2]; | |
149 } ch[2]; | |
150 }; | |
151 | |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
152 |
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
153 extern int synth_1to1 (real *,int,unsigned char *,int *,struct mpstr *); |
261 | 154 extern int synth_1to1_8bit (real *,int,unsigned char *,int *); |
279
52b9f37998db
Removed global state variable; should be thread safe now.
Ryan C. Gordon <icculus@icculus.org>
parents:
261
diff
changeset
|
155 extern int synth_1to1_mono (real *,unsigned char *,int *,struct mpstr *); |
261 | 156 extern int synth_1to1_mono2stereo (real *,unsigned char *,int *); |
157 extern int synth_1to1_8bit_mono (real *,unsigned char *,int *); | |
158 extern int synth_1to1_8bit_mono2stereo (real *,unsigned char *,int *); | |
159 | |
160 extern int synth_2to1 (real *,int,unsigned char *,int *); | |
161 extern int synth_2to1_8bit (real *,int,unsigned char *,int *); | |
162 extern int synth_2to1_mono (real *,unsigned char *,int *); | |
163 extern int synth_2to1_mono2stereo (real *,unsigned char *,int *); | |
164 extern int synth_2to1_8bit_mono (real *,unsigned char *,int *); | |
165 extern int synth_2to1_8bit_mono2stereo (real *,unsigned char *,int *); | |
166 | |
167 extern int synth_4to1 (real *,int,unsigned char *,int *); | |
168 extern int synth_4to1_8bit (real *,int,unsigned char *,int *); | |
169 extern int synth_4to1_mono (real *,unsigned char *,int *); | |
170 extern int synth_4to1_mono2stereo (real *,unsigned char *,int *); | |
171 extern int synth_4to1_8bit_mono (real *,unsigned char *,int *); | |
172 extern int synth_4to1_8bit_mono2stereo (real *,unsigned char *,int *); | |
173 | |
174 extern int synth_ntom (real *,int,unsigned char *,int *); | |
175 extern int synth_ntom_8bit (real *,int,unsigned char *,int *); | |
176 extern int synth_ntom_mono (real *,unsigned char *,int *); | |
177 extern int synth_ntom_mono2stereo (real *,unsigned char *,int *); | |
178 extern int synth_ntom_8bit_mono (real *,unsigned char *,int *); | |
179 extern int synth_ntom_8bit_mono2stereo (real *,unsigned char *,int *); | |
180 | |
181 extern void rewindNbits(int bits); | |
182 extern int hsstell(void); | |
183 extern int get_songlen(struct frame *fr,int no); | |
184 | |
185 extern void init_layer3(int); | |
186 extern void init_layer2(void); | |
187 extern void make_decode_tables(long scale); | |
188 extern void make_conv16to8_table(int); | |
189 extern void dct64(real *,real *,real *); | |
190 | |
191 extern void synth_ntom_set_step(long,long); | |
192 | |
193 extern unsigned char *conv16to8; | |
292
a9e211c3faa4
Cleanups and audio format determination.
Ryan C. Gordon <icculus@icculus.org>
parents:
290
diff
changeset
|
194 extern long mpglib_freqs[9]; |
261 | 195 extern real muls[27][64]; |
196 extern real decwin[512+32]; | |
197 extern real *pnts[5]; | |
198 | |
199 extern struct parameter param; | |
200 | |
201 |