Skip to content

Commit eb14ad2

Browse files
committed
mad: code cleanup
1 parent 7af7812 commit eb14ad2

File tree

25 files changed

+239
-2340
lines changed

25 files changed

+239
-2340
lines changed

components/mad/align.c

Lines changed: 0 additions & 18 deletions
This file was deleted.

components/mad/align.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

components/mad/bit.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
# endif
3333

3434
# include "bit.h"
35-
#include "align.h"
3635

3736
/*
3837
* This is the lookup table for computing the CRC-check word.
@@ -191,7 +190,6 @@ void mad_bit_write(struct mad_bitptr *bitptr, unsigned int len,
191190
}
192191
# endif
193192

194-
195193
/*
196194
* NAME: bit->crc()
197195
* DESCRIPTION: compute CRC-check word
@@ -206,22 +204,24 @@ unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len,
206204

207205
data = mad_bit_read(&bitptr, 32);
208206

209-
crc = (crc << 8) ^ unalShort(&crc_table[((crc >> 8) ^ (data >> 24)) & 0xff]);
210-
crc = (crc << 8) ^ unalShort(&crc_table[((crc >> 8) ^ (data >> 16)) & 0xff]);
211-
crc = (crc << 8) ^ unalShort(&crc_table[((crc >> 8) ^ (data >> 8)) & 0xff]);
212-
crc = (crc << 8) ^ unalShort(&crc_table[((crc >> 8) ^ (data >> 0)) & 0xff]);
207+
crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 24)) & 0xff];
208+
crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 16)) & 0xff];
209+
crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 8)) & 0xff];
210+
crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 0)) & 0xff];
213211
}
214212

215213
switch (len / 8) {
216214
case 3: crc = (crc << 8) ^
217-
unalShort(&crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff]);
215+
crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
218216
/* fall through */
219217
case 2: crc = (crc << 8) ^
220-
unalShort(&crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff]);
218+
crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
221219
/* fall through */
222220
case 1: crc = (crc << 8) ^
223-
unalShort(&crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff]);
224-
len %= 8;
221+
crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
222+
223+
len %= 8;
224+
225225
case 0: break;
226226
}
227227

components/mad/config.h

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* config.h. Generated by configure. */
2-
/* config.h.in. Generated from configure.ac by autoheader. */
32

43
/* Define to enable diagnostic debugging support. */
54
/* #undef DEBUG */
@@ -8,7 +7,7 @@
87
/* #undef EXPERIMENTAL */
98

109
/* Define to disable debugging assertions. */
11-
/* #define NDEBUG */
10+
#define NDEBUG
1211

1312
/* Define to optimize for accuracy over speed. */
1413
/* #undef OPT_ACCURACY */
@@ -23,53 +22,4 @@
2322
if this is in opposition with best accepted practices. */
2423
/* #undef OPT_STRICT */
2524

26-
/* Name of package */
27-
#define PACKAGE "libmad"
28-
29-
/* Define to the address where bug reports for this package should be sent. */
30-
#define PACKAGE_BUGREPORT "support@underbit.com"
31-
32-
/* Define to the full name of this package. */
33-
#define PACKAGE_NAME "MPEG Audio Decoder"
34-
35-
/* Define to the full name and version of this package. */
36-
#define PACKAGE_STRING "MPEG Audio Decoder 0.15.1b"
37-
38-
/* Define to the one symbol short name of this package. */
39-
#define PACKAGE_TARNAME "libmad"
40-
41-
/* Define to the version of this package. */
42-
#define PACKAGE_VERSION "0.15.1b"
43-
44-
/* The size of a `int', as computed by sizeof. */
45-
#define SIZEOF_INT 4
46-
47-
/* The size of a `long', as computed by sizeof. */
48-
#define SIZEOF_LONG 4
49-
50-
/* The size of a `long long', as computed by sizeof. */
51-
#define SIZEOF_LONG_LONG 8
52-
53-
/* Define to 1 if you have the ANSI C header files. */
54-
#undef STDC_HEADERS
55-
56-
/* Version number of package */
57-
#define VERSION "0.15.1b"
58-
59-
/* Define to 1 if your processor stores words with the most significant byte
60-
first (like Motorola and SPARC, unlike Intel and VAX). */
61-
/* #undef WORDS_BIGENDIAN */
62-
63-
/* Define to empty if `const' does not conform to ANSI C. */
64-
/* #undef const */
65-
66-
/* Define to `__inline__' or `__inline' if that's what the C compiler
67-
calls it, or to nothing if 'inline' is not supported under any name. */
68-
#ifndef __cplusplus
69-
/* #undef inline */
70-
#endif
71-
7225
#define FPM_DEFAULT
73-
74-
/* Define to `int' if <sys/types.h> does not define. */
75-
/* #undef pid_t */

components/mad/decoder.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,7 @@ int run_sync(struct mad_decoder *decoder)
322322
struct mad_frame *frame;
323323
struct mad_synth *synth;
324324
int result = 0;
325-
int r;
326325

327-
// printf("run_sync\n");
328326
if (decoder->input_func == 0)
329327
return 0;
330328

@@ -348,9 +346,7 @@ int run_sync(struct mad_decoder *decoder)
348346
mad_stream_options(stream, decoder->options);
349347

350348
do {
351-
r=decoder->input_func(decoder->cb_data, stream);
352-
// printf("Input fn: %d\n", r);
353-
switch (r) {
349+
switch (decoder->input_func(decoder->cb_data, stream)) {
354350
case MAD_FLOW_STOP:
355351
goto done;
356352
case MAD_FLOW_BREAK:
@@ -377,9 +373,7 @@ int run_sync(struct mad_decoder *decoder)
377373
# endif
378374

379375
if (decoder->header_func) {
380-
r=mad_header_decode(&frame->header, stream);
381-
// printf("mad_header_decode_func: %d\n", r);
382-
if (r!=-1) {
376+
if (mad_header_decode(&frame->header, stream) == -1) {
383377
if (!MAD_RECOVERABLE(stream->error))
384378
break;
385379

@@ -407,9 +401,7 @@ int run_sync(struct mad_decoder *decoder)
407401
}
408402
}
409403

410-
r=mad_frame_decode(frame, stream);
411-
// printf("mad_frame_decode: %d\n", r);
412-
if (r == -1) {
404+
if (mad_frame_decode(frame, stream) == -1) {
413405
if (!MAD_RECOVERABLE(stream->error))
414406
break;
415407

@@ -443,7 +435,6 @@ int run_sync(struct mad_decoder *decoder)
443435

444436
mad_synth_frame(synth, frame);
445437

446-
// printf("Calling output fn\n");
447438
if (decoder->output_func) {
448439
switch (decoder->output_func(decoder->cb_data,
449440
&frame->header, &synth->pcm)) {
@@ -543,7 +534,6 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
543534
{
544535
int result;
545536
int (*run)(struct mad_decoder *) = 0;
546-
static struct sync_t decsync; //statically-allocated decoder obj
547537

548538
switch (decoder->mode = mode) {
549539
case MAD_DECODER_MODE_SYNC:
@@ -560,15 +550,14 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
560550
if (run == 0)
561551
return -1;
562552

563-
// decoder->sync = malloc(sizeof(*decoder->sync));
564-
decoder->sync=&decsync;
553+
decoder->sync = malloc(sizeof(*decoder->sync));
565554
if (decoder->sync == 0)
566555
return -1;
567556

568557
result = run(decoder);
569558

570-
// free(decoder->sync);
571-
// decoder->sync = 0;
559+
free(decoder->sync);
560+
decoder->sync = 0;
572561

573562
return result;
574563
}

components/mad/decoder.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,6 @@ enum mad_flow {
3838
MAD_FLOW_IGNORE = 0x0020 /* ignore the current frame */
3939
};
4040

41-
42-
struct sync_t {
43-
struct mad_stream stream; // definito main_data_t un array di circa 4K
44-
struct mad_frame frame;
45-
struct mad_synth synth;
46-
};
47-
48-
// # define MAD_BUFFER_GUARD 8
49-
// # define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD)
50-
// typedef unsigned char main_data_t[MAD_BUFFER_MDLEN]; 2567
51-
52-
// in frame.h
53-
// struct mad_frame {
54-
// struct mad_header header; /* MPEG audio header */
55-
//
56-
// int options; /* decoding options (from stream) */
57-
//
58-
// mad_fixed_t sbsample[2][36][32]; /* synthesis subband filter samples 9216 */
59-
// mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data 4608 */
60-
//};
61-
//
62-
// in synth.h
63-
//struct mad_synth {
64-
// mad_fixed_t filter[2][2][2][16][8]; /* polyphase filterbank outputs 4096 */
65-
// /* [ch][eo][peo][s][v] */
66-
//
67-
// unsigned int phase; /* current processing phase */
68-
// struct mad_pcm pcm; /* PCM output */
69-
//};
70-
7141
struct mad_decoder {
7242
enum mad_decoder_mode mode;
7343

@@ -79,16 +49,12 @@ struct mad_decoder {
7949
int out;
8050
} async;
8151

82-
/*
8352
struct {
8453
struct mad_stream stream;
8554
struct mad_frame frame;
8655
struct mad_synth synth;
8756
} *sync;
8857

89-
*/
90-
struct sync_t *sync;
91-
9258
void *cb_data;
9359

9460
enum mad_flow (*input_func)(void *, struct mad_stream *);

components/mad/frame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void mad_frame_finish(struct mad_frame *frame)
107107
mad_header_finish(&frame->header);
108108

109109
if (frame->overlap) {
110-
// free(frame->overlap);
110+
free(frame->overlap);
111111
frame->overlap = 0;
112112
}
113113
}

components/mad/frame.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
# ifndef LIBMAD_FRAME_H
2323
# define LIBMAD_FRAME_H
2424

25-
2625
# include "fixed.h"
2726
# include "timer.h"
2827
# include "stream.h"

components/mad/global.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
# ifndef LIBMAD_GLOBAL_H
2323
# define LIBMAD_GLOBAL_H
2424

25-
// #include "esp_common.h"
26-
#include "config.h"
2725
/* conditional debugging */
2826

2927
# if defined(DEBUG) && defined(NDEBUG)
@@ -50,11 +48,11 @@
5048
# endif
5149

5250
# if !defined(HAVE_ASSERT_H)
53-
//# if defined(NDEBUG)
51+
# if defined(NDEBUG)
5452
# define assert(x) /* nothing */
55-
//# else
56-
//# define assert(x) do { if (!(x)) abort(); } while (0)
57-
//# endif
53+
# else
54+
# define assert(x) do { if (!(x)) abort(); } while (0)
55+
# endif
5856
# endif
5957

6058
# endif

components/mad/huffman.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,40 @@
2424

2525
union huffquad {
2626
struct {
27-
unsigned int final : 1;
28-
unsigned int bits : 3;
29-
unsigned int offset : 12;
27+
unsigned short final : 1;
28+
unsigned short bits : 3;
29+
unsigned short offset : 12;
3030
} ptr;
3131
struct {
32-
unsigned int final : 1;
33-
unsigned int hlen : 3;
34-
unsigned int v : 1;
35-
unsigned int w : 1;
36-
unsigned int x : 1;
37-
unsigned int y : 1;
32+
unsigned short final : 1;
33+
unsigned short hlen : 3;
34+
unsigned short v : 1;
35+
unsigned short w : 1;
36+
unsigned short x : 1;
37+
unsigned short y : 1;
3838
} value;
39-
unsigned int final : 1;
39+
unsigned short final : 1;
4040
};
4141

4242
union huffpair {
4343
struct {
44-
unsigned int final : 1;
45-
unsigned int bits : 3;
46-
unsigned int offset : 12;
44+
unsigned short final : 1;
45+
unsigned short bits : 3;
46+
unsigned short offset : 12;
4747
} ptr;
4848
struct {
49-
unsigned int final : 1;
50-
unsigned int hlen : 3;
51-
unsigned int x : 4;
52-
unsigned int y : 4;
49+
unsigned short final : 1;
50+
unsigned short hlen : 3;
51+
unsigned short x : 4;
52+
unsigned short y : 4;
5353
} value;
54-
unsigned int final : 1;
54+
unsigned short final : 1;
5555
};
5656

5757
struct hufftable {
5858
union huffpair const *table;
59-
unsigned int linbits;
60-
unsigned int startbits;
59+
unsigned short linbits;
60+
unsigned short startbits;
6161
};
6262

6363
extern union huffquad const *const mad_huff_quad_table[2];

0 commit comments

Comments
 (0)