zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
synthesis.c
Go to the documentation of this file.
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 
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 */
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' */
95  vorbis_dsp_state *vd=vb->vd;
97  vorbis_info *vi=vd->vi;
99  oggpack_buffer *opb=&vb->opb;
100  int mode;
101 
102  /* first things first. Make sure decode is ready */
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 
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 
172  /* set / clear half-sample-rate mode */
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 
183  return ci->halfrate_flag;
184 }
void _vorbis_block_ripcord(vorbis_block *vb)
Definition: block.c:137
oggpack_buffer opb
Definition: codec.h:91
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
#define NULL
Definition: ftobjs.h:61
int mode
Definition: codec.h:97
Definition: ogg.h:90
int vorbis_synthesis_halfrate_p(vorbis_info *v)
Definition: synthesis.c:181
vorbis_dsp_state * vd
Definition: codec.h:102
long W
Definition: codec.h:94
long lW
Definition: codec.h:93
vorbis_info_mode * mode_param[64]
vorbis_info * vi
Definition: codec.h:61
void * codec_setup
Definition: codec.h:53
int channels
Definition: codec.h:30
float ** pcm
Definition: codec.h:90
const GLdouble * v
Definition: glew.h:1377
long bytes
Definition: ogg.h:92
int pcmend
Definition: codec.h:96
unsigned char * packet
Definition: ogg.h:91
void oggpack_readinit(oggpack_buffer *b, unsigned char *buf, int bytes)
Definition: bitwise.c:255
long nW
Definition: codec.h:95
XVisualInfo * vi
int eofflag
Definition: codec.h:99
#define OV_ENOTAUDIO
Definition: codec.h:233
ogg_int64_t granulepos
Definition: codec.h:100
int vorbis_synthesis(vorbis_block *vb, ogg_packet *op)
Definition: synthesis.c:26
int vorbis_synthesis_trackonly(vorbis_block *vb, ogg_packet *op)
Definition: synthesis.c:94
ogg_int64_t granulepos
Definition: ogg.h:96
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
GLenum GLenum GLenum GLenum mapping
Definition: glew.h:12631
int vorbis_synthesis_halfrate(vorbis_info *v, int flag)
Definition: synthesis.c:171
long vorbis_packet_blocksize(vorbis_info *vi, ogg_packet *op)
Definition: synthesis.c:143
int i
Definition: pngrutil.c:1377
const vorbis_func_mapping *const _mapping_P[]
Definition: registry.c:43
long oggpack_read(oggpack_buffer *b, int bits)
Definition: bitwise.c:371
ogg_int64_t sequence
Definition: codec.h:101
long e_o_s
Definition: ogg.h:94
GLenum mode
Definition: glew.h:2394
void * backend_state
Definition: codec.h:85
void * _vorbis_block_alloc(vorbis_block *vb, long bytes)
Definition: block.c:113
#define OV_EBADPACKET
Definition: codec.h:234
ogg_int64_t packetno
Definition: ogg.h:98
vorbis_info_mapping * map_param[64]