zenilib: zenilib/jni/external/libvorbis/lib/synthesis.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
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 }
vorbis_info_mode::blockflag
int blockflag
Definition: codec_internal.h:48
_vorbis_block_ripcord
void _vorbis_block_ripcord(vorbis_block *vb)
Definition: block.c:137
vorbis_block::opb
oggpack_buffer opb
Definition: codec.h:91
misc.h
type
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
NULL
#define NULL
Definition: ftobjs.h:61
vorbis_block::mode
int mode
Definition: codec.h:97
ogg_packet
Definition: ogg.h:90
private_state::modebits
int modebits
Definition: codec_internal.h:68
vorbis_synthesis_halfrate_p
int vorbis_synthesis_halfrate_p(vorbis_info *v)
Definition: synthesis.c:181
vorbis_block::vd
vorbis_dsp_state * vd
Definition: codec.h:102
codec.h
codec_internal.h
vorbis_block::W
long W
Definition: codec.h:94
vorbis_block::lW
long lW
Definition: codec.h:93
codec_setup_info::mode_param
vorbis_info_mode * mode_param[64]
Definition: codec_internal.h:113
ogg.h
vorbis_dsp_state::vi
vorbis_info * vi
Definition: codec.h:61
vorbis_info::codec_setup
void * codec_setup
Definition: codec.h:53
vorbis_info::channels
int channels
Definition: codec.h:30
vorbis_block::pcm
float ** pcm
Definition: codec.h:90
v
const GLdouble * v
Definition: glew.h:1377
ogg_packet::bytes
long bytes
Definition: ogg.h:92
codec_setup_info::blocksizes
long blocksizes[2]
Definition: codec_internal.h:99
codec_setup_info::modes
int modes
Definition: codec_internal.h:106
codec_setup_info::map_type
int map_type[64]
Definition: codec_internal.h:114
os.h
vorbis_block::pcmend
int pcmend
Definition: codec.h:96
ogg_packet::packet
unsigned char * packet
Definition: ogg.h:91
oggpack_buffer
Definition: ogg.h:32
oggpack_readinit
void oggpack_readinit(oggpack_buffer *b, unsigned char *buf, int bytes)
Definition: bitwise.c:255
vorbis_block
Definition: codec.h:88
vorbis_block::nW
long nW
Definition: codec.h:95
codec_setup_info::halfrate_flag
int halfrate_flag
Definition: codec_internal.h:130
vi
XVisualInfo * vi
Definition: glewinfo_tail.c:221
vorbis_block::eofflag
int eofflag
Definition: codec.h:99
OV_ENOTAUDIO
#define OV_ENOTAUDIO
Definition: codec.h:233
vorbis_block::granulepos
ogg_int64_t granulepos
Definition: codec.h:100
vorbis_synthesis
int vorbis_synthesis(vorbis_block *vb, ogg_packet *op)
Definition: synthesis.c:26
vorbis_synthesis_trackonly
int vorbis_synthesis_trackonly(vorbis_block *vb, ogg_packet *op)
Definition: synthesis.c:94
codec_setup_info
Definition: codec_internal.h:94
ogg_packet::granulepos
ogg_int64_t granulepos
Definition: ogg.h:96
b
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
mapping
GLenum GLenum GLenum GLenum mapping
Definition: glew.h:12631
vorbis_synthesis_halfrate
int vorbis_synthesis_halfrate(vorbis_info *v, int flag)
Definition: synthesis.c:171
vorbis_packet_blocksize
long vorbis_packet_blocksize(vorbis_info *vi, ogg_packet *op)
Definition: synthesis.c:143
i
int i
Definition: pngrutil.c:1377
_mapping_P
const vorbis_func_mapping *const _mapping_P[]
Definition: registry.c:43
oggpack_read
long oggpack_read(oggpack_buffer *b, int bits)
Definition: bitwise.c:371
private_state
Definition: codec_internal.h:61
vorbis_block::sequence
ogg_int64_t sequence
Definition: codec.h:101
vorbis_info_mode::mapping
int mapping
Definition: codec_internal.h:51
ogg_packet::e_o_s
long e_o_s
Definition: ogg.h:94
mode
GLenum mode
Definition: glew.h:2394
vorbis_dsp_state::backend_state
void * backend_state
Definition: codec.h:85
_vorbis_block_alloc
void * _vorbis_block_alloc(vorbis_block *vb, long bytes)
Definition: block.c:113
OV_EBADPACKET
#define OV_EBADPACKET
Definition: codec.h:234
ogg_packet::packetno
ogg_int64_t packetno
Definition: ogg.h:98
registry.h
vorbis_info
Definition: codec.h:28
vorbis_dsp_state
Definition: codec.h:59
codec_setup_info::map_param
vorbis_info_mapping * map_param[64]
Definition: codec_internal.h:115