dbf-halloween2015

annotate libs/vorbis/synthesis.c @ 4:4316c0c879e9

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