4e02fa07bbe4707522bf3935c1b299f35e46a5b4
[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 } ogg_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 } ogg_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 frameno;
123
124 } ogg_packet;
125
126 typedef struct {
127   unsigned char *data;
128   int storage;
129   int fill;
130   int returned;
131
132   int unsynced;
133   int headerbytes;
134   int bodybytes;
135 } ogg_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 OggSquish 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 /* OggSquish BITSREAM PRIMITIVES: encoding **************************/
150
151 extern int    ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
152 extern int    ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
153
154 /* OggSquish BITSREAM PRIMITIVES: decoding **************************/
155
156 extern int    ogg_sync_init(ogg_sync_state *oy);
157 extern int    ogg_sync_clear(ogg_sync_state *oy);
158 extern int    ogg_sync_destroy(ogg_sync_state *oy);
159 extern int    ogg_sync_reset(ogg_sync_state *oy);
160
161 extern char  *ogg_sync_buffer(ogg_sync_state *oy, long size);
162 extern int    ogg_sync_wrote(ogg_sync_state *oy, long bytes);
163 extern int    ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
164 extern int    ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
165 extern int    ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
166
167 /* OggSquish BITSREAM PRIMITIVES: general ***************************/
168
169 extern int    ogg_stream_init(ogg_stream_state *os,int serialno);
170 extern int    ogg_stream_clear(ogg_stream_state *os);
171 extern int    ogg_stream_reset(ogg_stream_state *os);
172 extern int    ogg_stream_destroy(ogg_stream_state *os);
173 extern int    ogg_stream_eof(ogg_stream_state *os);
174
175 extern int    ogg_page_version(ogg_page *og);
176 extern int    ogg_page_continued(ogg_page *og);
177 extern int    ogg_page_bos(ogg_page *og);
178 extern int    ogg_page_eos(ogg_page *og);
179 extern size64 ogg_page_frameno(ogg_page *og);
180 extern int    ogg_page_serialno(ogg_page *og);
181 extern int    ogg_page_pageno(ogg_page *og);
182
183 /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
184
185 extern int  vorbis_analysis_init(vorbis_dsp_state *vd,vorbis_info *vi);
186 extern void vorbis_dsp_state_free(vorbis_dsp_state *vd);
187 extern int  vorbis_analysis_input(vorbis_dsp_state *vd,double **pcm,int vals);
188 extern int  vorbis_analysis(vorbis_dsp_state *vd,ogg_packet *op);
189
190 /* Vorbis PRIMITIVES: synthesis layer *******************************/
191
192 extern int  vorbis_synthesis_info(vorbis_dsp_state *vd,vorbis_info *vi);
193 extern int  vorbis_synthesis_packet(vorbis_dsp_state *vd,ogg_packet *op);
194 extern int  vorbis_synthesis_output(vorbis_dsp_state *vd,double **pcm);
195
196 #endif
197