summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-06-24 14:48:25 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-06-24 14:48:25 +0000
commit96af117e21b8eef19ea544283477b14afad36f97 (patch)
tree6bad94a650285a5dd3a7d08e390b3b583c516ae8
parentfcae888e81a0794880b78d3e443ef814c2ac0e1b (diff)
downloadrockbox-96af117e21b8eef19ea544283477b14afad36f97.tar.gz
rockbox-96af117e21b8eef19ea544283477b14afad36f97.zip
Submit FS#12142 by Sean Bartell with minor chnages by myself. Removes unused code and irrelevant files from libmad.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30065 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libmad/INSTALL183
-rw-r--r--apps/codecs/libmad/decoder.c589
-rw-r--r--apps/codecs/libmad/decoder.h93
-rw-r--r--apps/codecs/libmad/fixed.c81
-rw-r--r--apps/codecs/libmad/fixed.h5
-rw-r--r--apps/codecs/libmad/frame.c2
-rw-r--r--apps/codecs/libmad/frame.h3
-rw-r--r--apps/codecs/libmad/mad.h3
-rw-r--r--apps/codecs/libmad/mad.h.sed36
-rw-r--r--apps/codecs/libmad/minimad.c222
-rw-r--r--apps/codecs/libmad/stream.c9
-rw-r--r--apps/codecs/libmad/stream.h9
-rw-r--r--apps/codecs/libmad/synth.h17
-rw-r--r--apps/codecs/libmad/timer.c488
-rw-r--r--apps/codecs/libmad/timer.h100
-rw-r--r--apps/codecs/libmad/version.c74
-rw-r--r--apps/codecs/libmad/version.h47
17 files changed, 16 insertions, 1945 deletions
diff --git a/apps/codecs/libmad/INSTALL b/apps/codecs/libmad/INSTALL
deleted file mode 100644
index 50dbe439d0..0000000000
--- a/apps/codecs/libmad/INSTALL
+++ /dev/null
@@ -1,183 +0,0 @@
1Basic Installation
2==================
3
4 These are generic installation instructions.
5
6 The `configure' shell script attempts to guess correct values for
7various system-dependent variables used during compilation. It uses
8those values to create a `Makefile' in each directory of the package.
9It may also create one or more `.h' files containing system-dependent
10definitions. Finally, it creates a shell script `config.status' that
11you can run in the future to recreate the current configuration, a file
12`config.cache' that saves the results of its tests to speed up
13reconfiguring, and a file `config.log' containing compiler output
14(useful mainly for debugging `configure').
15
16 If you need to do unusual things to compile the package, please try
17to figure out how `configure' could check whether to do them, and mail
18diffs or instructions to the address given in the `README' so they can
19be considered for the next release. If at some point `config.cache'
20contains results you don't want to keep, you may remove or edit it.
21
22 The file `configure.in' is used to create `configure' by a program
23called `autoconf'. You only need `configure.in' if you want to change
24it or regenerate `configure' using a newer version of `autoconf'.
25
26The simplest way to compile this package is:
27
28 1. `cd' to the directory containing the package's source code and type
29 `./configure' to configure the package for your system. If you're
30 using `csh' on an old version of System V, you might need to type
31 `sh ./configure' instead to prevent `csh' from trying to execute
32 `configure' itself.
33
34 Running `configure' takes awhile. While running, it prints some
35 messages telling which features it is checking for.
36
37 2. Type `make' to compile the package.
38
39 3. Optionally, type `make check' to run any self-tests that come with
40 the package.
41
42 4. Type `make install' to install the programs and any data files and
43 documentation.
44
45 5. You can remove the program binaries and object files from the
46 source code directory by typing `make clean'. To also remove the
47 files that `configure' created (so you can compile the package for
48 a different kind of computer), type `make distclean'. There is
49 also a `make maintainer-clean' target, but that is intended mainly
50 for the package's developers. If you use it, you may have to get
51 all sorts of other programs in order to regenerate files that came
52 with the distribution.
53
54Compilers and Options
55=====================
56
57 Some systems require unusual options for compilation or linking that
58the `configure' script does not know about. You can give `configure'
59initial values for variables by setting them in the environment. Using
60a Bourne-compatible shell, you can do that on the command line like
61this:
62 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
63
64Or on systems that have the `env' program, you can do it like this:
65 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
66
67Compiling For Multiple Architectures
68====================================
69
70 You can compile the package for more than one kind of computer at the
71same time, by placing the object files for each architecture in their
72own directory. To do this, you must use a version of `make' that
73supports the `VPATH' variable, such as GNU `make'. `cd' to the
74directory where you want the object files and executables to go and run
75the `configure' script. `configure' automatically checks for the
76source code in the directory that `configure' is in and in `..'.
77
78 If you have to use a `make' that does not supports the `VPATH'
79variable, you have to compile the package for one architecture at a time
80in the source code directory. After you have installed the package for
81one architecture, use `make distclean' before reconfiguring for another
82architecture.
83
84Installation Names
85==================
86
87 By default, `make install' will install the package's files in
88`/usr/local/bin', `/usr/local/man', etc. You can specify an
89installation prefix other than `/usr/local' by giving `configure' the
90option `--prefix=PATH'.
91
92 You can specify separate installation prefixes for
93architecture-specific files and architecture-independent files. If you
94give `configure' the option `--exec-prefix=PATH', the package will use
95PATH as the prefix for installing programs and libraries.
96Documentation and other data files will still use the regular prefix.
97
98 In addition, if you use an unusual directory layout you can give
99options like `--bindir=PATH' to specify different values for particular
100kinds of files. Run `configure --help' for a list of the directories
101you can set and what kinds of files go in them.
102
103 If the package supports it, you can cause programs to be installed
104with an extra prefix or suffix on their names by giving `configure' the
105option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
106
107Optional Features
108=================
109
110 Some packages pay attention to `--enable-FEATURE' options to
111`configure', where FEATURE indicates an optional part of the package.
112They may also pay attention to `--with-PACKAGE' options, where PACKAGE
113is something like `gnu-as' or `x' (for the X Window System). The
114`README' should mention any `--enable-' and `--with-' options that the
115package recognizes.
116
117 For packages that use the X Window System, `configure' can usually
118find the X include and library files automatically, but if it doesn't,
119you can use the `configure' options `--x-includes=DIR' and
120`--x-libraries=DIR' to specify their locations.
121
122Specifying the System Type
123==========================
124
125 There may be some features `configure' can not figure out
126automatically, but needs to determine by the type of host the package
127will run on. Usually `configure' can figure that out, but if it prints
128a message saying it can not guess the host type, give it the
129`--host=TYPE' option. TYPE can either be a short name for the system
130type, such as `sun4', or a canonical name with three fields:
131 CPU-COMPANY-SYSTEM
132
133See the file `config.sub' for the possible values of each field. If
134`config.sub' isn't included in this package, then this package doesn't
135need to know the host type.
136
137 If you are building compiler tools for cross-compiling, you can also
138use the `--target=TYPE' option to select the type of system they will
139produce code for and the `--build=TYPE' option to select the type of
140system on which you are compiling the package.
141
142Sharing Defaults
143================
144
145 If you want to set default values for `configure' scripts to share,
146you can create a site shell script called `config.site' that gives
147default values for variables like `CC', `cache_file', and `prefix'.
148`configure' looks for `PREFIX/share/config.site' if it exists, then
149`PREFIX/etc/config.site' if it exists. Or, you can set the
150`CONFIG_SITE' environment variable to the location of the site script.
151A warning: not all `configure' scripts look for a site script.
152
153Operation Controls
154==================
155
156 `configure' recognizes the following options to control how it
157operates.
158
159`--cache-file=FILE'
160 Use and save the results of the tests in FILE instead of
161 `./config.cache'. Set FILE to `/dev/null' to disable caching, for
162 debugging `configure'.
163
164`--help'
165 Print a summary of the options to `configure', and exit.
166
167`--quiet'
168`--silent'
169`-q'
170 Do not print messages saying which checks are being made. To
171 suppress all normal output, redirect it to `/dev/null' (any error
172 messages will still be shown).
173
174`--srcdir=DIR'
175 Look for the package's source code in directory DIR. Usually
176 `configure' can determine that directory automatically.
177
178`--version'
179 Print the version of Autoconf used to generate the `configure'
180 script, and exit.
181
182`configure' also accepts some other, not widely useful, options.
183
diff --git a/apps/codecs/libmad/decoder.c b/apps/codecs/libmad/decoder.c
deleted file mode 100644
index af8e96962d..0000000000
--- a/apps/codecs/libmad/decoder.c
+++ /dev/null
@@ -1,589 +0,0 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id$
20 */
21
22# ifdef HAVE_CONFIG_H
23# include "config.h"
24# endif
25
26# include "global.h"
27
28# ifdef HAVE_SYS_TYPES_H
29# include <sys/types.h>
30# endif
31
32# ifdef HAVE_SYS_WAIT_H
33# include <sys/wait.h>
34# endif
35
36# ifdef HAVE_UNISTD_H
37# include <unistd.h>
38# endif
39
40# ifdef HAVE_FCNTL_H
41# include <fcntl.h>
42# endif
43
44# ifdef HAVE_ERRNO_H
45# include <errno.h>
46# endif
47
48# include "stream.h"
49# include "frame.h"
50# include "synth.h"
51# include "decoder.h"
52
53#if 0 /* rockbox: not used */
54/*
55 * NAME: decoder->init()
56 * DESCRIPTION: initialize a decoder object with callback routines
57 */
58void mad_decoder_init(struct mad_decoder *decoder, void *data,
59 enum mad_flow (*input_func)(void *,
60 struct mad_stream *),
61 enum mad_flow (*header_func)(void *,
62 struct mad_header const *),
63 enum mad_flow (*filter_func)(void *,
64 struct mad_stream const *,
65 struct mad_frame *),
66 enum mad_flow (*output_func)(void *,
67 struct mad_header const *,
68 struct mad_pcm *),
69 enum mad_flow (*error_func)(void *,
70 struct mad_stream *,
71 struct mad_frame *),
72 enum mad_flow (*message_func)(void *,
73 void *, unsigned int *))
74{
75 decoder->mode = -1;
76
77 decoder->options = 0;
78
79 decoder->async.pid = 0;
80 decoder->async.in = -1;
81 decoder->async.out = -1;
82
83 decoder->sync = 0;
84
85 decoder->cb_data = data;
86
87 decoder->input_func = input_func;
88 decoder->header_func = header_func;
89 decoder->filter_func = filter_func;
90 decoder->output_func = output_func;
91 decoder->error_func = error_func;
92 decoder->message_func = message_func;
93}
94
95int mad_decoder_finish(struct mad_decoder *decoder)
96{
97# if defined(USE_ASYNC)
98 if (decoder->mode == MAD_DECODER_MODE_ASYNC && decoder->async.pid) {
99 pid_t pid;
100 int status;
101
102 close(decoder->async.in);
103
104 do
105 pid = waitpid(decoder->async.pid, &status, 0);
106 while (pid == -1 && errno == EINTR);
107
108 decoder->mode = -1;
109
110 close(decoder->async.out);
111
112 decoder->async.pid = 0;
113 decoder->async.in = -1;
114 decoder->async.out = -1;
115
116 if (pid == -1)
117 return -1;
118
119 return (!WIFEXITED(status) || WEXITSTATUS(status)) ? -1 : 0;
120 }
121# else
122 /* Avoid compiler warning */
123 (void)decoder;
124# endif
125
126 return 0;
127}
128
129# if defined(USE_ASYNC)
130static
131enum mad_flow send_io(int fd, void const *data, size_t len)
132{
133 char const *ptr = data;
134 ssize_t count;
135
136 while (len) {
137 do
138 count = write(fd, ptr, len);
139 while (count == -1 && errno == EINTR);
140
141 if (count == -1)
142 return MAD_FLOW_BREAK;
143
144 len -= count;
145 ptr += count;
146 }
147
148 return MAD_FLOW_CONTINUE;
149}
150
151static
152enum mad_flow receive_io(int fd, void *buffer, size_t len)
153{
154 char *ptr = buffer;
155 ssize_t count;
156
157 while (len) {
158 do
159 count = read(fd, ptr, len);
160 while (count == -1 && errno == EINTR);
161
162 if (count == -1)
163 return (errno == EAGAIN) ? MAD_FLOW_IGNORE : MAD_FLOW_BREAK;
164 else if (count == 0)
165 return MAD_FLOW_STOP;
166
167 len -= count;
168 ptr += count;
169 }
170
171 return MAD_FLOW_CONTINUE;
172}
173
174static
175enum mad_flow receive_io_blocking(int fd, void *buffer, size_t len)
176{
177 int flags, blocking;
178 enum mad_flow result;
179
180 flags = fcntl(fd, F_GETFL);
181 if (flags == -1)
182 return MAD_FLOW_BREAK;
183
184 blocking = flags & ~O_NONBLOCK;
185
186 if (blocking != flags &&
187 fcntl(fd, F_SETFL, blocking) == -1)
188 return MAD_FLOW_BREAK;
189
190 result = receive_io(fd, buffer, len);
191
192 if (flags != blocking &&
193 fcntl(fd, F_SETFL, flags) == -1)
194 return MAD_FLOW_BREAK;
195
196 return result;
197}
198
199static
200enum mad_flow send(int fd, void const *message, unsigned int size)
201{
202 enum mad_flow result;
203
204 /* send size */
205
206 result = send_io(fd, &size, sizeof(size));
207
208 /* send message */
209
210 if (result == MAD_FLOW_CONTINUE)
211 result = send_io(fd, message, size);
212
213 return result;
214}
215
216static
217enum mad_flow receive(int fd, void **message, unsigned int *size)
218{
219 enum mad_flow result;
220 unsigned int actual;
221
222 if (*message == 0)
223 *size = 0;
224
225 /* receive size */
226
227 result = receive_io(fd, &actual, sizeof(actual));
228
229 /* receive message */
230
231 if (result == MAD_FLOW_CONTINUE) {
232 if (actual > *size)
233 actual -= *size;
234 else {
235 *size = actual;
236 actual = 0;
237 }
238
239 if (*size > 0) {
240 if (*message == 0) {
241 *message = malloc(*size);
242 if (*message == 0)
243 return MAD_FLOW_BREAK;
244 }
245
246 result = receive_io_blocking(fd, *message, *size);
247 }
248
249 /* throw away remainder of message */
250
251 while (actual && result == MAD_FLOW_CONTINUE) {
252 char sink[256];
253 unsigned int len;
254
255 len = actual > sizeof(sink) ? sizeof(sink) : actual;
256
257 result = receive_io_blocking(fd, sink, len);
258
259 actual -= len;
260 }
261 }
262
263 return result;
264}
265
266static
267enum mad_flow check_message(struct mad_decoder *decoder)
268{
269 enum mad_flow result;
270 void *message = 0;
271 unsigned int size;
272
273 result = receive(decoder->async.in, &message, &size);
274
275 if (result == MAD_FLOW_CONTINUE) {
276 if (decoder->message_func == 0)
277 size = 0;
278 else {
279 result = decoder->message_func(decoder->cb_data, message, &size);
280
281 if (result == MAD_FLOW_IGNORE ||
282 result == MAD_FLOW_BREAK)
283 size = 0;
284 }
285
286 if (send(decoder->async.out, message, size) != MAD_FLOW_CONTINUE)
287 result = MAD_FLOW_BREAK;
288 }
289
290 if (message)
291 free(message);
292
293 return result;
294}
295# endif
296
297static
298enum mad_flow error_default(void *data, struct mad_stream *stream,
299 struct mad_frame *frame)
300{
301 int *bad_last_frame = data;
302
303 switch (stream->error) {
304 case MAD_ERROR_BADCRC:
305 if (*bad_last_frame)
306 mad_frame_mute(frame);
307 else
308 *bad_last_frame = 1;
309
310 return MAD_FLOW_IGNORE;
311
312 default:
313 return MAD_FLOW_CONTINUE;
314 }
315}
316
317static
318int run_sync(struct mad_decoder *decoder)
319{
320 enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *);
321 void *error_data;
322 int bad_last_frame = 0;
323 struct mad_stream *stream;
324 struct mad_frame *frame;
325 struct mad_synth *synth;
326 int result = 0;
327
328 if (decoder->input_func == 0)
329 return 0;
330
331 if (decoder->error_func) {
332 error_func = decoder->error_func;
333 error_data = decoder->cb_data;
334 }
335 else {
336 error_func = error_default;
337 error_data = &bad_last_frame;
338 }
339
340 stream = &decoder->sync->stream;
341 frame = &decoder->sync->frame;
342 synth = &decoder->sync->synth;
343
344 mad_stream_init(stream);
345 mad_frame_init(frame);
346 mad_synth_init(synth);
347
348 mad_stream_options(stream, decoder->options);
349
350 do {
351 switch (decoder->input_func(decoder->cb_data, stream)) {
352 case MAD_FLOW_STOP:
353 goto done;
354 case MAD_FLOW_BREAK:
355 goto fail;
356 case MAD_FLOW_IGNORE:
357 continue;
358 case MAD_FLOW_CONTINUE:
359 break;
360 }
361
362 while (1) {
363# if defined(USE_ASYNC)
364 if (decoder->mode == MAD_DECODER_MODE_ASYNC) {
365 switch (check_message(decoder)) {
366 case MAD_FLOW_IGNORE:
367 case MAD_FLOW_CONTINUE:
368 break;
369 case MAD_FLOW_BREAK:
370 goto fail;
371 case MAD_FLOW_STOP:
372 goto done;
373 }
374 }
375# endif
376
377 if (decoder->header_func) {
378 if (mad_header_decode(&frame->header, stream) == -1) {
379 if (!MAD_RECOVERABLE(stream->error))
380 break;
381
382 switch (error_func(error_data, stream, frame)) {
383 case MAD_FLOW_STOP:
384 goto done;
385 case MAD_FLOW_BREAK:
386 goto fail;
387 case MAD_FLOW_IGNORE:
388 case MAD_FLOW_CONTINUE:
389 default:
390 continue;
391 }
392 }
393
394 switch (decoder->header_func(decoder->cb_data, &frame->header)) {
395 case MAD_FLOW_STOP:
396 goto done;
397 case MAD_FLOW_BREAK:
398 goto fail;
399 case MAD_FLOW_IGNORE:
400 continue;
401 case MAD_FLOW_CONTINUE:
402 break;
403 }
404 }
405
406 if (mad_frame_decode(frame, stream) == -1) {
407 if (!MAD_RECOVERABLE(stream->error))
408 break;
409
410 switch (error_func(error_data, stream, frame)) {
411 case MAD_FLOW_STOP:
412 goto done;
413 case MAD_FLOW_BREAK:
414 goto fail;
415 case MAD_FLOW_IGNORE:
416 break;
417 case MAD_FLOW_CONTINUE:
418 default:
419 continue;
420 }
421 }
422 else
423 bad_last_frame = 0;
424
425 if (decoder->filter_func) {
426 switch (decoder->filter_func(decoder->cb_data, stream, frame)) {
427 case MAD_FLOW_STOP:
428 goto done;
429 case MAD_FLOW_BREAK:
430 goto fail;
431 case MAD_FLOW_IGNORE:
432 continue;
433 case MAD_FLOW_CONTINUE:
434 break;
435 }
436 }
437
438 mad_synth_frame(synth, frame);
439
440 if (decoder->output_func) {
441 switch (decoder->output_func(decoder->cb_data,
442 &frame->header, &synth->pcm)) {
443 case MAD_FLOW_STOP:
444 goto done;
445 case MAD_FLOW_BREAK:
446 goto fail;
447 case MAD_FLOW_IGNORE:
448 case MAD_FLOW_CONTINUE:
449 break;
450 }
451 }
452 }
453 }
454 while (stream->error == MAD_ERROR_BUFLEN);
455
456 fail:
457 result = -1;
458
459 done:
460 mad_synth_finish(synth);
461 mad_frame_finish(frame);
462 mad_stream_finish(stream);
463
464 return result;
465}
466
467# if defined(USE_ASYNC)
468static
469int run_async(struct mad_decoder *decoder)
470{
471 pid_t pid;
472 int ptoc[2], ctop[2], flags;
473
474 if (pipe(ptoc) == -1)
475 return -1;
476
477 if (pipe(ctop) == -1) {
478 close(ptoc[0]);
479 close(ptoc[1]);
480 return -1;
481 }
482
483 flags = fcntl(ptoc[0], F_GETFL);
484 if (flags == -1 ||
485 fcntl(ptoc[0], F_SETFL, flags | O_NONBLOCK) == -1) {
486 close(ctop[0]);
487 close(ctop[1]);
488 close(ptoc[0]);
489 close(ptoc[1]);
490 return -1;
491 }
492
493 pid = fork();
494 if (pid == -1) {
495 close(ctop[0]);
496 close(ctop[1]);
497 close(ptoc[0]);
498 close(ptoc[1]);
499 return -1;
500 }
501
502 decoder->async.pid = pid;
503
504 if (pid) {
505 /* parent */
506
507 close(ptoc[0]);
508 close(ctop[1]);
509
510 decoder->async.in = ctop[0];
511 decoder->async.out = ptoc[1];
512
513 return 0;
514 }
515
516 /* child */
517
518 close(ptoc[1]);
519 close(ctop[0]);
520
521 decoder->async.in = ptoc[0];
522 decoder->async.out = ctop[1];
523
524 _exit(run_sync(decoder));
525
526 /* not reached */
527 return -1;
528}
529# endif
530
531/*
532 * NAME: decoder->run()
533 * DESCRIPTION: run the decoder thread either synchronously or asynchronously
534 */
535int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
536{
537 int result;
538 int (*run)(struct mad_decoder *) = 0;
539
540 switch (decoder->mode = mode) {
541 case MAD_DECODER_MODE_SYNC:
542 run = run_sync;
543 break;
544
545 case MAD_DECODER_MODE_ASYNC:
546# if defined(USE_ASYNC)
547 run = run_async;
548# endif
549 break;
550 }
551
552 if (run == 0)
553 return -1;
554
555 decoder->sync = malloc(sizeof(*decoder->sync));
556 if (decoder->sync == 0)
557 return -1;
558
559 result = run(decoder);
560
561 free(decoder->sync);
562 decoder->sync = 0;
563
564 return result;
565}
566
567/*
568 * NAME: decoder->message()
569 * DESCRIPTION: send a message to and receive a reply from the decoder process
570 */
571int mad_decoder_message(struct mad_decoder *decoder,
572 void *message, unsigned int *len)
573{
574# if defined(USE_ASYNC)
575 if (decoder->mode != MAD_DECODER_MODE_ASYNC ||
576 send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE ||
577 receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE)
578 return -1;
579
580 return 0;
581# else
582 /* Avoid compiler warnings */
583 (void)decoder;
584 (void)message;
585 (void)len;
586 return -1;
587# endif
588}
589#endif
diff --git a/apps/codecs/libmad/decoder.h b/apps/codecs/libmad/decoder.h
deleted file mode 100644
index 7700df6f9b..0000000000
--- a/apps/codecs/libmad/decoder.h
+++ /dev/null
@@ -1,93 +0,0 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id$
20 */
21
22# ifndef LIBMAD_DECODER_H
23# define LIBMAD_DECODER_H
24
25# include "stream.h"
26# include "frame.h"
27# include "synth.h"
28
29enum mad_decoder_mode {
30 MAD_DECODER_MODE_SYNC = 0,
31 MAD_DECODER_MODE_ASYNC
32};
33
34enum mad_flow {
35 MAD_FLOW_CONTINUE = 0x0000, /* continue normally */
36 MAD_FLOW_STOP = 0x0010, /* stop decoding normally */
37 MAD_FLOW_BREAK = 0x0011, /* stop decoding and signal an error */
38 MAD_FLOW_IGNORE = 0x0020 /* ignore the current frame */
39};
40
41struct mad_decoder {
42 enum mad_decoder_mode mode;
43
44 int options;
45
46 struct {
47 long pid;
48 int in;
49 int out;
50 } async;
51
52 struct {
53 struct mad_stream stream;
54 struct mad_frame frame;
55 struct mad_synth synth;
56 } *sync;
57
58 void *cb_data;
59/* rockbox: unused
60 enum mad_flow (*input_func)(void *, struct mad_stream *);
61 enum mad_flow (*header_func)(void *, struct mad_header const *);
62 enum mad_flow (*filter_func)(void *,
63 struct mad_stream const *, struct mad_frame *);
64 enum mad_flow (*output_func)(void *,
65 struct mad_header const *, struct mad_pcm *);
66 enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *);
67 enum mad_flow (*message_func)(void *, void *, unsigned int *);
68*/
69};
70/* rockbox: unused
71void mad_decoder_init(struct mad_decoder *, void *,
72 enum mad_flow (*)(void *, struct mad_stream *),
73 enum mad_flow (*)(void *, struct mad_header const *),
74 enum mad_flow (*)(void *,
75 struct mad_stream const *,
76 struct mad_frame *),
77 enum mad_flow (*)(void *,
78 struct mad_header const *,
79 struct mad_pcm *),
80 enum mad_flow (*)(void *,
81 struct mad_stream *,
82 struct mad_frame *),
83 enum mad_flow (*)(void *, void *, unsigned int *));
84int mad_decoder_finish(struct mad_decoder *);
85
86# define mad_decoder_options(decoder, opts) \
87 ((void) ((decoder)->options = (opts)))
88
89int mad_decoder_run(struct mad_decoder *, enum mad_decoder_mode);
90int mad_decoder_message(struct mad_decoder *, void *, unsigned int *);
91*/
92
93# endif
diff --git a/apps/codecs/libmad/fixed.c b/apps/codecs/libmad/fixed.c
deleted file mode 100644
index e839232058..0000000000
--- a/apps/codecs/libmad/fixed.c
+++ /dev/null
@@ -1,81 +0,0 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id$
20 */
21
22# ifdef HAVE_CONFIG_H
23# include "config.h"
24# endif
25
26# include "global.h"
27
28# include "fixed.h"
29
30/*
31 * NAME: fixed->abs()
32 * DESCRIPTION: return absolute value of a fixed-point number
33 */
34mad_fixed_t mad_f_abs(mad_fixed_t x)
35{
36 return x < 0 ? -x : x;
37}
38
39/*
40 * NAME: fixed->div()
41 * DESCRIPTION: perform division using fixed-point math
42 */
43mad_fixed_t mad_f_div(mad_fixed_t x, mad_fixed_t y)
44{
45 mad_fixed_t q, r;
46 unsigned int bits;
47
48 q = mad_f_abs(x / y);
49
50 if (x < 0) {
51 x = -x;
52 y = -y;
53 }
54
55 r = x % y;
56
57 if (y < 0) {
58 x = -x;
59 y = -y;
60 }
61
62 if (q > mad_f_intpart(MAD_F_MAX) &&
63 !(q == -mad_f_intpart(MAD_F_MIN) && r == 0 && (x < 0) != (y < 0)))
64 return 0;
65
66 for (bits = MAD_F_FRACBITS; bits && r; --bits) {
67 q <<= 1, r <<= 1;
68 if (r >= y)
69 r -= y, ++q;
70 }
71
72 /* round */
73 if (2 * r >= y)
74 ++q;
75
76 /* fix sign */
77 if ((x < 0) != (y < 0))
78 q = -q;
79
80 return q << bits;
81}
diff --git a/apps/codecs/libmad/fixed.h b/apps/codecs/libmad/fixed.h
index f77f48adcf..6015684644 100644
--- a/apps/codecs/libmad/fixed.h
+++ b/apps/codecs/libmad/fixed.h
@@ -507,9 +507,4 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y)
507# define MAD_F_SCALEBITS MAD_F_FRACBITS 507# define MAD_F_SCALEBITS MAD_F_FRACBITS
508# endif 508# endif
509 509
510/* C routines */
511
512mad_fixed_t mad_f_abs(mad_fixed_t);
513mad_fixed_t mad_f_div(mad_fixed_t, mad_fixed_t);
514
515# endif 510# endif
diff --git a/apps/codecs/libmad/frame.c b/apps/codecs/libmad/frame.c
index 0db5c5aa44..61671c7e13 100644
--- a/apps/codecs/libmad/frame.c
+++ b/apps/codecs/libmad/frame.c
@@ -315,6 +315,7 @@ int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
315 } 315 }
316 316
317 /* stream skip */ 317 /* stream skip */
318 /* rockbox: not used
318 if (stream->skiplen) { 319 if (stream->skiplen) {
319 if (!stream->sync) 320 if (!stream->sync)
320 ptr = stream->this_frame; 321 ptr = stream->this_frame;
@@ -332,6 +333,7 @@ int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
332 333
333 stream->sync = 1; 334 stream->sync = 1;
334 } 335 }
336 */
335 337
336 sync: 338 sync:
337 /* synchronize */ 339 /* synchronize */
diff --git a/apps/codecs/libmad/frame.h b/apps/codecs/libmad/frame.h
index a585b950d6..b1c6e0289d 100644
--- a/apps/codecs/libmad/frame.h
+++ b/apps/codecs/libmad/frame.h
@@ -114,7 +114,8 @@ void mad_header_init(struct mad_header *);
114int mad_header_decode(struct mad_header *, struct mad_stream *); 114int mad_header_decode(struct mad_header *, struct mad_stream *);
115 115
116void mad_frame_init(struct mad_frame *); 116void mad_frame_init(struct mad_frame *);
117void mad_frame_finish(struct mad_frame *); 117/* rockbox: not used
118void mad_frame_finish(struct mad_frame *);*/
118 119
119int mad_frame_decode(struct mad_frame *, struct mad_stream *); 120int mad_frame_decode(struct mad_frame *, struct mad_stream *);
120 121
diff --git a/apps/codecs/libmad/mad.h b/apps/codecs/libmad/mad.h
index 551f2d8e08..3ae0d88a0e 100644
--- a/apps/codecs/libmad/mad.h
+++ b/apps/codecs/libmad/mad.h
@@ -24,11 +24,8 @@
24 24
25#define FPM_DEFAULT 25#define FPM_DEFAULT
26 26
27#include "version.h"
28#include "fixed.h" 27#include "fixed.h"
29#include "bit.h" 28#include "bit.h"
30#include "timer.h"
31#include "stream.h" 29#include "stream.h"
32#include "frame.h" 30#include "frame.h"
33#include "synth.h" 31#include "synth.h"
34#include "decoder.h"
diff --git a/apps/codecs/libmad/mad.h.sed b/apps/codecs/libmad/mad.h.sed
deleted file mode 100644
index 56a1d59fa7..0000000000
--- a/apps/codecs/libmad/mad.h.sed
+++ /dev/null
@@ -1,36 +0,0 @@
1#
2# libmad - MPEG audio decoder library
3# Copyright (C) 2000-2004 Underbit Technologies, Inc.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18#
19# $Id$
20#
21
22/^\/\*$/{
23N
24s/ \* libmad - /&/
25t copy
26b next
27: copy
28g
29n
30s|^ \* \$\(Id: .*\) \$$|/* \1 */|p
31/^ \*\/$/d
32b copy
33}
34/^# *include "/d
35: next
36p
diff --git a/apps/codecs/libmad/minimad.c b/apps/codecs/libmad/minimad.c
deleted file mode 100644
index 7a23b346c2..0000000000
--- a/apps/codecs/libmad/minimad.c
+++ /dev/null
@@ -1,222 +0,0 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id$
20 */
21
22# include <stdio.h>
23# include <unistd.h>
24# include <sys/stat.h>
25# include <sys/mman.h>
26
27# include "mad.h"
28
29/*
30 * This is perhaps the simplest example use of the MAD high-level API.
31 * Standard input is mapped into memory via mmap(), then the high-level API
32 * is invoked with three callbacks: input, output, and error. The output
33 * callback converts MAD's high-resolution PCM samples to 16 bits, then
34 * writes them to standard output in little-endian, stereo-interleaved
35 * format.
36 */
37
38static int decode(unsigned char const *, unsigned long);
39
40int main(int argc, char *argv[])
41{
42 struct stat stat;
43 void *fdm;
44
45 if (argc != 1)
46 return 1;
47
48 if (fstat(STDIN_FILENO, &stat) == -1 ||
49 stat.st_size == 0)
50 return 2;
51
52 fdm = mmap(0, stat.st_size, PROT_READ, MAP_SHARED, STDIN_FILENO, 0);
53 if (fdm == MAP_FAILED)
54 return 3;
55
56 decode(fdm, stat.st_size);
57
58 if (munmap(fdm, stat.st_size) == -1)
59 return 4;
60
61 return 0;
62}
63
64/*
65 * This is a private message structure. A generic pointer to this structure
66 * is passed to each of the callback functions. Put here any data you need
67 * to access from within the callbacks.
68 */
69
70struct buffer {
71 unsigned char const *start;
72 unsigned long length;
73};
74
75/*
76 * This is the input callback. The purpose of this callback is to (re)fill
77 * the stream buffer which is to be decoded. In this example, an entire file
78 * has been mapped into memory, so we just call mad_stream_buffer() with the
79 * address and length of the mapping. When this callback is called a second
80 * time, we are finished decoding.
81 */
82
83static
84enum mad_flow input(void *data,
85 struct mad_stream *stream)
86{
87 struct buffer *buffer = data;
88
89 if (!buffer->length)
90 return MAD_FLOW_STOP;
91
92 mad_stream_buffer(stream, buffer->start, buffer->length);
93
94 buffer->length = 0;
95
96 return MAD_FLOW_CONTINUE;
97}
98
99/*
100 * The following utility routine performs simple rounding, clipping, and
101 * scaling of MAD's high-resolution samples down to 16 bits. It does not
102 * perform any dithering or noise shaping, which would be recommended to
103 * obtain any exceptional audio quality. It is therefore not recommended to
104 * use this routine if high-quality output is desired.
105 */
106
107static inline
108signed int scale(mad_fixed_t sample)
109{
110 /* round */
111 sample += (1L << (MAD_F_FRACBITS - 16));
112
113 /* clip */
114 if (sample >= MAD_F_ONE)
115 sample = MAD_F_ONE - 1;
116 else if (sample < -MAD_F_ONE)
117 sample = -MAD_F_ONE;
118
119 /* quantize */
120 return sample >> (MAD_F_FRACBITS + 1 - 16);
121}
122
123/*
124 * This is the output callback function. It is called after each frame of
125 * MPEG audio data has been completely decoded. The purpose of this callback
126 * is to output (or play) the decoded PCM audio.
127 */
128
129static
130enum mad_flow output(void *data,
131 struct mad_header const *header,
132 struct mad_pcm *pcm)
133{
134 unsigned int nchannels, nsamples;
135 mad_fixed_t const *left_ch, *right_ch;
136
137 /* pcm->samplerate contains the sampling frequency */
138
139 nchannels = pcm->channels;
140 nsamples = pcm->length;
141 left_ch = pcm->samples[0];
142 right_ch = pcm->samples[1];
143
144 while (nsamples--) {
145 signed int sample;
146
147 /* output sample(s) in 16-bit signed little-endian PCM */
148
149 sample = scale(*left_ch++);
150 putchar((sample >> 0) & 0xff);
151 putchar((sample >> 8) & 0xff);
152
153 if (nchannels == 2) {
154 sample = scale(*right_ch++);
155 putchar((sample >> 0) & 0xff);
156 putchar((sample >> 8) & 0xff);
157 }
158 }
159
160 return MAD_FLOW_CONTINUE;
161}
162
163/*
164 * This is the error callback function. It is called whenever a decoding
165 * error occurs. The error is indicated by stream->error; the list of
166 * possible MAD_ERROR_* errors can be found in the mad.h (or stream.h)
167 * header file.
168 */
169
170static
171enum mad_flow error(void *data,
172 struct mad_stream *stream,
173 struct mad_frame *frame)
174{
175 struct buffer *buffer = data;
176
177 fprintf(stderr, "decoding error 0x%04x (%s) at byte offset %u\n",
178 stream->error, mad_stream_errorstr(stream),
179 stream->this_frame - buffer->start);
180
181 /* return MAD_FLOW_BREAK here to stop decoding (and propagate an error) */
182
183 return MAD_FLOW_CONTINUE;
184}
185
186/*
187 * This is the function called by main() above to perform all the decoding.
188 * It instantiates a decoder object and configures it with the input,
189 * output, and error callback functions above. A single call to
190 * mad_decoder_run() continues until a callback function returns
191 * MAD_FLOW_STOP (to stop decoding) or MAD_FLOW_BREAK (to stop decoding and
192 * signal an error).
193 */
194
195static
196int decode(unsigned char const *start, unsigned long length)
197{
198 struct buffer buffer;
199 struct mad_decoder decoder;
200 int result;
201
202 /* initialize our private message structure */
203
204 buffer.start = start;
205 buffer.length = length;
206
207 /* configure input, output, and error functions */
208
209 mad_decoder_init(&decoder, &buffer,
210 input, 0 /* header */, 0 /* filter */, output,
211 error, 0 /* message */);
212
213 /* start decoding */
214
215 result = mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);
216
217 /* release the decoder */
218
219 mad_decoder_finish(&decoder);
220
221 return result;
222}
diff --git a/apps/codecs/libmad/stream.c b/apps/codecs/libmad/stream.c
index b0c5ad36fd..2958afc118 100644
--- a/apps/codecs/libmad/stream.c
+++ b/apps/codecs/libmad/stream.c
@@ -36,7 +36,8 @@ void mad_stream_init(struct mad_stream *stream)
36{ 36{
37 stream->buffer = 0; 37 stream->buffer = 0;
38 stream->bufend = 0; 38 stream->bufend = 0;
39 stream->skiplen = 0; 39 /* rockbox: not used
40 stream->skiplen = 0; */
40 41
41 stream->sync = 0; 42 stream->sync = 0;
42 stream->freerate = 0; 43 stream->freerate = 0;
@@ -62,6 +63,7 @@ void mad_stream_init(struct mad_stream *stream)
62 * NAME: stream->finish() 63 * NAME: stream->finish()
63 * DESCRIPTION: deallocate any dynamic memory associated with stream 64 * DESCRIPTION: deallocate any dynamic memory associated with stream
64 */ 65 */
66/* rockbox: not used
65void mad_stream_finish(struct mad_stream *stream) 67void mad_stream_finish(struct mad_stream *stream)
66{ 68{
67 if (stream->main_data) { 69 if (stream->main_data) {
@@ -71,7 +73,7 @@ void mad_stream_finish(struct mad_stream *stream)
71 73
72 mad_bit_finish(&stream->anc_ptr); 74 mad_bit_finish(&stream->anc_ptr);
73 mad_bit_finish(&stream->ptr); 75 mad_bit_finish(&stream->ptr);
74} 76} */
75 77
76/* 78/*
77 * NAME: stream->buffer() 79 * NAME: stream->buffer()
@@ -95,10 +97,11 @@ void mad_stream_buffer(struct mad_stream *stream,
95 * NAME: stream->skip() 97 * NAME: stream->skip()
96 * DESCRIPTION: arrange to skip bytes before the next frame 98 * DESCRIPTION: arrange to skip bytes before the next frame
97 */ 99 */
100/* rockbox: not used
98void mad_stream_skip(struct mad_stream *stream, unsigned long length) 101void mad_stream_skip(struct mad_stream *stream, unsigned long length)
99{ 102{
100 stream->skiplen += length; 103 stream->skiplen += length;
101} 104} */
102 105
103/* 106/*
104 * NAME: stream->sync() 107 * NAME: stream->sync()
diff --git a/apps/codecs/libmad/stream.h b/apps/codecs/libmad/stream.h
index 046708b063..0aafb98787 100644
--- a/apps/codecs/libmad/stream.h
+++ b/apps/codecs/libmad/stream.h
@@ -61,7 +61,8 @@ enum mad_error {
61struct mad_stream { 61struct mad_stream {
62 unsigned char const *buffer; /* input bitstream buffer */ 62 unsigned char const *buffer; /* input bitstream buffer */
63 unsigned char const *bufend; /* end of buffer */ 63 unsigned char const *bufend; /* end of buffer */
64 unsigned long skiplen; /* bytes to skip before next frame */ 64 /* rockbox: not used
65 unsigned long skiplen; */ /* bytes to skip before next frame */
65 66
66 int sync; /* stream sync found */ 67 int sync; /* stream sync found */
67 unsigned long freerate; /* free bitrate (fixed) */ 68 unsigned long freerate; /* free bitrate (fixed) */
@@ -94,14 +95,16 @@ enum {
94}; 95};
95 96
96void mad_stream_init(struct mad_stream *); 97void mad_stream_init(struct mad_stream *);
97void mad_stream_finish(struct mad_stream *); 98/* rockbox: not used
99void mad_stream_finish(struct mad_stream *); */
98 100
99# define mad_stream_options(stream, opts) \ 101# define mad_stream_options(stream, opts) \
100 ((void) ((stream)->options = (opts))) 102 ((void) ((stream)->options = (opts)))
101 103
102void mad_stream_buffer(struct mad_stream *, 104void mad_stream_buffer(struct mad_stream *,
103 unsigned char const *, unsigned long); 105 unsigned char const *, unsigned long);
104void mad_stream_skip(struct mad_stream *, unsigned long); 106/* rockbox: not used
107void mad_stream_skip(struct mad_stream *, unsigned long); */
105 108
106int mad_stream_sync(struct mad_stream *); 109int mad_stream_sync(struct mad_stream *);
107 110
diff --git a/apps/codecs/libmad/synth.h b/apps/codecs/libmad/synth.h
index edb951e471..93dd3946d4 100644
--- a/apps/codecs/libmad/synth.h
+++ b/apps/codecs/libmad/synth.h
@@ -41,23 +41,6 @@ struct mad_synth {
41 struct mad_pcm pcm; /* PCM output */ 41 struct mad_pcm pcm; /* PCM output */
42}; 42};
43 43
44/* single channel PCM selector */
45enum {
46 MAD_PCM_CHANNEL_SINGLE = 0
47};
48
49/* dual channel PCM selector */
50enum {
51 MAD_PCM_CHANNEL_DUAL_1 = 0,
52 MAD_PCM_CHANNEL_DUAL_2 = 1
53};
54
55/* stereo PCM selector */
56enum {
57 MAD_PCM_CHANNEL_STEREO_LEFT = 0,
58 MAD_PCM_CHANNEL_STEREO_RIGHT = 1
59};
60
61void mad_synth_init(struct mad_synth *); 44void mad_synth_init(struct mad_synth *);
62 45
63# define mad_synth_finish(synth) /* nothing */ 46# define mad_synth_finish(synth) /* nothing */
diff --git a/apps/codecs/libmad/timer.c b/apps/codecs/libmad/timer.c
deleted file mode 100644
index a6c64795b3..0000000000
--- a/apps/codecs/libmad/timer.c
+++ /dev/null
@@ -1,488 +0,0 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id$
20 */
21
22# ifdef HAVE_CONFIG_H
23# include "config.h"
24# endif
25
26# include "global.h"
27
28# include <stdio.h>
29
30# ifdef HAVE_ASSERT_H
31# include <assert.h>
32# endif
33
34# include "timer.h"
35
36mad_timer_t const mad_timer_zero = { 0, 0 };
37
38/*
39 * NAME: timer->compare()
40 * DESCRIPTION: indicate relative order of two timers
41 */
42int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2)
43{
44 signed long diff;
45
46 diff = timer1.seconds - timer2.seconds;
47 if (diff < 0)
48 return -1;
49 else if (diff > 0)
50 return +1;
51
52 diff = timer1.fraction - timer2.fraction;
53 if (diff < 0)
54 return -1;
55 else if (diff > 0)
56 return +1;
57
58 return 0;
59}
60
61/*
62 * NAME: timer->negate()
63 * DESCRIPTION: invert the sign of a timer
64 */
65void mad_timer_negate(mad_timer_t *timer)
66{
67 timer->seconds = -timer->seconds;
68
69 if (timer->fraction) {
70 timer->seconds -= 1;
71 timer->fraction = MAD_TIMER_RESOLUTION - timer->fraction;
72 }
73}
74
75/*
76 * NAME: timer->abs()
77 * DESCRIPTION: return the absolute value of a timer
78 */
79mad_timer_t mad_timer_abs(mad_timer_t timer)
80{
81 if (timer.seconds < 0)
82 mad_timer_negate(&timer);
83
84 return timer;
85}
86
87/*
88 * NAME: reduce_timer()
89 * DESCRIPTION: carry timer fraction into seconds
90 */
91static
92void reduce_timer(mad_timer_t *timer)
93{
94 timer->seconds += timer->fraction / MAD_TIMER_RESOLUTION;
95 timer->fraction %= MAD_TIMER_RESOLUTION;
96}
97
98/*
99 * NAME: gcd()
100 * DESCRIPTION: compute greatest common denominator
101 */
102static
103unsigned long gcd(unsigned long num1, unsigned long num2)
104{
105 unsigned long tmp;
106
107 while (num2) {
108 tmp = num2;
109 num2 = num1 % num2;
110 num1 = tmp;
111 }
112
113 return num1;
114}
115
116/*
117 * NAME: reduce_rational()
118 * DESCRIPTION: convert rational expression to lowest terms
119 */
120static
121void reduce_rational(unsigned long *numer, unsigned long *denom)
122{
123 unsigned long factor;
124
125 factor = gcd(*numer, *denom);
126
127 assert(factor != 0);
128
129 *numer /= factor;
130 *denom /= factor;
131}
132
133/*
134 * NAME: scale_rational()
135 * DESCRIPTION: solve numer/denom == ?/scale avoiding overflowing
136 */
137static
138unsigned long scale_rational(unsigned long numer, unsigned long denom,
139 unsigned long scale)
140{
141 reduce_rational(&numer, &denom);
142 reduce_rational(&scale, &denom);
143
144 assert(denom != 0);
145
146 if (denom < scale)
147 return numer * (scale / denom) + numer * (scale % denom) / denom;
148 if (denom < numer)
149 return scale * (numer / denom) + scale * (numer % denom) / denom;
150
151 return numer * scale / denom;
152}
153
154/*
155 * NAME: timer->set()
156 * DESCRIPTION: set timer to specific (positive) value
157 */
158void mad_timer_set(mad_timer_t *timer, unsigned long seconds,
159 unsigned long numer, unsigned long denom)
160{
161 timer->seconds = seconds;
162 if (numer >= denom && denom > 0) {
163 timer->seconds += numer / denom;
164 numer %= denom;
165 }
166
167 switch (denom) {
168 case 0:
169 case 1:
170 timer->fraction = 0;
171 break;
172
173 case MAD_TIMER_RESOLUTION:
174 timer->fraction = numer;
175 break;
176
177 case 1000:
178 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 1000);
179 break;
180
181 case 8000:
182 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 8000);
183 break;
184
185 case 11025:
186 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 11025);
187 break;
188
189 case 12000:
190 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 12000);
191 break;
192
193 case 16000:
194 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 16000);
195 break;
196
197 case 22050:
198 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 22050);
199 break;
200
201 case 24000:
202 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 24000);
203 break;
204
205 case 32000:
206 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 32000);
207 break;
208
209 case 44100:
210 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 44100);
211 break;
212
213 case 48000:
214 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 48000);
215 break;
216
217 default:
218 timer->fraction = scale_rational(numer, denom, MAD_TIMER_RESOLUTION);
219 break;
220 }
221
222 if (timer->fraction >= MAD_TIMER_RESOLUTION)
223 reduce_timer(timer);
224}
225
226/*
227 * NAME: timer->add()
228 * DESCRIPTION: add one timer to another
229 */
230void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
231{
232 timer->seconds += incr.seconds;
233 timer->fraction += incr.fraction;
234
235 if (timer->fraction >= MAD_TIMER_RESOLUTION)
236 reduce_timer(timer);
237}
238
239/*
240 * NAME: timer->multiply()
241 * DESCRIPTION: multiply a timer by a scalar value
242 */
243void mad_timer_multiply(mad_timer_t *timer, signed long scalar)
244{
245 mad_timer_t addend;
246 unsigned long factor;
247
248 factor = scalar;
249 if (scalar < 0) {
250 factor = -scalar;
251 mad_timer_negate(timer);
252 }
253
254 addend = *timer;
255 *timer = mad_timer_zero;
256
257 while (factor) {
258 if (factor & 1)
259 mad_timer_add(timer, addend);
260
261 mad_timer_add(&addend, addend);
262 factor >>= 1;
263 }
264}
265
266/*
267 * NAME: timer->count()
268 * DESCRIPTION: return timer value in selected units
269 */
270signed long mad_timer_count(mad_timer_t timer, enum mad_units units)
271{
272 switch (units) {
273 case MAD_UNITS_HOURS:
274 return timer.seconds / 60 / 60;
275
276 case MAD_UNITS_MINUTES:
277 return timer.seconds / 60;
278
279 case MAD_UNITS_SECONDS:
280 return timer.seconds;
281
282 case MAD_UNITS_DECISECONDS:
283 case MAD_UNITS_CENTISECONDS:
284 case MAD_UNITS_MILLISECONDS:
285
286 case MAD_UNITS_8000_HZ:
287 case MAD_UNITS_11025_HZ:
288 case MAD_UNITS_12000_HZ:
289 case MAD_UNITS_16000_HZ:
290 case MAD_UNITS_22050_HZ:
291 case MAD_UNITS_24000_HZ:
292 case MAD_UNITS_32000_HZ:
293 case MAD_UNITS_44100_HZ:
294 case MAD_UNITS_48000_HZ:
295
296 case MAD_UNITS_24_FPS:
297 case MAD_UNITS_25_FPS:
298 case MAD_UNITS_30_FPS:
299 case MAD_UNITS_48_FPS:
300 case MAD_UNITS_50_FPS:
301 case MAD_UNITS_60_FPS:
302 case MAD_UNITS_75_FPS:
303 return timer.seconds * (signed long) units +
304 (signed long) scale_rational(timer.fraction, MAD_TIMER_RESOLUTION,
305 units);
306
307 case MAD_UNITS_23_976_FPS:
308 case MAD_UNITS_24_975_FPS:
309 case MAD_UNITS_29_97_FPS:
310 case MAD_UNITS_47_952_FPS:
311 case MAD_UNITS_49_95_FPS:
312 case MAD_UNITS_59_94_FPS:
313 return (mad_timer_count(timer, -units) + 1) * 1000 / 1001;
314 }
315
316 /* unsupported units */
317 return 0;
318}
319
320/*
321 * NAME: timer->fraction()
322 * DESCRIPTION: return fractional part of timer in arbitrary terms
323 */
324unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long denom)
325{
326 timer = mad_timer_abs(timer);
327
328 switch (denom) {
329 case 0:
330 return timer.fraction ?
331 MAD_TIMER_RESOLUTION / timer.fraction : MAD_TIMER_RESOLUTION + 1;
332
333 case MAD_TIMER_RESOLUTION:
334 return timer.fraction;
335
336 default:
337 return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, denom);
338 }
339}
340
341/*
342 * NAME: timer->string()
343 * DESCRIPTION: write a string representation of a timer using a template
344 */
345void mad_timer_string(mad_timer_t timer,
346 char *dest, char const *format, enum mad_units units,
347 enum mad_units fracunits, unsigned long subparts)
348{
349 unsigned long hours, minutes, seconds, sub;
350 unsigned int frac;
351
352 timer = mad_timer_abs(timer);
353
354 seconds = timer.seconds;
355 frac = sub = 0;
356
357 dest[0]=0;
358 (void)format;
359
360 switch (fracunits) {
361 case MAD_UNITS_HOURS:
362 case MAD_UNITS_MINUTES:
363 case MAD_UNITS_SECONDS:
364 break;
365
366 case MAD_UNITS_DECISECONDS:
367 case MAD_UNITS_CENTISECONDS:
368 case MAD_UNITS_MILLISECONDS:
369
370 case MAD_UNITS_8000_HZ:
371 case MAD_UNITS_11025_HZ:
372 case MAD_UNITS_12000_HZ:
373 case MAD_UNITS_16000_HZ:
374 case MAD_UNITS_22050_HZ:
375 case MAD_UNITS_24000_HZ:
376 case MAD_UNITS_32000_HZ:
377 case MAD_UNITS_44100_HZ:
378 case MAD_UNITS_48000_HZ:
379
380 case MAD_UNITS_24_FPS:
381 case MAD_UNITS_25_FPS:
382 case MAD_UNITS_30_FPS:
383 case MAD_UNITS_48_FPS:
384 case MAD_UNITS_50_FPS:
385 case MAD_UNITS_60_FPS:
386 case MAD_UNITS_75_FPS:
387 {
388 unsigned long denom;
389
390 denom = MAD_TIMER_RESOLUTION / fracunits;
391
392 frac = timer.fraction / denom;
393 sub = scale_rational(timer.fraction % denom, denom, subparts);
394 }
395 break;
396
397 case MAD_UNITS_23_976_FPS:
398 case MAD_UNITS_24_975_FPS:
399 case MAD_UNITS_29_97_FPS:
400 case MAD_UNITS_47_952_FPS:
401 case MAD_UNITS_49_95_FPS:
402 case MAD_UNITS_59_94_FPS:
403 /* drop-frame encoding */
404 /* N.B. this is only well-defined for MAD_UNITS_29_97_FPS */
405 {
406 unsigned long frame, cycle, d, m;
407
408 frame = mad_timer_count(timer, fracunits);
409
410 cycle = -fracunits * 60 * 10 - (10 - 1) * 2;
411
412 d = frame / cycle;
413 m = frame % cycle;
414 frame += (10 - 1) * 2 * d;
415 if (m > 2)
416 frame += 2 * ((m - 2) / (cycle / 10));
417
418 frac = frame % -fracunits;
419 seconds = frame / -fracunits;
420 }
421 break;
422 }
423
424 switch (units) {
425 case MAD_UNITS_HOURS:
426 minutes = seconds / 60;
427 hours = minutes / 60;
428
429// sprintf(dest, format,
430// hours,
431// (unsigned int) (minutes % 60),
432// (unsigned int) (seconds % 60),
433// frac, sub);
434 break;
435
436 case MAD_UNITS_MINUTES:
437 minutes = seconds / 60;
438
439// sprintf(dest, format,
440// minutes,
441// (unsigned int) (seconds % 60),
442// frac, sub);
443 break;
444
445 case MAD_UNITS_SECONDS:
446// sprintf(dest, format,
447// seconds,
448// frac, sub);
449 break;
450
451 case MAD_UNITS_23_976_FPS:
452 case MAD_UNITS_24_975_FPS:
453 case MAD_UNITS_29_97_FPS:
454 case MAD_UNITS_47_952_FPS:
455 case MAD_UNITS_49_95_FPS:
456 case MAD_UNITS_59_94_FPS:
457 if (fracunits < 0) {
458 /* not yet implemented */
459 sub = 0;
460 }
461
462 /* fall through */
463
464 case MAD_UNITS_DECISECONDS:
465 case MAD_UNITS_CENTISECONDS:
466 case MAD_UNITS_MILLISECONDS:
467
468 case MAD_UNITS_8000_HZ:
469 case MAD_UNITS_11025_HZ:
470 case MAD_UNITS_12000_HZ:
471 case MAD_UNITS_16000_HZ:
472 case MAD_UNITS_22050_HZ:
473 case MAD_UNITS_24000_HZ:
474 case MAD_UNITS_32000_HZ:
475 case MAD_UNITS_44100_HZ:
476 case MAD_UNITS_48000_HZ:
477
478 case MAD_UNITS_24_FPS:
479 case MAD_UNITS_25_FPS:
480 case MAD_UNITS_30_FPS:
481 case MAD_UNITS_48_FPS:
482 case MAD_UNITS_50_FPS:
483 case MAD_UNITS_60_FPS:
484 case MAD_UNITS_75_FPS:
485// sprintf(dest, format, mad_timer_count(timer, units), sub);
486 break;
487 }
488}
diff --git a/apps/codecs/libmad/timer.h b/apps/codecs/libmad/timer.h
deleted file mode 100644
index e890c48fe5..0000000000
--- a/apps/codecs/libmad/timer.h
+++ /dev/null
@@ -1,100 +0,0 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id$
20 */
21
22# ifndef LIBMAD_TIMER_H
23# define LIBMAD_TIMER_H
24
25typedef struct {
26 signed long seconds; /* whole seconds */
27 unsigned long fraction; /* 1/MAD_TIMER_RESOLUTION seconds */
28} mad_timer_t;
29
30extern mad_timer_t const mad_timer_zero;
31
32# define MAD_TIMER_RESOLUTION 352800000UL
33
34enum mad_units {
35 MAD_UNITS_HOURS = -2,
36 MAD_UNITS_MINUTES = -1,
37 MAD_UNITS_SECONDS = 0,
38
39 /* metric units */
40
41 MAD_UNITS_DECISECONDS = 10,
42 MAD_UNITS_CENTISECONDS = 100,
43 MAD_UNITS_MILLISECONDS = 1000,
44
45 /* audio sample units */
46
47 MAD_UNITS_8000_HZ = 8000,
48 MAD_UNITS_11025_HZ = 11025,
49 MAD_UNITS_12000_HZ = 12000,
50
51 MAD_UNITS_16000_HZ = 16000,
52 MAD_UNITS_22050_HZ = 22050,
53 MAD_UNITS_24000_HZ = 24000,
54
55 MAD_UNITS_32000_HZ = 32000,
56 MAD_UNITS_44100_HZ = 44100,
57 MAD_UNITS_48000_HZ = 48000,
58
59 /* video frame/field units */
60
61 MAD_UNITS_24_FPS = 24,
62 MAD_UNITS_25_FPS = 25,
63 MAD_UNITS_30_FPS = 30,
64 MAD_UNITS_48_FPS = 48,
65 MAD_UNITS_50_FPS = 50,
66 MAD_UNITS_60_FPS = 60,
67
68 /* CD audio frames */
69
70 MAD_UNITS_75_FPS = 75,
71
72 /* video drop-frame units */
73
74 MAD_UNITS_23_976_FPS = -24,
75 MAD_UNITS_24_975_FPS = -25,
76 MAD_UNITS_29_97_FPS = -30,
77 MAD_UNITS_47_952_FPS = -48,
78 MAD_UNITS_49_95_FPS = -50,
79 MAD_UNITS_59_94_FPS = -60
80};
81
82# define mad_timer_reset(timer) ((void) (*(timer) = mad_timer_zero))
83
84int mad_timer_compare(mad_timer_t, mad_timer_t);
85
86# define mad_timer_sign(timer) mad_timer_compare((timer), mad_timer_zero)
87
88void mad_timer_negate(mad_timer_t *);
89mad_timer_t mad_timer_abs(mad_timer_t);
90
91void mad_timer_set(mad_timer_t *, unsigned long, unsigned long, unsigned long);
92void mad_timer_add(mad_timer_t *, mad_timer_t);
93void mad_timer_multiply(mad_timer_t *, signed long);
94
95signed long mad_timer_count(mad_timer_t, enum mad_units);
96unsigned long mad_timer_fraction(mad_timer_t, unsigned long);
97void mad_timer_string(mad_timer_t, char *, char const *,
98 enum mad_units, enum mad_units, unsigned long);
99
100# endif
diff --git a/apps/codecs/libmad/version.c b/apps/codecs/libmad/version.c
deleted file mode 100644
index 89ca22964e..0000000000
--- a/apps/codecs/libmad/version.c
+++ /dev/null
@@ -1,74 +0,0 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id$
20 */
21
22# ifdef HAVE_CONFIG_H
23# include "config.h"
24# endif
25
26# include "global.h"
27
28# include "version.h"
29
30char const mad_version[] = "MPEG Audio Decoder " MAD_VERSION;
31char const mad_copyright[] = "Copyright (C) " MAD_PUBLISHYEAR " " MAD_AUTHOR;
32char const mad_author[] = MAD_AUTHOR " <" MAD_EMAIL ">";
33
34char const mad_build[] = ""
35# if defined(DEBUG)
36 "DEBUG "
37# elif defined(NDEBUG)
38 "NDEBUG "
39# endif
40
41# if defined(EXPERIMENTAL)
42 "EXPERIMENTAL "
43# endif
44
45# if defined(FPM_64BIT)
46 "FPM_64BIT "
47# elif defined(FPM_INTEL)
48 "FPM_INTEL "
49# elif defined(FPM_ARM)
50 "FPM_ARM "
51# elif defined(FPM_MIPS)
52 "FPM_MIPS "
53# elif defined(FPM_SPARC)
54 "FPM_SPARC "
55# elif defined(FPM_PPC)
56 "FPM_PPC "
57# elif defined(FPM_DEFAULT)
58 "FPM_DEFAULT "
59# endif
60
61# if defined(OPT_SPEED)
62 "OPT_SPEED "
63# elif defined(OPT_ACCURACY)
64 "OPT_ACCURACY "
65# endif
66
67# if defined(OPT_SSO)
68 "OPT_SSO "
69# endif
70
71# if defined(OPT_STRICT)
72 "OPT_STRICT "
73# endif
74;
diff --git a/apps/codecs/libmad/version.h b/apps/codecs/libmad/version.h
deleted file mode 100644
index 0bf662fedd..0000000000
--- a/apps/codecs/libmad/version.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id$
20 */
21
22# ifndef LIBMAD_VERSION_H
23# define LIBMAD_VERSION_H
24
25# define MAD_VERSION_MAJOR 0
26# define MAD_VERSION_MINOR 15
27# define MAD_VERSION_PATCH 1
28# define MAD_VERSION_EXTRA " (beta)"
29
30# define MAD_VERSION_STRINGIZE(str) #str
31# define MAD_VERSION_STRING(num) MAD_VERSION_STRINGIZE(num)
32
33# define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) "." \
34 MAD_VERSION_STRING(MAD_VERSION_MINOR) "." \
35 MAD_VERSION_STRING(MAD_VERSION_PATCH) \
36 MAD_VERSION_EXTRA
37
38# define MAD_PUBLISHYEAR "2000-2004"
39# define MAD_AUTHOR "Underbit Technologies, Inc."
40# define MAD_EMAIL "info@underbit.com"
41
42extern char const mad_version[];
43extern char const mad_copyright[];
44extern char const mad_author[];
45extern char const mad_build[];
46
47# endif