Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * |
michael@0 | 4 | * * |
michael@0 | 5 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 6 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 7 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 8 | * * |
michael@0 | 9 | * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * |
michael@0 | 10 | * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * |
michael@0 | 11 | * * |
michael@0 | 12 | ******************************************************************** |
michael@0 | 13 | |
michael@0 | 14 | function: single-block PCM synthesis |
michael@0 | 15 | last mod: $Id: synthesis.c,v 1.4 2003/03/29 03:07:21 xiphmont Exp $ |
michael@0 | 16 | |
michael@0 | 17 | ********************************************************************/ |
michael@0 | 18 | |
michael@0 | 19 | #include <stdio.h> |
michael@0 | 20 | #include <ogg/ogg.h> |
michael@0 | 21 | #include "ivorbiscodec.h" |
michael@0 | 22 | #include "codec_internal.h" |
michael@0 | 23 | #include "registry.h" |
michael@0 | 24 | #include "misc.h" |
michael@0 | 25 | #include "block.h" |
michael@0 | 26 | |
michael@0 | 27 | static int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep){ |
michael@0 | 28 | vorbis_dsp_state *vd= vb ? vb->vd : 0; |
michael@0 | 29 | private_state *b= vd ? (private_state *)vd->backend_state: 0; |
michael@0 | 30 | vorbis_info *vi= vd ? vd->vi : 0; |
michael@0 | 31 | codec_setup_info *ci= vi ? (codec_setup_info *)vi->codec_setup : 0; |
michael@0 | 32 | oggpack_buffer *opb=vb ? &vb->opb : 0; |
michael@0 | 33 | int type,mode,i; |
michael@0 | 34 | |
michael@0 | 35 | if (!vd || !b || !vi || !ci || !opb) { |
michael@0 | 36 | return OV_EBADPACKET; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | /* first things first. Make sure decode is ready */ |
michael@0 | 40 | _vorbis_block_ripcord(vb); |
michael@0 | 41 | oggpack_readinit(opb,op->packet,op->bytes); |
michael@0 | 42 | |
michael@0 | 43 | /* Check the packet type */ |
michael@0 | 44 | if(oggpack_read(opb,1)!=0){ |
michael@0 | 45 | /* Oops. This is not an audio data packet */ |
michael@0 | 46 | return(OV_ENOTAUDIO); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | /* read our mode and pre/post windowsize */ |
michael@0 | 50 | mode=oggpack_read(opb,b->modebits); |
michael@0 | 51 | if(mode==-1)return(OV_EBADPACKET); |
michael@0 | 52 | |
michael@0 | 53 | vb->mode=mode; |
michael@0 | 54 | if(!ci->mode_param[mode]){ |
michael@0 | 55 | return(OV_EBADPACKET); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | vb->W=ci->mode_param[mode]->blockflag; |
michael@0 | 59 | if(vb->W){ |
michael@0 | 60 | vb->lW=oggpack_read(opb,1); |
michael@0 | 61 | vb->nW=oggpack_read(opb,1); |
michael@0 | 62 | if(vb->nW==-1) return(OV_EBADPACKET); |
michael@0 | 63 | }else{ |
michael@0 | 64 | vb->lW=0; |
michael@0 | 65 | vb->nW=0; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | /* more setup */ |
michael@0 | 69 | vb->granulepos=op->granulepos; |
michael@0 | 70 | vb->sequence=op->packetno-3; /* first block is third packet */ |
michael@0 | 71 | vb->eofflag=op->e_o_s; |
michael@0 | 72 | |
michael@0 | 73 | if(decodep){ |
michael@0 | 74 | /* alloc pcm passback storage */ |
michael@0 | 75 | vb->pcmend=ci->blocksizes[vb->W]; |
michael@0 | 76 | vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); |
michael@0 | 77 | for(i=0;i<vi->channels;i++) |
michael@0 | 78 | vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); |
michael@0 | 79 | |
michael@0 | 80 | /* unpack_header enforces range checking */ |
michael@0 | 81 | type=ci->map_type[ci->mode_param[mode]->mapping]; |
michael@0 | 82 | |
michael@0 | 83 | return(_mapping_P[type]->inverse(vb,b->mode[mode])); |
michael@0 | 84 | }else{ |
michael@0 | 85 | /* no pcm */ |
michael@0 | 86 | vb->pcmend=0; |
michael@0 | 87 | vb->pcm=NULL; |
michael@0 | 88 | |
michael@0 | 89 | return(0); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){ |
michael@0 | 94 | return _vorbis_synthesis1(vb,op,1); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | /* used to track pcm position without actually performing decode. |
michael@0 | 98 | Useful for sequential 'fast forward' */ |
michael@0 | 99 | int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){ |
michael@0 | 100 | return _vorbis_synthesis1(vb,op,0); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){ |
michael@0 | 104 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; |
michael@0 | 105 | oggpack_buffer opb; |
michael@0 | 106 | int mode; |
michael@0 | 107 | |
michael@0 | 108 | oggpack_readinit(&opb,op->packet,op->bytes); |
michael@0 | 109 | |
michael@0 | 110 | /* Check the packet type */ |
michael@0 | 111 | if(oggpack_read(&opb,1)!=0){ |
michael@0 | 112 | /* Oops. This is not an audio data packet */ |
michael@0 | 113 | return(OV_ENOTAUDIO); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | { |
michael@0 | 117 | int modebits=0; |
michael@0 | 118 | int v=ci->modes; |
michael@0 | 119 | while(v>1){ |
michael@0 | 120 | modebits++; |
michael@0 | 121 | v>>=1; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | /* read our mode and pre/post windowsize */ |
michael@0 | 125 | mode=oggpack_read(&opb,modebits); |
michael@0 | 126 | } |
michael@0 | 127 | if(mode==-1)return(OV_EBADPACKET); |
michael@0 | 128 | return(ci->blocksizes[ci->mode_param[mode]->blockflag]); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 |