vrshoot

annotate libs/vorbis/synthesis.c @ 2:334d17aed7de

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