vrshoot

diff libs/vorbis/synthesis.c @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vorbis/synthesis.c	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,184 @@
     1.4 +/********************************************************************
     1.5 + *                                                                  *
     1.6 + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
     1.7 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
     1.8 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
     1.9 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
    1.10 + *                                                                  *
    1.11 + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
    1.12 + * by the Xiph.Org Foundation http://www.xiph.org/                  *
    1.13 + *                                                                  *
    1.14 + ********************************************************************
    1.15 +
    1.16 + function: single-block PCM synthesis
    1.17 + last mod: $Id: synthesis.c 17474 2010-09-30 03:41:41Z gmaxwell $
    1.18 +
    1.19 + ********************************************************************/
    1.20 +
    1.21 +#include <stdio.h>
    1.22 +#include <ogg/ogg.h>
    1.23 +#include "vorbis/codec.h"
    1.24 +#include "codec_internal.h"
    1.25 +#include "registry.h"
    1.26 +#include "misc.h"
    1.27 +#include "os.h"
    1.28 +
    1.29 +int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
    1.30 +  vorbis_dsp_state     *vd= vb ? vb->vd : 0;
    1.31 +  private_state        *b= vd ? vd->backend_state : 0;
    1.32 +  vorbis_info          *vi= vd ? vd->vi : 0;
    1.33 +  codec_setup_info     *ci= vi ? vi->codec_setup : 0;
    1.34 +  oggpack_buffer       *opb=vb ? &vb->opb : 0;
    1.35 +  int                   type,mode,i;
    1.36 +
    1.37 +  if (!vd || !b || !vi || !ci || !opb) {
    1.38 +    return OV_EBADPACKET;
    1.39 +  }
    1.40 +
    1.41 +  /* first things first.  Make sure decode is ready */
    1.42 +  _vorbis_block_ripcord(vb);
    1.43 +  oggpack_readinit(opb,op->packet,op->bytes);
    1.44 +
    1.45 +  /* Check the packet type */
    1.46 +  if(oggpack_read(opb,1)!=0){
    1.47 +    /* Oops.  This is not an audio data packet */
    1.48 +    return(OV_ENOTAUDIO);
    1.49 +  }
    1.50 +
    1.51 +  /* read our mode and pre/post windowsize */
    1.52 +  mode=oggpack_read(opb,b->modebits);
    1.53 +  if(mode==-1){
    1.54 +    return(OV_EBADPACKET);
    1.55 +  }
    1.56 +
    1.57 +  vb->mode=mode;
    1.58 +  if(!ci->mode_param[mode]){
    1.59 +    return(OV_EBADPACKET);
    1.60 +  }
    1.61 +
    1.62 +  vb->W=ci->mode_param[mode]->blockflag;
    1.63 +  if(vb->W){
    1.64 +
    1.65 +    /* this doesn;t get mapped through mode selection as it's used
    1.66 +       only for window selection */
    1.67 +    vb->lW=oggpack_read(opb,1);
    1.68 +    vb->nW=oggpack_read(opb,1);
    1.69 +    if(vb->nW==-1){
    1.70 +      return(OV_EBADPACKET);
    1.71 +    }
    1.72 +  }else{
    1.73 +    vb->lW=0;
    1.74 +    vb->nW=0;
    1.75 +  }
    1.76 +
    1.77 +  /* more setup */
    1.78 +  vb->granulepos=op->granulepos;
    1.79 +  vb->sequence=op->packetno;
    1.80 +  vb->eofflag=op->e_o_s;
    1.81 +
    1.82 +  /* alloc pcm passback storage */
    1.83 +  vb->pcmend=ci->blocksizes[vb->W];
    1.84 +  vb->pcm=_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
    1.85 +  for(i=0;i<vi->channels;i++)
    1.86 +    vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
    1.87 +
    1.88 +  /* unpack_header enforces range checking */
    1.89 +  type=ci->map_type[ci->mode_param[mode]->mapping];
    1.90 +
    1.91 +  return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
    1.92 +                                                   mapping]));
    1.93 +}
    1.94 +
    1.95 +/* used to track pcm position without actually performing decode.
    1.96 +   Useful for sequential 'fast forward' */
    1.97 +int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
    1.98 +  vorbis_dsp_state     *vd=vb->vd;
    1.99 +  private_state        *b=vd->backend_state;
   1.100 +  vorbis_info          *vi=vd->vi;
   1.101 +  codec_setup_info     *ci=vi->codec_setup;
   1.102 +  oggpack_buffer       *opb=&vb->opb;
   1.103 +  int                   mode;
   1.104 +
   1.105 +  /* first things first.  Make sure decode is ready */
   1.106 +  _vorbis_block_ripcord(vb);
   1.107 +  oggpack_readinit(opb,op->packet,op->bytes);
   1.108 +
   1.109 +  /* Check the packet type */
   1.110 +  if(oggpack_read(opb,1)!=0){
   1.111 +    /* Oops.  This is not an audio data packet */
   1.112 +    return(OV_ENOTAUDIO);
   1.113 +  }
   1.114 +
   1.115 +  /* read our mode and pre/post windowsize */
   1.116 +  mode=oggpack_read(opb,b->modebits);
   1.117 +  if(mode==-1)return(OV_EBADPACKET);
   1.118 +
   1.119 +  vb->mode=mode;
   1.120 +  if(!ci->mode_param[mode]){
   1.121 +    return(OV_EBADPACKET);
   1.122 +  }
   1.123 +  
   1.124 +  vb->W=ci->mode_param[mode]->blockflag;
   1.125 +  if(vb->W){
   1.126 +    vb->lW=oggpack_read(opb,1);
   1.127 +    vb->nW=oggpack_read(opb,1);
   1.128 +    if(vb->nW==-1)   return(OV_EBADPACKET);
   1.129 +  }else{
   1.130 +    vb->lW=0;
   1.131 +    vb->nW=0;
   1.132 +  }
   1.133 +
   1.134 +  /* more setup */
   1.135 +  vb->granulepos=op->granulepos;
   1.136 +  vb->sequence=op->packetno;
   1.137 +  vb->eofflag=op->e_o_s;
   1.138 +
   1.139 +  /* no pcm */
   1.140 +  vb->pcmend=0;
   1.141 +  vb->pcm=NULL;
   1.142 +
   1.143 +  return(0);
   1.144 +}
   1.145 +
   1.146 +long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
   1.147 +  codec_setup_info     *ci=vi->codec_setup;
   1.148 +  oggpack_buffer       opb;
   1.149 +  int                  mode;
   1.150 +
   1.151 +  oggpack_readinit(&opb,op->packet,op->bytes);
   1.152 +
   1.153 +  /* Check the packet type */
   1.154 +  if(oggpack_read(&opb,1)!=0){
   1.155 +    /* Oops.  This is not an audio data packet */
   1.156 +    return(OV_ENOTAUDIO);
   1.157 +  }
   1.158 +
   1.159 +  {
   1.160 +    int modebits=0;
   1.161 +    int v=ci->modes;
   1.162 +    while(v>1){
   1.163 +      modebits++;
   1.164 +      v>>=1;
   1.165 +    }
   1.166 +
   1.167 +    /* read our mode and pre/post windowsize */
   1.168 +    mode=oggpack_read(&opb,modebits);
   1.169 +  }
   1.170 +  if(mode==-1)return(OV_EBADPACKET);
   1.171 +  return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
   1.172 +}
   1.173 +
   1.174 +int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
   1.175 +  /* set / clear half-sample-rate mode */
   1.176 +  codec_setup_info     *ci=vi->codec_setup;
   1.177 +
   1.178 +  /* right now, our MDCT can't handle < 64 sample windows. */
   1.179 +  if(ci->blocksizes[0]<=64 && flag)return -1;
   1.180 +  ci->halfrate_flag=(flag?1:0);
   1.181 +  return 0;
   1.182 +}
   1.183 +
   1.184 +int vorbis_synthesis_halfrate_p(vorbis_info *vi){
   1.185 +  codec_setup_info     *ci=vi->codec_setup;
   1.186 +  return ci->halfrate_flag;
   1.187 +}