/src/vorbis/lib/synthesis.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /******************************************************************** | 
| 2 |  |  *                                                                  * | 
| 3 |  |  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   * | 
| 4 |  |  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     * | 
| 5 |  |  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * | 
| 6 |  |  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       * | 
| 7 |  |  *                                                                  * | 
| 8 |  |  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2015             * | 
| 9 |  |  * by the Xiph.Org Foundation https://xiph.org/                     * | 
| 10 |  |  *                                                                  * | 
| 11 |  |  ******************************************************************** | 
| 12 |  |  | 
| 13 |  |  function: single-block PCM synthesis | 
| 14 |  |  | 
| 15 |  |  ********************************************************************/ | 
| 16 |  |  | 
| 17 |  | #include <stdio.h> | 
| 18 |  | #include <ogg/ogg.h> | 
| 19 |  | #include "vorbis/codec.h" | 
| 20 |  | #include "codec_internal.h" | 
| 21 |  | #include "registry.h" | 
| 22 |  | #include "misc.h" | 
| 23 |  | #include "os.h" | 
| 24 |  |  | 
| 25 | 1.64M | int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){ | 
| 26 | 1.64M |   vorbis_dsp_state     *vd= vb ? vb->vd : 0; | 
| 27 | 1.64M |   private_state        *b= vd ? vd->backend_state : 0; | 
| 28 | 1.64M |   vorbis_info          *vi= vd ? vd->vi : 0; | 
| 29 | 1.64M |   codec_setup_info     *ci= vi ? vi->codec_setup : 0; | 
| 30 | 1.64M |   oggpack_buffer       *opb=vb ? &vb->opb : 0; | 
| 31 | 1.64M |   int                   type,mode,i; | 
| 32 |  |  | 
| 33 | 1.64M |   if (!vd || !b || !vi || !ci || !opb) { | 
| 34 | 0 |     return OV_EBADPACKET; | 
| 35 | 0 |   } | 
| 36 |  |  | 
| 37 |  |   /* first things first.  Make sure decode is ready */ | 
| 38 | 1.64M |   _vorbis_block_ripcord(vb); | 
| 39 | 1.64M |   oggpack_readinit(opb,op->packet,op->bytes); | 
| 40 |  |  | 
| 41 |  |   /* Check the packet type */ | 
| 42 | 1.64M |   if(oggpack_read(opb,1)!=0){ | 
| 43 |  |     /* Oops.  This is not an audio data packet */ | 
| 44 | 1.56M |     return(OV_ENOTAUDIO); | 
| 45 | 1.56M |   } | 
| 46 |  |  | 
| 47 |  |   /* read our mode and pre/post windowsize */ | 
| 48 | 73.8k |   mode=oggpack_read(opb,b->modebits); | 
| 49 | 73.8k |   if(mode==-1){ | 
| 50 | 0 |     return(OV_EBADPACKET); | 
| 51 | 0 |   } | 
| 52 |  |  | 
| 53 | 73.8k |   vb->mode=mode; | 
| 54 | 73.8k |   if(!ci->mode_param[mode]){ | 
| 55 | 201 |     return(OV_EBADPACKET); | 
| 56 | 201 |   } | 
| 57 |  |  | 
| 58 | 73.6k |   vb->W=ci->mode_param[mode]->blockflag; | 
| 59 | 73.6k |   if(vb->W){ | 
| 60 |  |  | 
| 61 |  |     /* this doesn;t get mapped through mode selection as it's used | 
| 62 |  |        only for window selection */ | 
| 63 | 18.0k |     vb->lW=oggpack_read(opb,1); | 
| 64 | 18.0k |     vb->nW=oggpack_read(opb,1); | 
| 65 | 18.0k |     if(vb->nW==-1){ | 
| 66 | 194 |       return(OV_EBADPACKET); | 
| 67 | 194 |     } | 
| 68 | 55.5k |   }else{ | 
| 69 | 55.5k |     vb->lW=0; | 
| 70 | 55.5k |     vb->nW=0; | 
| 71 | 55.5k |   } | 
| 72 |  |  | 
| 73 |  |   /* more setup */ | 
| 74 | 73.4k |   vb->granulepos=op->granulepos; | 
| 75 | 73.4k |   vb->sequence=op->packetno; | 
| 76 | 73.4k |   vb->eofflag=op->e_o_s; | 
| 77 |  |  | 
| 78 |  |   /* alloc pcm passback storage */ | 
| 79 | 73.4k |   vb->pcmend=ci->blocksizes[vb->W]; | 
| 80 | 73.4k |   vb->pcm=_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); | 
| 81 | 3.33M |   for(i=0;i<vi->channels;i++) | 
| 82 | 3.25M |     vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); | 
| 83 |  |  | 
| 84 |  |   /* unpack_header enforces range checking */ | 
| 85 | 73.4k |   type=ci->map_type[ci->mode_param[mode]->mapping]; | 
| 86 |  |  | 
| 87 | 73.4k |   return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]-> | 
| 88 | 73.4k |                                                    mapping])); | 
| 89 | 73.6k | } | 
| 90 |  |  | 
| 91 |  | /* used to track pcm position without actually performing decode. | 
| 92 |  |    Useful for sequential 'fast forward' */ | 
| 93 | 0 | int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){ | 
| 94 | 0 |   vorbis_dsp_state     *vd=vb->vd; | 
| 95 | 0 |   private_state        *b=vd->backend_state; | 
| 96 | 0 |   vorbis_info          *vi=vd->vi; | 
| 97 | 0 |   codec_setup_info     *ci=vi->codec_setup; | 
| 98 | 0 |   oggpack_buffer       *opb=&vb->opb; | 
| 99 | 0 |   int                   mode; | 
| 100 |  |  | 
| 101 |  |   /* first things first.  Make sure decode is ready */ | 
| 102 | 0 |   _vorbis_block_ripcord(vb); | 
| 103 | 0 |   oggpack_readinit(opb,op->packet,op->bytes); | 
| 104 |  |  | 
| 105 |  |   /* Check the packet type */ | 
| 106 | 0 |   if(oggpack_read(opb,1)!=0){ | 
| 107 |  |     /* Oops.  This is not an audio data packet */ | 
| 108 | 0 |     return(OV_ENOTAUDIO); | 
| 109 | 0 |   } | 
| 110 |  |  | 
| 111 |  |   /* read our mode and pre/post windowsize */ | 
| 112 | 0 |   mode=oggpack_read(opb,b->modebits); | 
| 113 | 0 |   if(mode==-1)return(OV_EBADPACKET); | 
| 114 |  |  | 
| 115 | 0 |   vb->mode=mode; | 
| 116 | 0 |   if(!ci->mode_param[mode]){ | 
| 117 | 0 |     return(OV_EBADPACKET); | 
| 118 | 0 |   } | 
| 119 |  |  | 
| 120 | 0 |   vb->W=ci->mode_param[mode]->blockflag; | 
| 121 | 0 |   if(vb->W){ | 
| 122 | 0 |     vb->lW=oggpack_read(opb,1); | 
| 123 | 0 |     vb->nW=oggpack_read(opb,1); | 
| 124 | 0 |     if(vb->nW==-1)   return(OV_EBADPACKET); | 
| 125 | 0 |   }else{ | 
| 126 | 0 |     vb->lW=0; | 
| 127 | 0 |     vb->nW=0; | 
| 128 | 0 |   } | 
| 129 |  |  | 
| 130 |  |   /* more setup */ | 
| 131 | 0 |   vb->granulepos=op->granulepos; | 
| 132 | 0 |   vb->sequence=op->packetno; | 
| 133 | 0 |   vb->eofflag=op->e_o_s; | 
| 134 |  |  | 
| 135 |  |   /* no pcm */ | 
| 136 | 0 |   vb->pcmend=0; | 
| 137 | 0 |   vb->pcm=NULL; | 
| 138 |  | 
 | 
| 139 | 0 |   return(0); | 
| 140 | 0 | } | 
| 141 |  |  | 
| 142 | 0 | long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){ | 
| 143 | 0 |   codec_setup_info     *ci=vi->codec_setup; | 
| 144 | 0 |   oggpack_buffer       opb; | 
| 145 | 0 |   int                  mode; | 
| 146 |  | 
 | 
| 147 | 0 |   if(ci==NULL || ci->modes<=0){ | 
| 148 |  |     /* codec setup not properly intialized */ | 
| 149 | 0 |     return(OV_EFAULT); | 
| 150 | 0 |   } | 
| 151 |  |  | 
| 152 | 0 |   oggpack_readinit(&opb,op->packet,op->bytes); | 
| 153 |  |  | 
| 154 |  |   /* Check the packet type */ | 
| 155 | 0 |   if(oggpack_read(&opb,1)!=0){ | 
| 156 |  |     /* Oops.  This is not an audio data packet */ | 
| 157 | 0 |     return(OV_ENOTAUDIO); | 
| 158 | 0 |   } | 
| 159 |  |  | 
| 160 |  |   /* read our mode and pre/post windowsize */ | 
| 161 | 0 |   mode=oggpack_read(&opb,ov_ilog(ci->modes-1)); | 
| 162 | 0 |   if(mode==-1 || !ci->mode_param[mode])return(OV_EBADPACKET); | 
| 163 | 0 |   return(ci->blocksizes[ci->mode_param[mode]->blockflag]); | 
| 164 | 0 | } | 
| 165 |  |  | 
| 166 | 0 | int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){ | 
| 167 |  |   /* set / clear half-sample-rate mode */ | 
| 168 | 0 |   codec_setup_info     *ci=vi->codec_setup; | 
| 169 |  |  | 
| 170 |  |   /* right now, our MDCT can't handle < 64 sample windows. */ | 
| 171 | 0 |   if(ci->blocksizes[0]<=64 && flag)return -1; | 
| 172 | 0 |   ci->halfrate_flag=(flag?1:0); | 
| 173 | 0 |   return 0; | 
| 174 | 0 | } | 
| 175 |  |  | 
| 176 | 595k | int vorbis_synthesis_halfrate_p(vorbis_info *vi){ | 
| 177 | 595k |   codec_setup_info     *ci=vi->codec_setup; | 
| 178 | 595k |   return ci->halfrate_flag; | 
| 179 | 595k | } |