From 196e2848b980241c8349a05d119c3d99d9ebc46a Mon Sep 17 00:00:00 2001 From: Buschel Date: Sun, 27 Jun 2010 18:11:07 +0000 Subject: [PATCH] Comment unused code in libmad. Clean up initialization and memset'ing of decoder arrays. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27159 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libmad/decoder.c | 2 ++ apps/codecs/libmad/decoder.h | 6 ++++-- apps/codecs/libmad/frame.c | 26 ++++++++------------------ apps/codecs/libmad/layer3.c | 11 ++++++++++- apps/codecs/libmad/stream.c | 3 +++ apps/codecs/libmad/synth.c | 22 +++++++--------------- apps/codecs/mpa.c | 27 +++++++++++++-------------- 7 files changed, 47 insertions(+), 50 deletions(-) diff --git a/apps/codecs/libmad/decoder.c b/apps/codecs/libmad/decoder.c index 46f4dfe5f..af8e96962 100644 --- a/apps/codecs/libmad/decoder.c +++ b/apps/codecs/libmad/decoder.c @@ -50,6 +50,7 @@ # include "synth.h" # include "decoder.h" +#if 0 /* rockbox: not used */ /* * NAME: decoder->init() * DESCRIPTION: initialize a decoder object with callback routines @@ -585,3 +586,4 @@ int mad_decoder_message(struct mad_decoder *decoder, return -1; # endif } +#endif diff --git a/apps/codecs/libmad/decoder.h b/apps/codecs/libmad/decoder.h index b9ea0b188..7700df6f9 100644 --- a/apps/codecs/libmad/decoder.h +++ b/apps/codecs/libmad/decoder.h @@ -56,7 +56,7 @@ struct mad_decoder { } *sync; void *cb_data; - +/* rockbox: unused enum mad_flow (*input_func)(void *, struct mad_stream *); enum mad_flow (*header_func)(void *, struct mad_header const *); enum mad_flow (*filter_func)(void *, @@ -65,8 +65,9 @@ struct mad_decoder { struct mad_header const *, struct mad_pcm *); enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *); enum mad_flow (*message_func)(void *, void *, unsigned int *); +*/ }; - +/* rockbox: unused void mad_decoder_init(struct mad_decoder *, void *, enum mad_flow (*)(void *, struct mad_stream *), enum mad_flow (*)(void *, struct mad_header const *), @@ -87,5 +88,6 @@ int mad_decoder_finish(struct mad_decoder *); int mad_decoder_run(struct mad_decoder *, enum mad_decoder_mode); int mad_decoder_message(struct mad_decoder *, void *, unsigned int *); +*/ # endif diff --git a/apps/codecs/libmad/frame.c b/apps/codecs/libmad/frame.c index 7fd4235e3..f5e0cf8d3 100644 --- a/apps/codecs/libmad/frame.c +++ b/apps/codecs/libmad/frame.c @@ -92,8 +92,10 @@ void mad_frame_init(struct mad_frame *frame) mad_header_init(&frame->header); frame->options = 0; - +/* rockbox: comment this to proper zero this array in mad_frame_mute(). overlap + * is linked to an array in rockbox' apps/codecs/mpa.c before calling this. frame->overlap = 0; +*/ mad_frame_mute(frame); } @@ -101,6 +103,7 @@ void mad_frame_init(struct mad_frame *frame) * NAME: frame->finish() * DESCRIPTION: deallocate any dynamic memory associated with frame */ +/* rockbox: unused void mad_frame_finish(struct mad_frame *frame) { mad_header_finish(&frame->header); @@ -110,6 +113,7 @@ void mad_frame_finish(struct mad_frame *frame) frame->overlap = 0; } } +*/ /* * NAME: decode_header() @@ -484,21 +488,7 @@ int mad_frame_decode(struct mad_frame *frame, struct mad_stream *stream) */ void mad_frame_mute(struct mad_frame *frame) { - unsigned int s, sb; - - for (s = 0; s < 36; ++s) { - for (sb = 0; sb < 32; ++sb) { - (*frame->sbsample)[0][s][sb] = - (*frame->sbsample)[1][s][sb] = 0; - } - } - - if (frame->overlap) { - for (s = 0; s < 18; ++s) { - for (sb = 0; sb < 32; ++sb) { - (*frame->overlap)[0][sb][s] = - (*frame->overlap)[1][sb][s] = 0; - } - } - } + memset((*frame->sbsample_prev), 0, sizeof(*frame->sbsample_prev)); + memset((*frame->sbsample) , 0, sizeof(*frame->sbsample)); + memset((*frame->overlap) , 0, sizeof(*frame->overlap)); } diff --git a/apps/codecs/libmad/layer3.c b/apps/codecs/libmad/layer3.c index 752dbdbf6..0198e66a3 100644 --- a/apps/codecs/libmad/layer3.c +++ b/apps/codecs/libmad/layer3.c @@ -3230,8 +3230,10 @@ int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame) enum mad_error error; int result = 0; +#if 0 /* rockbox: do not allocate */ /* allocate Layer III dynamic structures */ - + /* rockbox: not used. Both pointers are linked to an array in rockbox' + * apps/codecs/mpa.c before calling this. */ if (stream->main_data == 0) { stream->main_data = malloc(MAD_BUFFER_MDLEN); if (stream->main_data == 0) { @@ -3247,6 +3249,13 @@ int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame) return -1; } } +#else + /* rockbox: This should not happen. Return with error. */ + if ((stream->main_data == 0) || (frame->overlap == 0)) { + stream->error = MAD_ERROR_NOMEM; + return -1; + } +#endif /* rockbox */ nch = MAD_NCHANNELS(header); si_len = (header->flags & MAD_FLAG_LSF_EXT) ? diff --git a/apps/codecs/libmad/stream.c b/apps/codecs/libmad/stream.c index adc982650..b0c5ad36f 100644 --- a/apps/codecs/libmad/stream.c +++ b/apps/codecs/libmad/stream.c @@ -48,7 +48,10 @@ void mad_stream_init(struct mad_stream *stream) mad_bit_init(&stream->anc_ptr, 0); stream->anc_bitlen = 0; +/* rockbox: comment this to avoid allocation in following code. main_data is + * linked to an array in rockbox' apps/codecs/mpa.c before calling this. stream->main_data = 0; +*/ stream->md_len = 0; stream->options = 0; diff --git a/apps/codecs/libmad/synth.c b/apps/codecs/libmad/synth.c index 89f971a1c..0e7c68378 100644 --- a/apps/codecs/libmad/synth.c +++ b/apps/codecs/libmad/synth.c @@ -55,18 +55,6 @@ void mad_synth_init(struct mad_synth *synth) */ void mad_synth_mute(struct mad_synth *synth) { - /* - unsigned int ch, s, v; - - for (ch = 0; ch < 2; ++ch) { - for (s = 0; s < 16; ++s) { - for (v = 0; v < 8; ++v) { - synth->filter[ch][0][0][s][v] = synth->filter[ch][0][1][s][v] = - synth->filter[ch][1][0][s][v] = synth->filter[ch][1][1][s][v] = 0; - } - } - } - */ memset(synth->filter, 0, sizeof(synth->filter)); } @@ -1272,8 +1260,10 @@ void synth_half(struct mad_synth *synth, struct mad_frame const *frame, void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame) { unsigned int nch, ns; +#if 0 /* rockbox: unused */ void (*synth_frame)(struct mad_synth *, struct mad_frame const *, unsigned int, unsigned int); +#endif nch = MAD_NCHANNELS(&frame->header); ns = MAD_NSBSAMPLES(&frame->header); @@ -1282,18 +1272,20 @@ void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame) synth->pcm.channels = nch; synth->pcm.length = 32 * ns; +#if 0 /* rockbox: unused */ synth_frame = synth_full; -#if 0 /* rockbox: unused */ if (frame->options & MAD_OPTION_HALFSAMPLERATE) { synth->pcm.samplerate /= 2; synth->pcm.length /= 2; synth_frame = synth_half; } -#endif - + synth_frame(synth, frame, nch, ns); +#else + synth_full(synth, frame, nch, ns); +#endif synth->phase = (synth->phase + ns) % 16; } diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index 6fea80807..314009143 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -59,30 +59,29 @@ int mpeg_framesize[3] = {384, 1152, 1152}; static void init_mad(void) { ci->memset(&stream, 0, sizeof(struct mad_stream)); - ci->memset(&frame, 0, sizeof(struct mad_frame)); - ci->memset(&synth, 0, sizeof(struct mad_synth)); - - ci->memset(&sbsample, 0, sizeof(sbsample)); + ci->memset(&frame , 0, sizeof(struct mad_frame)); + ci->memset(&synth , 0, sizeof(struct mad_synth)); #ifdef MPA_SYNTH_ON_COP frame.sbsample_prev = &sbsample_prev; - ci->memset(&sbsample_prev, 0, sizeof(sbsample_prev)); + frame.sbsample = &sbsample; #else frame.sbsample_prev = &sbsample; + frame.sbsample = &sbsample; #endif - frame.sbsample=&sbsample; - + /* We do this so libmad doesn't try to call codec_calloc(). This needs to + * be called before mad_stream_init(), mad_frame_inti() and + * mad_synth_init(). */ + frame.overlap = &mad_frame_overlap; + stream.main_data = &mad_main_data; + + /* Call mad initialization. Those will zero the arrays frame.overlap, + * frame.sbsample and frame.sbsample_prev. Therefore there is no need to + * zero them here. */ mad_stream_init(&stream); mad_frame_init(&frame); mad_synth_init(&synth); - - /* We do this so libmad doesn't try to call codec_calloc() */ - ci->memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap)); - frame.overlap = &mad_frame_overlap; - stream.main_data = &mad_main_data; - - } static int get_file_pos(int newtime) -- 2.11.4.GIT