Bringing my development in line with CVS now that the repository is set up.
[platform/upstream/libvorbis.git] / lib / codec.h
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5  * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
6  * PLEASE READ THESE TERMS DISTRIBUTING.                            *
7  *                                                                  *
8  * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-1999             *
9  * by 1999 Monty <monty@xiph.org> and The XIPHOPHORUS Company       *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: PCM data vector blocking, windowing and dis/reassembly
15  author: Monty <xiphmont@mit.edu>
16  modifications by: Monty
17  last modification date: Jul 13 1999
18
19  ********************************************************************/
20
21 #ifndef _vorbis_codec_h_
22 #define _vorbis_codec_h_
23
24 typedef struct vorbis_info{
25   int channels;
26   int rate;
27   int version;
28   int mode;
29   char **user_comments;
30   char *vendor;
31
32 } vorbis_info;
33  
34 typedef struct vorbis_dsp_state{
35   int samples_per_envelope_step;
36   int block_size[2];
37   double *window[2][2][2]; /* windowsize, leadin, leadout */
38
39   double **pcm;
40   int      pcm_storage;
41   int      pcm_channels;
42   int      pcm_current;
43
44   double **deltas;
45   int    **multipliers;
46   int      envelope_storage;
47   int      envelope_channels;
48   int      envelope_current;
49
50   int  initflag;
51
52   long lW;
53   long W;
54   long Sl;
55   long Sr;
56
57   long beginW;
58   long endW;
59   long beginSl;
60   long endSl;
61   long beginSr;
62   long endSr;
63
64   long frame;
65   long samples;
66
67 } vorbis_dsp_state;
68
69 typedef struct {
70   unsigned char *header;
71   long header_len;
72   unsigned char *body;
73   long body_len;
74 } vorbis_page;
75
76 typedef struct {
77  
78   /*             _________________________________________________
79      body_data: |_________________________________________________|
80      body_returned ----^       ^                          ^       ^
81      body_processed------------'                          |       |
82      body_fill     ---------------------------------------'       |     
83      body_storage  _______________________________________________' 
84
85      the header is labelled the same way.  Not all the pointers are 
86      used by both encode and decode */
87
88   unsigned char   *body_data;    /* bytes from packet bodies */
89   long    body_storage;          /* storage elements allocated */
90   long    body_fill;             /* elements stored; fill mark */
91   long    body_returned;         /* elements of fill returned */
92
93
94   int    *lacing_vals;    /* The values that will go to the segment table */
95   size64 *pcm_vals;       /* pcm_pos values for headers. Not compact
96                              this way, but it is simple coupled to the
97                              lacing fifo */
98   long    lacing_storage;
99   long    lacing_fill;
100   long    lacing_packet;
101   long    lacing_returned;
102
103   unsigned char    header[282];      /* working space for header encode */
104   int              header_fill;
105
106   int     e_o_s;          /* set when we have buffered the last packet in the
107                              logical bitstream */
108   int     b_o_s;          /* set after we've written the initial page
109                              of a logical bitstream */
110   long    serialno;
111   long    pageno;
112   size64  pcmpos;
113
114 } vorbis_stream_state;
115
116 typedef struct {
117   unsigned char *packet;
118   long  bytes;
119   long  b_o_s;
120   long  e_o_s;
121
122   size64 pcm_pos;
123
124 } vorbis_packet;
125
126 typedef struct {
127   char *data;
128   int storage;
129   int fill;
130   int returned;
131
132   int unsynced;
133   int headerbytes;
134   int bodybytes;
135 } vorbis_sync_state;
136
137 /* libvorbis encodes in two abstraction layers; first we perform DSP
138    and produce a packet (see docs/analysis.txt).  The packet is then
139    coded into a framed bitstream by the second layer (see
140    docs/framing.txt).  Decode is the reverse process; we sync/frame
141    the bitstream and extract individual packets, then decode the
142    packet back into PCM audio.
143
144    The extra framing/packetizing is used in streaming formats, such as
145    files.  Over the net (such as with UDP), the framing and
146    packetization aren't necessary as they're provided by the transport
147    and the streaming layer is not used */
148
149 /* ENCODING PRIMITIVES: analysis/DSP layer **************************/
150
151 extern int vorbis_analysis_init(vorbis_dsp_state *vd,vorbis_info *i);
152 extern void vorbis_dsp_state_free(vorbis_dsp_state *vd);
153 extern int vorbis_analysis_input(vorbis_dsp_state *vd,double **pcm,int vals);
154 extern int vorbis_analysis(vorbis_dsp_state *vd,vorbis_packet *vp);
155
156 /* GENERAL PRIMITIVES: packet streaming layer ***********************/
157
158 extern int vorbis_stream_init(vorbis_stream_state *vs,int serialno);
159 extern int vorbis_stream_clear(vorbis_stream_state *vs);
160 extern int vorbis_stream_destroy(vorbis_stream_state *vs);
161 extern int vorbis_stream_eof(vorbis_stream_state *vs);
162
163 extern int vorbis_page_version(vorbis_page *vg);
164 extern int vorbis_page_continued(vorbis_page *vg);
165 extern int vorbis_page_bos(vorbis_page *vg);
166 extern int vorbis_page_eos(vorbis_page *vg);
167 extern size64 vorbis_page_pcmpos(vorbis_page *vg);
168 extern int vorbis_page_serialno(vorbis_page *vg);
169 extern int vorbis_page_pageno(vorbis_page *vg);
170
171 /* ENCODING PRIMITIVES: packet streaming layer **********************/
172
173 extern int vorbis_stream_encode(vorbis_stream_state *vs,vorbis_packet *vp);
174 extern int vorbis_stream_page(vorbis_stream_state *vs, vorbis_page *vg);
175
176 /* DECODING PRIMITIVES: packet streaming layer **********************/
177
178 extern int vorbis_sync_init(vorbis_sync_state *vs);
179 extern int vorbis_sync_clear(vorbis_sync_state *vs);
180 extern int vorbis_sync_destroy(vorbis_sync_state *vs);
181
182 extern char *vorbis_decode_buffer(vorbis_sync_state *vs, long size);
183 extern int vorbis_decode_wrote(vorbis_sync_state *vs, long bytes);
184 extern int vorbis_decode_stream(vorbis_sync_state *vs, vorbis_page *vg);
185 extern int vorbis_decode_page(vorbis_stream_state *vs, vorbis_page *vg);
186 extern int vorbis_stream_packet(vorbis_stream_state *vs,vorbis_packet *vp);
187
188 extern int vorbis_sync_reset(vorbis_sync_state *vs);
189 extern int vorbis_stream_reset(vorbis_stream_state *vs);
190
191 /* DECODING PRIMITIVES: synthesis layer *****************************/
192
193 extern int vorbis_synthesis_info(vorbis_dsp_state *vd,vorbis_info *vi);
194 extern int vorbis_synthesis(vorbis_dsp_state *vd,vorbis_packet *vp);
195 extern int vorbis_synthesis_output(vorbis_dsp_state *vd,double **pcm);
196
197 #endif
198