int vorbis_block_clear(vorbis_block *vb){ _vorbis_block_ripcord(vb); if(vb->localstore)_ogg_free(vb->localstore); memset(vb,0,sizeof(*vb)); return(0); }
int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){ vorbis_dsp_state *vd=vb->vd; private_state *b=(private_state *)vd->backend_state; vorbis_info *vi=vd->vi; codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; oggpack_buffer *opb=&vb->opb; int type,mode,i; /* first things first. Make sure decode is ready */ _vorbis_block_ripcord(vb); oggpack_readinit(opb,op->packet); /* Check the packet type */ if(oggpack_read(opb,1)!=0){ /* Oops. This is not an audio data packet */ return(OV_ENOTAUDIO); } /* read our mode and pre/post windowsize */ mode=oggpack_read(opb,b->modebits); if(mode==-1)return(OV_EBADPACKET); vb->mode=mode; vb->W=ci->mode_param[mode]->blockflag; if(vb->W){ vb->lW=oggpack_read(opb,1); vb->nW=oggpack_read(opb,1); if(vb->nW==-1) return(OV_EBADPACKET); }else{ vb->lW=0; vb->nW=0; } /* more setup */ vb->granulepos=op->granulepos; vb->sequence=op->packetno-3; /* first block is third packet */ vb->eofflag=op->e_o_s; if(decodep){ /* alloc pcm passback storage */ vb->pcmend=ci->blocksizes[vb->W]; vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); for(i=0;i<vi->channels;i++) vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); /* unpack_header enforces range checking */ type=ci->map_type[ci->mode_param[mode]->mapping]; return(_mapping_P[type]->inverse(vb,b->mode[mode])); }else{ /* no pcm */ vb->pcmend=0; vb->pcm=NULL; return(0); } }
int vorbis_block_clear(vorbis_block *vb){ if(vb->vd) if(vb->vd->analysisp) oggpack_writeclear(&vb->opb); _vorbis_block_ripcord(vb); if(vb->localstore)_ogg_free(vb->localstore); if(vb->internal)_ogg_free(vb->internal); memset(vb,0,sizeof(vorbis_block)); return(0); }
/* used to track pcm position without actually performing decode. Useful for sequential 'fast forward' */ int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){ vorbis_dsp_state *vd=vb->vd; private_state *b=vd->backend_state; vorbis_info *vi=vd->vi; codec_setup_info *ci=vi->codec_setup; oggpack_buffer *opb=&vb->opb; int mode; /* first things first. Make sure decode is ready */ _vorbis_block_ripcord(vb); oggpack_readinit(opb,op->packet,op->bytes); /* Check the packet type */ if(oggpack_read(opb,1)!=0){ /* Oops. This is not an audio data packet */ return(OV_ENOTAUDIO); } /* read our mode and pre/post windowsize */ mode=oggpack_read(opb,b->modebits); if(mode==-1)return(OV_EBADPACKET); vb->mode=mode; if(!ci->mode_param[mode]){ return(OV_EBADPACKET); } vb->W=ci->mode_param[mode]->blockflag; if(vb->W){ vb->lW=oggpack_read(opb,1); vb->nW=oggpack_read(opb,1); if(vb->nW==-1) return(OV_EBADPACKET); }else{ vb->lW=0; vb->nW=0; } /* more setup */ vb->granulepos=op->granulepos; vb->sequence=op->packetno; vb->eofflag=op->e_o_s; /* no pcm */ vb->pcmend=0; vb->pcm=NULL; return(0); }
int vorbis_block_clear(vorbis_block *vb){ int i; vorbis_block_internal *vbi=vb->internal; _vorbis_block_ripcord(vb); if(vb->localstore)_ogg_free(vb->localstore); if(vbi){ for(i=0;i<PACKETBLOBS;i++){ oggpack_writeclear(vbi->packetblob[i]); if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]); } _ogg_free(vbi); } memset(vb,0,sizeof(*vb)); return(0); }
int vorbis_block_clear(vorbis_block *vb){ if(vb->vd) if(vb->vd->analysisp) oggpack_writeclear(&vb->opb); _vorbis_block_ripcord(vb); if(vb->localstore)_ogg_free(vb->localstore); if(vb->internal){ vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal; if(vbi->packet_markers)_ogg_free(vbi->packet_markers); _ogg_free(vb->internal); } memset(vb,0,sizeof(*vb)); return(0); }
/* do the deltas, envelope shaping, pre-echo and determine the size of the next block on which to continue analysis */ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){ int i; vorbis_info *vi=v->vi; codec_setup_info *ci=vi->codec_setup; private_state *b=v->backend_state; vorbis_look_psy_global *g=b->psy_g_look; long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext; vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal; /* check to see if we're started... */ if(!v->preextrapolate)return(0); /* check to see if we're done... */ if(v->eofflag==-1)return(0); /* By our invariant, we have lW, W and centerW set. Search for the next boundary so we can determine nW (the next window size) which lets us compute the shape of the current block's window */ /* we do an envelope search even on a single blocksize; we may still be throwing more bits at impulses, and envelope search handles marking impulses too. */ { long bp=_ve_envelope_search(v); if(bp==-1){ if(v->eofflag==0)return(0); /* not enough data currently to search for a full long block */ v->nW=0; }else{ if(ci->blocksizes[0]==ci->blocksizes[1]) v->nW=0; else v->nW=bp; } } centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4; { /* center of next block + next block maximum right side. */ long blockbound=centerNext+ci->blocksizes[v->nW]/2; if(v->pcm_current<blockbound)return(0); /* not enough data yet; although this check is less strict that the _ve_envelope_search, the search is not run if we only use one block size */ } /* fill in the block. Note that for a short window, lW and nW are *short* regardless of actual settings in the stream */ _vorbis_block_ripcord(vb); vb->lW=v->lW; vb->W=v->W; vb->nW=v->nW; if(v->W){ if(!v->lW || !v->nW){ vbi->blocktype=BLOCKTYPE_TRANSITION; /*fprintf(stderr,"-");*/ }else{ vbi->blocktype=BLOCKTYPE_LONG; /*fprintf(stderr,"_");*/ } }else{ if(_ve_envelope_mark(v)){ vbi->blocktype=BLOCKTYPE_IMPULSE; /*fprintf(stderr,"|");*/ }else{ vbi->blocktype=BLOCKTYPE_PADDING; /*fprintf(stderr,".");*/ } } vb->vd=v; vb->sequence=v->sequence++; vb->granulepos=v->granulepos; vb->pcmend=ci->blocksizes[v->W]; /* copy the vectors; this uses the local storage in vb */ /* this tracks 'strongest peak' for later psychoacoustics */ /* moved to the global psy state; clean this mess up */ if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax; g->ampmax=_vp_ampmax_decay(g->ampmax,v); vbi->ampmax=g->ampmax; vb->pcm=_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); vbi->pcmdelay=_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels); for(i=0;i<vi->channels;i++){ vbi->pcmdelay[i]= _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i])); memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i])); vb->pcm[i]=vbi->pcmdelay[i]+beginW; /* before we added the delay vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); memcpy(vb->pcm[i],v->pcm[i]+beginW,ci->blocksizes[v->W]*sizeof(*vb->pcm[i])); */ } /* handle eof detection: eof==0 means that we've not yet received EOF eof>0 marks the last 'real' sample in pcm[] eof<0 'no more to do'; doesn't get here */ if(v->eofflag){ if(v->centerW>=v->eofflag){ v->eofflag=-1; vb->eofflag=1; return(1); } } /* advance storage vectors and clean up */ { int new_centerNext=ci->blocksizes[1]/2; int movementW=centerNext-new_centerNext; if(movementW>0){ _ve_envelope_shift(b->ve,movementW); v->pcm_current-=movementW; for(i=0;i<vi->channels;i++) memmove(v->pcm[i],v->pcm[i]+movementW, v->pcm_current*sizeof(*v->pcm[i])); v->lW=v->W; v->W=v->nW; v->centerW=new_centerNext; if(v->eofflag){ v->eofflag-=movementW; if(v->eofflag<=0)v->eofflag=-1; /* do not add padding to end of stream! */ if(v->centerW>=v->eofflag){ v->granulepos+=movementW-(v->centerW-v->eofflag); }else{ v->granulepos+=movementW; } }else{ v->granulepos+=movementW; } } } /* done */ return(1); }
int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){ vorbis_dsp_state *vd= vb ? vb->vd : 0; private_state *b= vd ? vd->backend_state : 0; vorbis_info *vi= vd ? vd->vi : 0; codec_setup_info *ci= vi ? vi->codec_setup : 0; oggpack_buffer *opb=vb ? &vb->opb : 0; int type,mode,i; if (!vd || !b || !vi || !ci || !opb) { return OV_EBADPACKET; } /* first things first. Make sure decode is ready */ _vorbis_block_ripcord(vb); oggpack_readinit(opb,op->packet,op->bytes); /* Check the packet type */ if(oggpack_read(opb,1)!=0){ /* Oops. This is not an audio data packet */ return(OV_ENOTAUDIO); } /* read our mode and pre/post windowsize */ mode=oggpack_read(opb,b->modebits); if(mode==-1){ return(OV_EBADPACKET); } vb->mode=mode; if(!ci->mode_param[mode]){ return(OV_EBADPACKET); } vb->W=ci->mode_param[mode]->blockflag; if(vb->W){ /* this doesn;t get mapped through mode selection as it's used only for window selection */ vb->lW=oggpack_read(opb,1); vb->nW=oggpack_read(opb,1); if(vb->nW==-1){ return(OV_EBADPACKET); } }else{ vb->lW=0; vb->nW=0; } /* more setup */ vb->granulepos=op->granulepos; vb->sequence=op->packetno; vb->eofflag=op->e_o_s; /* alloc pcm passback storage */ vb->pcmend=ci->blocksizes[vb->W]; vb->pcm=_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); for(i=0;i<vi->channels;i++) vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); /* unpack_header enforces range checking */ type=ci->map_type[ci->mode_param[mode]->mapping]; return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]-> mapping])); }
static inline int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep){ vorbis_dsp_state *vd= vb ? vb->vd : 0; private_state *b= vd ? (private_state *)vd->backend_state: 0; vorbis_info *vi= vd ? vd->vi : 0; codec_setup_info *ci= vi ? (codec_setup_info *)vi->codec_setup : 0; oggpack_buffer *opb=vb ? &vb->opb : 0; int type,mode,i; if (!vd || !b || !vi || !ci || !opb) { return OV_EBADPACKET; } /* first things first. Make sure decode is ready */ _vorbis_block_ripcord(vb); oggpack_readinit(opb,op->packet,op->bytes); /* Check the packet type */ if(oggpack_read(opb,1)!=0){ /* Oops. This is not an audio data packet */ return(OV_ENOTAUDIO); } /* read our mode and pre/post windowsize */ mode=oggpack_read(opb,b->modebits); if(mode==-1)return(OV_EBADPACKET); vb->mode=mode; if(!ci->mode_param[mode]){ return(OV_EBADPACKET); } vb->W=ci->mode_param[mode]->blockflag; if(vb->W){ vb->lW=oggpack_read(opb,1); vb->nW=oggpack_read(opb,1); if(vb->nW==-1) return(OV_EBADPACKET); }else{ vb->lW=0; vb->nW=0; } /* more setup */ vb->granulepos=op->granulepos; vb->sequence=op->packetno-3; /* first block is third packet */ vb->eofflag=op->e_o_s; if(decodep && vi->channels<=CHANNELS) { vb->pcm = ipcm_vect; /* set pcm end point */ vb->pcmend=ci->blocksizes[vb->W]; /* use statically allocated buffer */ if(vd->reset_pcmb || vb->pcm[0]==NULL) { /* one-time initialisation at codec start NOT for every block synthesis start allows us to flip between buffers once initialised by simply flipping pointers */ for(i=0; i<vi->channels; i++) vb->pcm[i] = &vd->first_pcm[i*ci->blocksizes[1]]; } vd->reset_pcmb = false; /* unpack_header enforces range checking */ type=ci->map_type[ci->mode_param[mode]->mapping]; return(_mapping_P[type]->inverse(vb,b->mode[mode])); }else{ /* no pcm */ vb->pcmend=0; vb->pcm=NULL; return(0); } }