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