summaryrefslogtreecommitdiffstats
path: root/apps/codecs
diff options
context:
space:
mode:
authorThom Johansen <thomj@rockbox.org>2005-10-12 16:25:59 +0000
committerThom Johansen <thomj@rockbox.org>2005-10-12 16:25:59 +0000
commit0059995326348bb9026ff91b6ff2be56f0059661 (patch)
treed96c60bbc4faa57dee5d1713ba6fc91099bc4e95 /apps/codecs
parent7d51325b1dc07ee72c9c21c99b9b9b685ac29936 (diff)
downloadrockbox-0059995326348bb9026ff91b6ff2be56f0059661.tar.gz
rockbox-0059995326348bb9026ff91b6ff2be56f0059661.zip
Cosmetic changes and cleanup. Removed all unused mad_timer code and a couple of unnecessary headers.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7623 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/mpa.c150
1 files changed, 61 insertions, 89 deletions
diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c
index 9970d57240..53a976f44b 100644
--- a/apps/codecs/mpa.c
+++ b/apps/codecs/mpa.c
@@ -18,19 +18,13 @@
****************************************************************************/
#include "codec.h"
-
-#include <codecs/libmad/mad.h>
-
-#include "playback.h"
-#include "dsp.h"
#include "lib/codeclib.h"
-#include "system.h"
+#include <codecs/libmad/mad.h>
#include <inttypes.h>
-struct mad_stream Stream IDATA_ATTR;
-struct mad_frame Frame IDATA_ATTR;
-struct mad_synth Synth IDATA_ATTR;
-mad_timer_t Timer;
+struct mad_stream stream IDATA_ATTR;
+struct mad_frame frame IDATA_ATTR;
+struct mad_synth synth IDATA_ATTR;
/* The following function is used inside libmad - let's hope it's never
called.
@@ -39,13 +33,13 @@ mad_timer_t Timer;
void abort(void) {
}
-
#define INPUT_CHUNK_SIZE 8192
mad_fixed_t mad_frame_overlap[2][32][18] IDATA_ATTR;
unsigned char mad_main_data[MAD_BUFFER_MDLEN] IDATA_ATTR;
/* TODO: what latency does layer 1 have? */
int mpeg_latency[3] = { 0, 481, 529 };
+
#ifdef USE_IRAM
extern char iramcopy[];
extern char iramstart[];
@@ -67,69 +61,61 @@ void recalc_samplecount(void)
if (ci->id3->frame_count) {
/* TODO: 1152 is the frame size in samples for MPEG1 layer 2 and layer 3,
it's probably not correct at all for MPEG2 and layer 1 */
- samplecount = ((int64_t) ci->id3->frame_count) * 1152;
+ samplecount = ((int64_t)ci->id3->frame_count) * 1152;
} else {
- samplecount = ((int64_t) ci->id3->length) * current_frequency / 1000;
+ samplecount = ((int64_t)ci->id3->length) * current_frequency / 1000;
}
samplecount -= start_skip + stop_skip;
}
/* this is the codec entry point */
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_start(struct codec_api *api)
{
- int Status = 0;
+ int status = 0;
size_t size;
int file_end;
int frame_skip;
- char *InputBuffer;
+ char *inputbuffer;
ci = api;
-
- /* Generic codec inititialisation */
TEST_CODEC_API(api);
#ifdef USE_IRAM
ci->memcpy(iramstart, iramcopy, iramend - iramstart);
#endif
- /* This function sets up the buffers and reads the file into RAM */
-
- if (codec_init(api)) {
+ if (codec_init(api))
return CODEC_ERROR;
- }
/* Create a decoder instance */
- ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
- ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16));
+ ci->configure(CODEC_DSP_ENABLE, (bool *)true);
+ ci->configure(DSP_DITHER, (bool *)false);
ci->configure(DSP_SET_CLIP_MIN, (int *)-MAD_F_ONE);
ci->configure(DSP_SET_CLIP_MAX, (int *)(MAD_F_ONE - 1));
ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(MAD_F_FRACBITS));
- ci->configure(DSP_DITHER, (bool *)false);
- ci->configure(CODEC_DSP_ENABLE, (bool *)true);
+ ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2));
+ ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16));
- 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(&Timer, 0, sizeof(mad_timer_t));
+ ci->memset(&stream, 0, sizeof(struct mad_stream));
+ ci->memset(&frame, 0, sizeof(struct mad_frame));
+ ci->memset(&synth, 0, sizeof(struct mad_synth));
- mad_stream_init(&Stream);
- mad_frame_init(&Frame);
- mad_synth_init(&Synth);
- mad_timer_reset(&Timer);
+ mad_stream_init(&stream);
+ mad_frame_init(&frame);
+ mad_synth_init(&synth);
/* We do this so libmad doesn't try to call codec_calloc() */
memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap));
- Frame.overlap = &mad_frame_overlap;
- Stream.main_data = &mad_main_data;
+ frame.overlap = &mad_frame_overlap;
+ stream.main_data = &mad_main_data;
+
/* This label might need to be moved above all the init code, but I don't
think reiniting the codec is necessary for MPEG. It might even be unwanted
for gapless playback */
- next_track:
-
+next_track:
file_end = 0;
-
while (!*ci->taginfo_ready && !ci->stop_codec)
ci->sleep(1);
@@ -150,7 +136,7 @@ enum codec_status codec_start(struct codec_api* api)
start_skip = mpeg_latency[ci->id3->layer];
}
- samplesdone = ((int64_t) ci->id3->elapsed) * current_frequency / 1000;
+ samplesdone = ((int64_t)ci->id3->elapsed) * current_frequency / 1000;
frame_skip = start_skip;
recalc_samplecount();
@@ -159,9 +145,8 @@ enum codec_status codec_start(struct codec_api* api)
int framelength;
ci->yield();
- if (ci->stop_codec || ci->reload_codec) {
- break ;
- }
+ if (ci->stop_codec || ci->reload_codec)
+ break;
if (ci->seek_time) {
int newpos;
@@ -171,113 +156,100 @@ enum codec_status codec_start(struct codec_api* api)
newpos = ci->mp3_get_filepos(ci->seek_time-1) +
ci->id3->first_frame_offset;
- if (!ci->seek_buffer(newpos)) {
+ if (!ci->seek_buffer(newpos))
goto next_track;
- }
- ci->seek_time = 0;
if (newpos == 0)
frame_skip = start_skip;
- /* Optional but good thing to do. */
ci->seek_complete();
}
/* Lock buffers */
- if (Stream.error == 0) {
- InputBuffer = ci->request_buffer(&size, INPUT_CHUNK_SIZE);
- if (size == 0 || InputBuffer == NULL)
- break ;
- mad_stream_buffer(&Stream, InputBuffer, size);
+ if (stream.error == 0) {
+ inputbuffer = ci->request_buffer(&size, INPUT_CHUNK_SIZE);
+ if (size == 0 || inputbuffer == NULL)
+ break;
+ mad_stream_buffer(&stream, inputbuffer, size);
}
- if(mad_frame_decode(&Frame,&Stream))
- {
- if (Stream.error == MAD_FLAG_INCOMPLETE || Stream.error == MAD_ERROR_BUFLEN) {
+ if (mad_frame_decode(&frame,&stream)) {
+ if (stream.error == MAD_FLAG_INCOMPLETE
+ || stream.error == MAD_ERROR_BUFLEN) {
// ci->splash(HZ*1, true, "Incomplete");
- /* This makes the codec to support partially corrupted files too. */
+ /* This makes the codec support partially corrupted files */
if (file_end == 30)
- break ;
+ break;
/* Fill the buffer */
- Stream.error = 0;
+ stream.error = 0;
file_end++;
- continue ;
- }
- else if(MAD_RECOVERABLE(Stream.error))
- {
- if(Stream.error!=MAD_ERROR_LOSTSYNC)
- {
+ continue;
+ } else if (MAD_RECOVERABLE(stream.error)) {
+ if (stream.error != MAD_ERROR_LOSTSYNC) {
// rb->splash(HZ*1, true, "Recoverable...!");
}
continue;
- }
- else if(Stream.error==MAD_ERROR_BUFLEN) {
+ } else if (stream.error == MAD_ERROR_BUFLEN) {
//rb->splash(HZ*1, true, "Buflen error");
- break ;
+ break;
} else {
//rb->splash(HZ*1, true, "Unrecoverable error");
- Status=1;
+ status = 1;
break;
}
- break ;
+ break;
}
file_end = false;
- /* ?? Do we need the timer module? */
- // mad_timer_add(&Timer,Frame.header.duration);
- mad_synth_frame(&Synth,&Frame);
- framelength = Synth.pcm.length - frame_skip;
+ mad_synth_frame(&synth, &frame);
+ framelength = synth.pcm.length - frame_skip;
- /* Convert MAD's numbers to an array of 16-bit LE signed integers */
/* We skip frame_skip number of samples here, this should only happen for
very first frame in the stream. */
/* TODO: possible for frame_skip to exceed one frames worth of samples? */
- if(Frame.header.samplerate != current_frequency) {
- current_frequency = Frame.header.samplerate;
- ci->configure(DSP_SWITCH_FREQUENCY,
- (int *)current_frequency);
+ if (frame.header.samplerate != current_frequency) {
+ current_frequency = frame.header.samplerate;
+ ci->configure(DSP_SWITCH_FREQUENCY, (int *)current_frequency);
recalc_samplecount();
}
- if (stop_skip > 0)
- {
+ if (stop_skip > 0) {
int64_t max = samplecount - samplesdone;
if (max < 0) max = 0;
- if (max < framelength) framelength = (int) max;
+ if (max < framelength) framelength = (int)max;
if (framelength == 0) break;
}
- if (MAD_NCHANNELS(&Frame.header) == 2) {
+ if (MAD_NCHANNELS(&frame.header) == 2) {
if (current_stereo_mode != STEREO_NONINTERLEAVED) {
ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED);
current_stereo_mode = STEREO_NONINTERLEAVED;
}
- ci->pcmbuf_insert_split(&Synth.pcm.samples[0][frame_skip],
- &Synth.pcm.samples[1][frame_skip],
+ ci->pcmbuf_insert_split(&synth.pcm.samples[0][frame_skip],
+ &synth.pcm.samples[1][frame_skip],
framelength * 4);
} else {
if (current_stereo_mode != STEREO_MONO) {
ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO);
current_stereo_mode = STEREO_MONO;
}
- ci->pcmbuf_insert((char *)&Synth.pcm.samples[0][frame_skip],
+ ci->pcmbuf_insert((char *)&synth.pcm.samples[0][frame_skip],
framelength * 4);
}
frame_skip = 0;
- if (Stream.next_frame)
- ci->advance_buffer_loc((void *)Stream.next_frame);
+ if (stream.next_frame)
+ ci->advance_buffer_loc((void *)stream.next_frame);
else
ci->advance_buffer(size);
samplesdone += framelength;
ci->set_elapsed(samplesdone / (current_frequency / 1000));
}
-
- Stream.error = 0;
+ stream.error = 0;
if (ci->request_next_track())
goto next_track;