Optimizations to the FLAC-codec buffer requesting to eliminate the

need of extra copying.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7685 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2005-10-30 07:38:52 +00:00
parent a3ed62b36f
commit 169c935c24

View file

@ -210,12 +210,11 @@ bool flac_seek(FLACContext* fc, uint32_t newsample) {
/* this is the codec entry point */ /* this is the codec entry point */
enum codec_status codec_start(struct codec_api* api) enum codec_status codec_start(struct codec_api* api)
{ {
size_t n; int8_t *buf;
static int8_t buf[MAX_FRAMESIZE];
FLACContext fc; FLACContext fc;
uint32_t samplesdone; uint32_t samplesdone;
uint32_t elapsedtime; uint32_t elapsedtime;
int bytesleft; long bytesleft;
int consumed; int consumed;
int res; int res;
int frame; int frame;
@ -246,7 +245,7 @@ enum codec_status codec_start(struct codec_api* api)
return CODEC_ERROR; return CODEC_ERROR;
} }
while (!ci->taginfo_ready) while (!*ci->taginfo_ready)
ci->yield(); ci->yield();
ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency)); ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
@ -254,7 +253,7 @@ enum codec_status codec_start(struct codec_api* api)
/* The main decoding loop */ /* The main decoding loop */
samplesdone=0; samplesdone=0;
frame=0; frame=0;
bytesleft=ci->read_filebuf(buf,sizeof(buf)); buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE);
while (bytesleft) { while (bytesleft) {
ci->yield(); ci->yield();
if (ci->stop_codec || ci->reload_codec) { if (ci->stop_codec || ci->reload_codec) {
@ -265,7 +264,7 @@ enum codec_status codec_start(struct codec_api* api)
if (ci->seek_time) { if (ci->seek_time) {
if (flac_seek(&fc,(ci->seek_time/20) * (ci->id3->frequency/50))) { if (flac_seek(&fc,(ci->seek_time/20) * (ci->id3->frequency/50))) {
/* Refill the input buffer */ /* Refill the input buffer */
bytesleft=ci->read_filebuf(buf,sizeof(buf)); buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE);
} }
ci->seek_time = 0; ci->seek_time = 0;
} }
@ -289,13 +288,9 @@ enum codec_status codec_start(struct codec_api* api)
elapsedtime=(samplesdone*10)/(ci->id3->frequency/100); elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
ci->set_elapsed(elapsedtime); ci->set_elapsed(elapsedtime);
memmove(buf,&buf[consumed],bytesleft-consumed); ci->advance_buffer(consumed);
bytesleft-=consumed;
n=ci->read_filebuf(&buf[bytesleft],sizeof(buf)-bytesleft); buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE);
if (n > 0) {
bytesleft+=n;
}
} }
LOGF("FLAC: Decoded %d samples\n",samplesdone); LOGF("FLAC: Decoded %d samples\n",samplesdone);