Index: apps/codecs/libtremor/config-tremor.h =================================================================== --- apps/codecs/libtremor/config-tremor.h (revision 26096) +++ apps/codecs/libtremor/config-tremor.h (arbetskopia) @@ -35,6 +35,10 @@ #define ICODE_ATTR_TREMOR_NOT_MDCT ICODE_ATTR #endif +#ifdef USE_IRAM +#define TREMOR_USE_IRAM +#endif + /* Define CPU of large IRAM (PP5022/5024, MCF5250) */ #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || defined(CPU_S5L870X) || (CONFIG_CPU == MCF5250) /* PCM_BUFFER : 32768 byte (4096*2*4 or 2048*4*4) * @@ -42,7 +46,7 @@ * TOTAL : 41984 */ #define IRAM_IBSS_SIZE 41984 -/* Define CPU of Normal IRAM (96KB) (and SIM also) */ +/* Define CPU of Normal IRAM (96KB) */ #else /* PCM_BUFFER : 16384 Byte (2048*2*4) * * WINDOW_LOOKUP : 4608 Byte (128*4 + 1024*4) * Index: apps/codecs/libtremor/oggmalloc.c =================================================================== --- apps/codecs/libtremor/oggmalloc.c (revision 26096) +++ apps/codecs/libtremor/oggmalloc.c (arbetskopia) @@ -60,6 +60,7 @@ tlsf_free(ptr); } +#ifdef TREMOR_USE_IRAM /* Allocate IRAM buffer */ static unsigned char iram_buff[IRAM_IBSS_SIZE] IBSS_ATTR __attribute__ ((aligned (16))); static size_t iram_remain; @@ -83,3 +84,5 @@ return x; } +#endif + Index: apps/codecs/libtremor/block.c =================================================================== --- apps/codecs/libtremor/block.c (revision 26096) +++ apps/codecs/libtremor/block.c (arbetskopia) @@ -40,6 +40,7 @@ static ogg_int32_t* _pcmp [CHANNELS] IBSS_ATTR; static ogg_int32_t* _pcmbp[CHANNELS] IBSS_ATTR; static ogg_int32_t* _pcmret[CHANNELS] IBSS_ATTR; +static ogg_int32_t* pcm_copy[CHANNELS] = {NULL}; /* pcm accumulator examples (not exhaustive): @@ -151,7 +152,6 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ int i; long b_size[2]; - LOOKUP_TNC *iramposw; codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; private_state *b=NULL; @@ -162,15 +162,19 @@ 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=(ogg_int32_t *)iram_malloc(vi->channels*ci->blocksizes[1]*sizeof(ogg_int32_t)); + 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){ - v->first_pcm=(ogg_int32_t *)_ogg_malloc(vi->channels*ci->blocksizes[1]*sizeof(ogg_int32_t)); +#endif + { + v->first_pcm = _ogg_malloc(vi->channels*ci->blocksizes[1]*sizeof(ogg_int32_t)); + pcm_copy[0] = v->first_pcm; } - + v->centerW=0; /* Vorbis I uses only window type 0 */ @@ -178,10 +182,12 @@ b_size[1]=ci->blocksizes[1]/2; b->window[0]=_vorbis_window(0,b_size[0]); b->window[1]=_vorbis_window(0,b_size[1]); - + +#ifdef TREMOR_USE_IRAM /* allocate IRAM buffer for window tables too, if sufficient iram available */ /* give preference to the larger window over the smaller window (on the assumption that both windows are equally likely used) */ + LOOKUP_TNC *iramposw; for(i=1; i>=0; i--){ iramposw=(LOOKUP_TNC *)iram_malloc(b_size[i]*sizeof(LOOKUP_TNC)); if(iramposw!=NULL) { @@ -189,6 +195,7 @@ b->window[i]=iramposw; } } +#endif /* finish the codebooks */ if(!ci->fullbooks){ @@ -212,6 +219,8 @@ _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 @@ -220,12 +229,15 @@ 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;ichannels;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 */ @@ -290,8 +302,8 @@ if(NULL == v->iram_double_pcm && vi != NULL) { /* pcm buffer came from oggmalloc rather than iram */ - for(i=0;ichannels;i++) - if(v->pcm[i])_ogg_free(v->pcm[i]); + if(pcm_copy[0])_ogg_free(pcm_copy[0]); + if(pcm_copy[1])_ogg_free(pcm_copy[1]); } /* free mode lookups; these are actually vorbis_look_mapping structs */ @@ -323,7 +335,9 @@ 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); @@ -347,16 +361,16 @@ int n0=ci->blocksizes[0]/2; int n1=ci->blocksizes[1]/2; - if(iram_pcm_doublebuffer) +#ifdef TREMOR_USE_IRAM + if(iram_pcm_doublebuffer == NULL) { - prevCenter = ln; - } - else - { 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)) @@ -388,9 +402,21 @@ } } } - +#ifdef TREMOR_USE_IRAM /* the copy section */ - if(iram_pcm_doublebuffer) + if(iram_pcm_doublebuffer == NULL) + { + for(j=0;jchannels;j++) + { + /* at best only vb->pcm is in iram, and that's where we do the + synthesis, so we copy out the right-hand subframe of last + synthesis into (noniram) local buffer so we can still do + synth in iram */ + 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; @@ -401,18 +427,7 @@ v->pcm[1]=vb->pcm[1]; vb->pcm[1] = p; } - else - { - for(j=0;jchannels;j++) - { - /* at best only vb->pcm is in iram, and that's where we do the - synthesis, so we copy out the right-hand subframe of last - synthesis into (noniram) local buffer so we can still do - synth in iram */ - vect_copy(v->pcm[j]+v->centerW, vb->pcm[j]+n, n); - } - } - + /* 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 */ @@ -426,7 +441,7 @@ } } - + /* 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