Index: apps/codecs/libtremor/oggmalloc.c =================================================================== --- apps/codecs/libtremor/oggmalloc.c (revision 26096) +++ apps/codecs/libtremor/oggmalloc.c (arbetskopia) @@ -60,26 +60,30 @@ tlsf_free(ptr); } +#ifdef USE_IRAM /* Allocate IRAM buffer */ static unsigned char iram_buff[IRAM_IBSS_SIZE] IBSS_ATTR __attribute__ ((aligned (16))); static size_t iram_remain; -void iram_malloc_init(void){ - iram_remain=IRAM_IBSS_SIZE; +void iram_malloc_init(void) +{ + iram_remain = IRAM_IBSS_SIZE; } -void *iram_malloc(size_t size){ - void* x; - +void *iram_malloc(size_t size) +{ + void *x; + /* always ensure 16-byte aligned */ - if(size&0x0f) - size=(size-(size&0x0f))+16; - - if(size>iram_remain) + size = (size + 0xf) & ~0xf; + + if (size > iram_remain) return NULL; - + x = &iram_buff[IRAM_IBSS_SIZE-iram_remain]; - iram_remain-=size; + iram_remain -= size; return x; } +#endif + Index: apps/codecs/libtremor/ivorbiscodec.h =================================================================== --- apps/codecs/libtremor/ivorbiscodec.h (revision 26096) +++ apps/codecs/libtremor/ivorbiscodec.h (arbetskopia) @@ -79,7 +79,9 @@ void *backend_state; ogg_int32_t *first_pcm; /* PCM buffer (for normal RAM or IRAM)*/ +#ifdef USE_IRAM ogg_int32_t *iram_double_pcm; /* PCM 2nd buffer for IRAM */ +#endif bool reset_pcmb; } vorbis_dsp_state; Index: apps/codecs/libtremor/block.c =================================================================== --- apps/codecs/libtremor/block.c (revision 26096) +++ apps/codecs/libtremor/block.c (arbetskopia) @@ -151,7 +151,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,14 +161,15 @@ v->vi=vi; b->modebits=ilog(ci->modes); - + +#ifdef 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)); /* when can't allocate IRAM buffer, allocate normal RAM buffer */ - if(v->first_pcm == NULL){ + if(v->first_pcm == NULL) +#endif v->first_pcm=(ogg_int32_t *)_ogg_malloc(vi->channels*ci->blocksizes[1]*sizeof(ogg_int32_t)); - } v->centerW=0; @@ -178,10 +178,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 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 +191,7 @@ b->window[i]=iramposw; } } +#endif /* finish the codebooks */ if(!ci->fullbooks){ @@ -212,6 +215,7 @@ _pcmp[1]=NULL; _pcmbp[0]=NULL; _pcmbp[1]=NULL; +#ifdef 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,6 +224,7 @@ 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 */ @@ -247,7 +252,6 @@ int vorbis_synthesis_restart(vorbis_dsp_state *v){ vorbis_info *vi=v->vi; codec_setup_info *ci; - int i; if(!v->backend_state)return -1; if(!vi)return -1; @@ -265,11 +269,13 @@ /* indicate to synthesis code that buffer pointers no longer valid (if we're using double pcm buffer) and will need to reset them */ v->reset_pcmb = true; +#ifdef USE_IRAM /* also reset our copy of the double buffer pointers if we have one */ + int i; if(v->iram_double_pcm) for(i=0;ichannels;i++) v->pcm[i]=&v->iram_double_pcm[i*v->pcm_storage]; - +#endif return(0); } @@ -287,7 +293,11 @@ codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); private_state *b=(private_state *)v->backend_state; - if(NULL == v->iram_double_pcm && vi != NULL) + if( +#ifdef USE_IRAM + NULL == v->iram_double_pcm && +#endif + vi != NULL) { /* pcm buffer came from oggmalloc rather than iram */ for(i=0;ichannels;i++) @@ -323,7 +333,9 @@ codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; private_state *b=v->backend_state; int j; +#ifdef 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 +359,16 @@ int n0=ci->blocksizes[0]/2; int n1=ci->blocksizes[1]/2; - if(iram_pcm_doublebuffer) +#ifdef USE_IRAM + if(!iram_pcm_doublebuffer) { - 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)) @@ -389,8 +401,21 @@ } } +#ifdef USE_IRAM /* the copy section */ - if(iram_pcm_doublebuffer) + if(!iram_pcm_doublebuffer) + { + 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 +426,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 */