libvorbis  1.3.7
codec.h
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-2001 *
9  * by the Xiph.Org Foundation https://xiph.org/ *
10 
11  ********************************************************************
12 
13  function: libvorbis codec headers
14 
15  ********************************************************************/
16 
17 #ifndef _vorbis_codec_h_
18 #define _vorbis_codec_h_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif /* __cplusplus */
24 
25 #include <ogg/ogg.h>
26 
27 typedef struct vorbis_info{
28  int version;
29  int channels;
30  long rate;
31 
32  /* The below bitrate declarations are *hints*.
33  Combinations of the three values carry the following implications:
34 
35  all three set to the same value:
36  implies a fixed rate bitstream
37  only nominal set:
38  implies a VBR stream that averages the nominal bitrate. No hard
39  upper/lower limit
40  upper and or lower set:
41  implies a VBR bitstream that obeys the bitrate limits. nominal
42  may also be set to give a nominal rate.
43  none set:
44  the coder does not care to speculate.
45  */
46 
47  long bitrate_upper;
48  long bitrate_nominal;
49  long bitrate_lower;
50  long bitrate_window;
51 
52  void *codec_setup;
54 
55 /* vorbis_dsp_state buffers the current vorbis audio
56  analysis/synthesis state. The DSP state belongs to a specific
57  logical bitstream ****************************************************/
58 typedef struct vorbis_dsp_state{
59  int analysisp;
61 
62  float **pcm;
63  float **pcmret;
67 
69  int eofflag;
70 
71  long lW;
72  long W;
73  long nW;
74  long centerW;
75 
76  ogg_int64_t granulepos;
77  ogg_int64_t sequence;
78 
79  ogg_int64_t glue_bits;
80  ogg_int64_t time_bits;
81  ogg_int64_t floor_bits;
82  ogg_int64_t res_bits;
83 
86 
87 typedef struct vorbis_block{
88  /* necessary stream state for linking to the framing abstraction */
89  float **pcm; /* this is a pointer into local storage */
90  oggpack_buffer opb;
91 
92  long lW;
93  long W;
94  long nW;
95  int pcmend;
96  int mode;
97 
98  int eofflag;
99  ogg_int64_t granulepos;
100  ogg_int64_t sequence;
101  vorbis_dsp_state *vd; /* For read-only access of configuration */
102 
103  /* local storage to avoid remallocing; it's up to the mapping to
104  structure it */
105  void *localstore;
106  long localtop;
108  long totaluse;
109  struct alloc_chain *reap;
110 
111  /* bitmetrics for the frame */
112  long glue_bits;
113  long time_bits;
115  long res_bits;
116 
117  void *internal;
118 
120 
121 /* vorbis_block is a single block of data to be processed as part of
122 the analysis/synthesis stream; it belongs to a specific logical
123 bitstream, but is independent from other vorbis_blocks belonging to
124 that logical bitstream. *************************************************/
125 
126 struct alloc_chain{
127  void *ptr;
128  struct alloc_chain *next;
129 };
130 
131 /* vorbis_info contains all the setup information specific to the
132  specific compression/decompression mode in progress (eg,
133  psychoacoustic settings, channel setup, options, codebook
134  etc). vorbis_info and substructures are in backends.h.
135 *********************************************************************/
136 
137 /* the comments are not part of vorbis_info so that vorbis_info can be
138  static storage */
139 typedef struct vorbis_comment{
140  /* unlimited user comment fields. libvorbis writes 'libvorbis'
141  whatever vendor is set to in encode */
144  int comments;
145  char *vendor;
146 
148 
149 
150 /* libvorbis encodes in two abstraction layers; first we perform DSP
151  and produce a packet (see docs/analysis.txt). The packet is then
152  coded into a framed OggSquish bitstream by the second layer (see
153  docs/framing.txt). Decode is the reverse process; we sync/frame
154  the bitstream and extract individual packets, then decode the
155  packet back into PCM audio.
156 
157  The extra framing/packetizing is used in streaming formats, such as
158  files. Over the net (such as with UDP), the framing and
159  packetization aren't necessary as they're provided by the transport
160  and the streaming layer is not used */
161 
162 /* Vorbis PRIMITIVES: general ***************************************/
163 
164 extern void vorbis_info_init(vorbis_info *vi);
166 extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
168 extern void vorbis_comment_add(vorbis_comment *vc, const char *comment);
170  const char *tag, const char *contents);
171 extern char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count);
172 extern int vorbis_comment_query_count(vorbis_comment *vc, const char *tag);
174 
179  ogg_int64_t granulepos);
180 
181 extern const char *vorbis_version_string(void);
182 
183 /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
184 
186 extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
188  vorbis_comment *vc,
189  ogg_packet *op,
190  ogg_packet *op_comm,
191  ogg_packet *op_code);
192 extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
193 extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
195 extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
196 
199  ogg_packet *op);
200 
201 /* Vorbis PRIMITIVES: synthesis layer *******************************/
202 extern int vorbis_synthesis_idheader(ogg_packet *op);
204  ogg_packet *op);
205 
208 extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
209 extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
211 extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
212 extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
213 extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
214 extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
215 
216 extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
218 
219 /* Vorbis ERRORS and return codes ***********************************/
220 
221 #define OV_FALSE -1
222 #define OV_EOF -2
223 #define OV_HOLE -3
224 
225 #define OV_EREAD -128
226 #define OV_EFAULT -129
227 #define OV_EIMPL -130
228 #define OV_EINVAL -131
229 #define OV_ENOTVORBIS -132
230 #define OV_EBADHEADER -133
231 #define OV_EVERSION -134
232 #define OV_ENOTAUDIO -135
233 #define OV_EBADPACKET -136
234 #define OV_EBADLINK -137
235 #define OV_ENOSEEK -138
236 
237 #ifdef __cplusplus
238 }
239 #endif /* __cplusplus */
240 
241 #endif
242 
vorbis_info::version
int version
Definition: codec.h:42
vorbis_analysis
int vorbis_analysis(vorbis_block *vb, ogg_packet *op)
vorbis_dsp_state::pcm_returned
int pcm_returned
Definition: codec.h:66
vorbis_synthesis_trackonly
int vorbis_synthesis_trackonly(vorbis_block *vb, ogg_packet *op)
vorbis_block::W
long W
Definition: codec.h:93
vorbis_block::pcm
float ** pcm
Definition: codec.h:89
vorbis_comment_query
char * vorbis_comment_query(vorbis_comment *vc, const char *tag, int count)
vorbis_synthesis_init
int vorbis_synthesis_init(vorbis_dsp_state *v, vorbis_info *vi)
vorbis_commentheader_out
int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op)
vorbis_dsp_state::pcm_storage
int pcm_storage
Definition: codec.h:64
vorbis_comment_clear
void vorbis_comment_clear(vorbis_comment *vc)
alloc_chain::ptr
void * ptr
Definition: codec.h:127
vorbis_synthesis_restart
int vorbis_synthesis_restart(vorbis_dsp_state *v)
vorbis_dsp_state::pcm
float ** pcm
Definition: codec.h:62
vorbis_info
Definition: codec.h:27
vorbis_analysis_headerout
int vorbis_analysis_headerout(vorbis_dsp_state *v, vorbis_comment *vc, ogg_packet *op, ogg_packet *op_comm, ogg_packet *op_code)
vorbis_dsp_state::backend_state
void * backend_state
Definition: codec.h:84
vorbis_block::glue_bits
long glue_bits
Definition: codec.h:112
vorbis_dsp_clear
void vorbis_dsp_clear(vorbis_dsp_state *v)
vorbis_synthesis_idheader
int vorbis_synthesis_idheader(ogg_packet *op)
vorbis_dsp_state::res_bits
ogg_int64_t res_bits
Definition: codec.h:82
vorbis_analysis_buffer
float ** vorbis_analysis_buffer(vorbis_dsp_state *v, int vals)
vorbis_comment
Definition: codec.h:139
vorbis_dsp_state::W
long W
Definition: codec.h:72
vorbis_comment_add_tag
void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, const char *contents)
vorbis_bitrate_addblock
int vorbis_bitrate_addblock(vorbis_block *vb)
vorbis_block::pcmend
int pcmend
Definition: codec.h:95
vorbis_block::vd
vorbis_dsp_state * vd
Definition: codec.h:101
vorbis_info
struct vorbis_info vorbis_info
vorbis_dsp_state::pcm_current
int pcm_current
Definition: codec.h:65
vorbis_block
struct vorbis_block vorbis_block
vorbis_comment_query_count
int vorbis_comment_query_count(vorbis_comment *vc, const char *tag)
vorbis_synthesis_lapout
int vorbis_synthesis_lapout(vorbis_dsp_state *v, float ***pcm)
vorbis_synthesis_halfrate
int vorbis_synthesis_halfrate(vorbis_info *v, int flag)
vorbis_dsp_state::centerW
long centerW
Definition: codec.h:74
vorbis_dsp_state
struct vorbis_dsp_state vorbis_dsp_state
vorbis_info::bitrate_window
long bitrate_window
Definition: codec.h:64
vorbis_info_init
void vorbis_info_init(vorbis_info *vi)
vorbis_analysis_blockout
int vorbis_analysis_blockout(vorbis_dsp_state *v, vorbis_block *vb)
vorbis_block::granulepos
ogg_int64_t granulepos
Definition: codec.h:99
vorbis_block::totaluse
long totaluse
Definition: codec.h:108
vorbis_info::bitrate_upper
long bitrate_upper
Definition: codec.h:61
vorbis_comment
struct vorbis_comment vorbis_comment
vorbis_comment::comment_lengths
int * comment_lengths
Definition: codec.h:143
vorbis_packet_blocksize
long vorbis_packet_blocksize(vorbis_info *vi, ogg_packet *op)
vorbis_block_clear
int vorbis_block_clear(vorbis_block *vb)
vorbis_block::nW
long nW
Definition: codec.h:94
vorbis_dsp_state::eofflag
int eofflag
Definition: codec.h:69
vorbis_comment::user_comments
char ** user_comments
Definition: codec.h:142
vorbis_dsp_state::pcmret
float ** pcmret
Definition: codec.h:63
vorbis_comment_init
void vorbis_comment_init(vorbis_comment *vc)
vorbis_info_clear
void vorbis_info_clear(vorbis_info *vi)
vorbis_dsp_state::lW
long lW
Definition: codec.h:71
vorbis_block::opb
oggpack_buffer opb
Definition: codec.h:90
vorbis_version_string
const char * vorbis_version_string(void)
vorbis_bitrate_flushpacket
int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op)
vorbis_dsp_state::granulepos
ogg_int64_t granulepos
Definition: codec.h:76
vorbis_dsp_state
Definition: codec.h:58
vorbis_block::reap
struct alloc_chain * reap
Definition: codec.h:109
vorbis_block::localstore
void * localstore
Definition: codec.h:105
vorbis_dsp_state::nW
long nW
Definition: codec.h:73
vorbis_comment::comments
int comments
Definition: codec.h:144
vorbis_block::floor_bits
long floor_bits
Definition: codec.h:114
vorbis_info::channels
int channels
Definition: codec.h:43
vorbis_info::codec_setup
void * codec_setup
Definition: codec.h:66
vorbis_comment_add
void vorbis_comment_add(vorbis_comment *vc, const char *comment)
vorbis_dsp_state::floor_bits
ogg_int64_t floor_bits
Definition: codec.h:81
vorbis_synthesis_halfrate_p
int vorbis_synthesis_halfrate_p(vorbis_info *v)
vorbis_block::localalloc
long localalloc
Definition: codec.h:107
vorbis_dsp_state::analysisp
int analysisp
Definition: codec.h:59
vorbis_granule_time
double vorbis_granule_time(vorbis_dsp_state *v, ogg_int64_t granulepos)
vorbis_analysis_wrote
int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals)
alloc_chain::next
struct alloc_chain * next
Definition: codec.h:128
vorbis_block::localtop
long localtop
Definition: codec.h:106
vorbis_dsp_state::glue_bits
ogg_int64_t glue_bits
Definition: codec.h:79
vorbis_block
Definition: codec.h:87
vorbis_synthesis_read
int vorbis_synthesis_read(vorbis_dsp_state *v, int samples)
vorbis_analysis_init
int vorbis_analysis_init(vorbis_dsp_state *v, vorbis_info *vi)
vorbis_block::time_bits
long time_bits
Definition: codec.h:113
vorbis_synthesis_pcmout
int vorbis_synthesis_pcmout(vorbis_dsp_state *v, float ***pcm)
vorbis_block::res_bits
long res_bits
Definition: codec.h:115
alloc_chain
Definition: codec.h:126
vorbis_info::bitrate_nominal
long bitrate_nominal
Definition: codec.h:62
vorbis_synthesis_headerin
int vorbis_synthesis_headerin(vorbis_info *vi, vorbis_comment *vc, ogg_packet *op)
vorbis_dsp_state::time_bits
ogg_int64_t time_bits
Definition: codec.h:80
vorbis_dsp_state::preextrapolate
int preextrapolate
Definition: codec.h:68
vorbis_synthesis_blockin
int vorbis_synthesis_blockin(vorbis_dsp_state *v, vorbis_block *vb)
vorbis_dsp_state::sequence
ogg_int64_t sequence
Definition: codec.h:77
vorbis_block::sequence
ogg_int64_t sequence
Definition: codec.h:100
vorbis_info::rate
long rate
Definition: codec.h:44
vorbis_comment::vendor
char * vendor
Definition: codec.h:145
vorbis_info::bitrate_lower
long bitrate_lower
Definition: codec.h:63
vorbis_block_init
int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb)
vorbis_synthesis
int vorbis_synthesis(vorbis_block *vb, ogg_packet *op)
vorbis_block::eofflag
int eofflag
Definition: codec.h:98
vorbis_block::lW
long lW
Definition: codec.h:92
vorbis_block::mode
int mode
Definition: codec.h:96
vorbis_dsp_state::vi
vorbis_info * vi
Definition: codec.h:60
vorbis_info_blocksize
int vorbis_info_blocksize(vorbis_info *vi, int zo)