summaryrefslogtreecommitdiffstats
path: root/apps/codecs/libtremor/block.c
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2011-06-06 13:27:12 +0000
committerNils Wallménius <nils@rockbox.org>2011-06-06 13:27:12 +0000
commite62b9a9aaee94d18550a1788b910d023bc257a89 (patch)
tree3fb054717bdb0995ec5323cd178e7d65d7597b20 /apps/codecs/libtremor/block.c
parent684b74147f203662fb6767f65b4ca8fc9b8eeeac (diff)
downloadrockbox-e62b9a9aaee94d18550a1788b910d023bc257a89.tar.gz
rockbox-e62b9a9aaee94d18550a1788b910d023bc257a89.tar.bz2
rockbox-e62b9a9aaee94d18550a1788b910d023bc257a89.zip
libtremor: Implement a memory configuration for targets that don't use separate iram for codecs.
Such targets would previously default to using the configuration for targets with small iram which uses an extra memcpy per block. This saves 2MHz decoding a 128kbps vorbis file on the Gigabeat S and saves a bit of codec buffer. Patch from FS#11268, also replaces patch from FS#12147. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29976 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libtremor/block.c')
-rw-r--r--apps/codecs/libtremor/block.c94
1 files changed, 56 insertions, 38 deletions
diff --git a/apps/codecs/libtremor/block.c b/apps/codecs/libtremor/block.c
index b88896dd15..d678719cbe 100644
--- a/apps/codecs/libtremor/block.c
+++ b/apps/codecs/libtremor/block.c
@@ -40,8 +40,8 @@ static int ilog(unsigned int v){
static ogg_int32_t* _pcmp [CHANNELS] IBSS_ATTR;
static ogg_int32_t* _pcmbp[CHANNELS] IBSS_ATTR;
static ogg_int32_t* _pcmret[CHANNELS] IBSS_ATTR;
-/* save original pointer returned by malloc so we can free it easily */
-static ogg_int32_t* _first_pcm = NULL;
+/* save original pointers returned by malloc so we can free it easily */
+static ogg_int32_t* pcm_copy[CHANNELS] = {NULL};
/* pcm accumulator examples (not exhaustive):
@@ -165,18 +165,21 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){
v->vi=vi;
b->modebits=ilog(ci->modes);
-
+
+#ifdef TREMOR_USE_IRAM
/* allocate IRAM buffer for the PCM data generated by synthesis */
iram_malloc_init();
v->first_pcm = iram_malloc(vi->channels*ci->blocksizes[1]*sizeof(ogg_int32_t));
/* when can't allocate IRAM buffer, allocate normal RAM buffer */
- if(v->first_pcm == NULL){
- _first_pcm = _ogg_malloc(vi->channels*ci->blocksizes[1]*sizeof(ogg_int32_t));
- v->first_pcm= _first_pcm;
+ if(v->first_pcm == NULL)
+#endif
+ {
+ pcm_copy[0] = _ogg_malloc(vi->channels*ci->blocksizes[1]*sizeof(ogg_int32_t));
+ v->first_pcm = pcm_copy[0];
}
-
+
v->centerW=0;
-
+
/* Vorbis I uses only window type 0 */
b_size[0]=ci->blocksizes[0]/2;
b_size[1]=ci->blocksizes[1]/2;
@@ -222,6 +225,8 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){
_pcmp[1]=NULL;
_pcmbp[0]=NULL;
_pcmbp[1]=NULL;
+
+#ifdef TREMOR_USE_IRAM
if(NULL != (v->iram_double_pcm = iram_malloc(vi->channels*v->pcm_storage*sizeof(ogg_int32_t))))
{
/* one-time initialisation at codec start or on switch from
@@ -230,12 +235,15 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){
v->pcm[i]=&v->iram_double_pcm[i*v->pcm_storage];
}
else
+#endif
{
/* one-time initialisation at codec start or on switch from
blocksizes that fit in IRAM_PCM_END to those that don't */
+ /* save copy of the pointer so we can free it easily later */
+ pcm_copy[1] = _ogg_calloc(vi->channels*v->pcm_storage,sizeof(*v->pcm[i]));
for(i=0;i<vi->channels;i++)
- v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
- }
+ v->pcm[i] = pcm_copy[1]+i*v->pcm_storage;
+ }
/* all 1 (large block) or 0 (small block) */
/* explicitly set for the sake of clarity */
@@ -285,10 +293,16 @@ int vorbis_synthesis_restart(vorbis_dsp_state *v){
(if we're using double pcm buffer) and will need to reset them */
v->reset_pcmb = true;
/* also reset our copy of the double buffer pointers if we have one */
+#ifdef TREMOR_USE_IRAM
if(v->iram_double_pcm)
+ {
for(i=0;i<vi->channels;i++)
v->pcm[i]=&v->iram_double_pcm[i*v->pcm_storage];
-
+ }
+#else
+ for(i=0;i<vi->channels;i++)
+ v->pcm[i] = pcm_copy[1]+i*v->pcm_storage;
+#endif
return(0);
}
@@ -306,14 +320,15 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){
codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL);
private_state *b=(private_state *)v->backend_state;
- if(_first_pcm != NULL)
- _ogg_free(_first_pcm);
-
- if(NULL == v->iram_double_pcm && vi != NULL)
+ if(vi != NULL)
{
/* pcm buffer came from oggmalloc rather than iram */
- for(i=0;i<vi->channels;i++)
- if(v->pcm[i])_ogg_free(v->pcm[i]);
+ for(i=0;i<2;i++)
+ if(pcm_copy[i])
+ {
+ _ogg_free(pcm_copy[i]);
+ pcm_copy[i] = NULL;
+ }
}
/* free mode lookups; these are actually vorbis_look_mapping structs */
@@ -345,7 +360,9 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
private_state *b=v->backend_state;
int j;
+#ifdef TREMOR_USE_IRAM
bool iram_pcm_doublebuffer = (NULL != v->iram_double_pcm);
+#endif
if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
@@ -369,16 +386,16 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
int n0=ci->blocksizes[0]/2;
int n1=ci->blocksizes[1]/2;
- if(iram_pcm_doublebuffer)
- {
- prevCenter = ln;
- }
- else
+#ifdef TREMOR_USE_IRAM
+ if(!iram_pcm_doublebuffer)
{
prevCenter = v->centerW;
v->centerW = n1 - v->centerW;
}
-
+ else
+#endif
+ prevCenter = ln;
+
/* overlap/add PCM */
/* nb nothing to overlap with on first block so don't bother */
if(LIKELY(v->pcm_returned!=-1))
@@ -410,20 +427,9 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
}
}
}
-
+#ifdef TREMOR_USE_IRAM
/* the copy section */
- if(iram_pcm_doublebuffer)
- {
- /* just flip the pointers over as we have a double buffer in iram */
- ogg_int32_t *p;
- p=v->pcm[0];
- v->pcm[0]=vb->pcm[0];
- vb->pcm[0] = p;
- p=v->pcm[1];
- v->pcm[1]=vb->pcm[1];
- vb->pcm[1] = p;
- }
- else
+ if(!iram_pcm_doublebuffer)
{
for(j=0;j<vi->channels;j++)
{
@@ -434,7 +440,19 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
vect_copy(v->pcm[j]+v->centerW, vb->pcm[j]+n, n);
}
}
-
+ else
+#endif
+ {
+ /* just flip the pointers over as we have a double buffer in iram */
+ ogg_int32_t *p;
+ p=v->pcm[0];
+ v->pcm[0]=vb->pcm[0];
+ vb->pcm[0] = p;
+ p=v->pcm[1];
+ v->pcm[1]=vb->pcm[1];
+ vb->pcm[1] = p;
+ }
+
/* deal with initial packet state; we do this using the explicit
pcm_returned==-1 flag otherwise we're sensitive to first block
being short or long */
@@ -448,7 +466,7 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
}
}
-
+
/* track the frame number... This is for convenience, but also
making sure our last packet doesn't end with added padding. If
the last packet is partial, the number of samples we'll have to