annotate src/libvorbis-1.3.3/lib/synthesis.c @ 83:ae30d91d2ffe

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