1 {
2   Translation of the vorbis headers for FreePascal
3   Copyright (C) 2006 by Ivo Steinmann
4 }
5 
6 (********************************************************************
7  *                                                                  *
8  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
9  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
10  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
11  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
12  *                                                                  *
13  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
14  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
15  *                                                                  *
16  ********************************************************************)
17 
18 unit vorbis;
19 
20 {$mode objfpc}
21 {$MINENUMSIZE 4}
22 {$PACKRECORDS C}
23 
24 interface
25 
26 uses
27   ctypes, ogg;
28 
29 {$IFDEF WINDOWS}
30   {$DEFINE DYNLINK}
31 {$ENDIF}
32 
33 {$IFDEF DYNLINK}
34 const
35 {$IF Defined(WINDOWS)}
36   vorbislib     = 'vorbis.dll';
37   vorbisfilelib = 'vorbisfile.dll';
38   vorbisenclib  = 'vorbisenc.dll';
39 {$ELSEIF Defined(UNIX)}
40   vorbislib     = 'libvorbis.so';
41   vorbisfilelib = 'libvorbisfile.so';
42   vorbisenclib  = 'libvorbisenc.so';
43 {$ELSE}
44   {$MESSAGE ERROR 'DYNLINK not supported'}
45 {$IFEND}
46 {$ELSE}
47   {$LINKLIB vorbis}
48   {$LINKLIB vorbisfile}
49   {$LINKLIB vorbisenc}
50 {$ENDIF}
51 
52 (***********************************************************************)
53 (* Header : codec.h                                                    *)
54 (***********************************************************************)
55 
56 type
57   ppcfloat = ^pcfloat;
58 
59   pvorbis_info = ^vorbis_info;
60   vorbis_info = record
61     version         : cint;
62     channels        : cint;
63     rate            : clong;
64 
65   { The below bitrate declarations are *hints*.
66      Combinations of the three values carry the following implications:
67 
68      all three set to the same value:
69        implies a fixed rate bitstream
70      only nominal set:
71        implies a VBR stream that averages the nominal bitrate.  No hard
72        upper/lower limit
73      upper and or lower set:
74        implies a VBR bitstream that obeys the bitrate limits. nominal
75        may also be set to give a nominal rate.
76      none set:
77        the coder does not care to speculate.
78   }
79 
80     bitrate_upper   : clong;
81     bitrate_nominal : clong;
82     bitrate_lower   : clong;
83     bitrate_window  : clong;
84     codec_setup     : pointer;
85   end;
86 
87 { vorbis_dsp_state buffers the current vorbis audio analysis/synthesis state.  The DSP state belongs to a specific logical bitstream }
88 
89   pvorbis_dsp_state = ^vorbis_dsp_state;
90   vorbis_dsp_state = record
91     analysisp       : cint;
92     vi              : pvorbis_info;
93 
94     pcm             : ppcfloat;
95     pcmret          : ppcfloat;
96     pcm_storage     : cint;
97     pcm_current     : cint;
98     pcm_returned    : cint;
99 
100     preextrapolate  : cint;
101     eofflag         : cint;
102 
103     lW              : clong;
104     W               : clong;
105     nW              : clong;
106     centerW         : clong;
107 
108     granulepos      : ogg_int64_t;
109     sequence        : ogg_int64_t;
110 
111     glue_bits       : ogg_int64_t;
112     time_bits       : ogg_int64_t;
113     floor_bits      : ogg_int64_t;
114     res_bits        : ogg_int64_t;
115 
116     backend_state   : pointer;
117   end;
118 
119 { vorbis_block is a single block of data to be processed as part of
120   the analysis/synthesis stream; it belongs to a specific logical
121   bitstream, but is independant from other vorbis_blocks belonging to
122   that logical bitstream. }
123 
124   palloc_chain = ^alloc_chain;
125   alloc_chain = record
126     ptr             : pointer;
127     next            : palloc_chain;
128   end;
129 
130   pvorbis_block = ^vorbis_block;
131   vorbis_block = record
132   { necessary stream state for linking to the framing abstraction }
133     pcm             : ppcfloat;            { this is a pointer into local storage }
134     opb             : oggpack_buffer;
135 
136     lW              : clong;
137     W               : clong;
138     nW              : clong;
139     pcmend          : cint;
140     mode            : cint;
141 
142     eofflag         : cint;
143     granulepos      : ogg_int64_t;
144     sequence        : ogg_int64_t;
145     vd              : pvorbis_dsp_state; { For read-only access of configuration }
146 
147   { local storage to avoid remallocing; it's up to the mapping to structure it }
148     localstore      : pointer;
149     localtop        : clong;
150     localalloc      : clong;
151     totaluse        : clong;
152     reap            : palloc_chain;
153 
154   { bitmetrics for the frame }
155     glue_bits       : clong;
156     time_bits       : clong;
157     floor_bits      : clong;
158     res_bits        : clong;
159 
160     internal        : pointer;
161   end;
162 
163 { vorbis_info contains all the setup information specific to the
164   specific compression/decompression mode in progress (eg,
165   psychoacoustic settings, channel setup, options, codebook
166   etc). vorbis_info and substructures are in backends.h. }
167 
168 { the comments are not part of vorbis_info so that vorbis_info can be static storage }
169 
170   pvorbis_comment = ^vorbis_comment;
171   vorbis_comment = record
172   { unlimited user comment fields.  libvorbis writes 'libvorbis' whatever vendor is set to in encode }
173     user_comments   : ^pcchar;
174     comment_lengths : pcint;
175     comments        : cint;
176     vendor          : pcchar;
177   end;
178 
179 
180 { libvorbis encodes in two abstraction layers; first we perform DSP
181   and produce a packet (see docs/analysis.txt).  The packet is then
182   coded into a framed OggSquish bitstream by the second layer (see
183   docs/framing.txt).  Decode is the reverse process; we sync/frame
184   the bitstream and extract individual packets, then decode the
185   packet back into PCM audio.
186 
187   The extra framing/packetizing is used in streaming formats, such as
188   files.  Over the net (such as with UDP), the framing and
189   packetization aren't necessary as they're provided by the transport
190   and the streaming layer is not used }
191 
192 { Vorbis PRIMITIVES: general }
193 
194 procedure vorbis_info_init(var vi: vorbis_info); cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
195 procedure vorbis_info_clear(var vi: vorbis_info); cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_info_blocksizenull196 function  vorbis_info_blocksize(var vi: vorbis_info; zo: cint): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
197 procedure vorbis_comment_init(var vc: vorbis_comment); cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
198 procedure vorbis_comment_add(var vc: vorbis_comment; comment: pchar); cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
199 procedure vorbis_comment_add_tag(var vc: vorbis_comment; tag: pchar; contents: pchar); cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_comment_querynull200 function  vorbis_comment_query(var vc: vorbis_comment; tag: pchar; count: cint): pchar; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_comment_query_countnull201 function  vorbis_comment_query_count(var vc: vorbis_comment; tag: pchar): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
202 procedure vorbis_comment_clear(var vc: vorbis_comment); cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
203 
vorbis_block_initnull204 function  vorbis_block_init(var v: vorbis_dsp_state; var vb: vorbis_block): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_block_clearnull205 function  vorbis_block_clear(var vb: vorbis_block): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
206 procedure vorbis_dsp_clear(var v: vorbis_dsp_state); cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_granule_timenull207 function  vorbis_granule_time(var v: vorbis_dsp_state; granulepos: ogg_int64_t): cdouble; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
208 
209 { vorbislib PRIMITIVES: analysis/DSP layer }
210 
vorbis_analysis_initnull211 function  vorbis_analysis_init(var v: vorbis_dsp_state; var vi: vorbis_info): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_commentheader_outnull212 function  vorbis_commentheader_out(var vc: vorbis_comment; var op: ogg_packet): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_analysis_headeroutnull213 function  vorbis_analysis_headerout(var v:vorbis_dsp_state; var vc: vorbis_comment; var op: ogg_packet; var op_comm: ogg_packet; var op_code: ogg_packet): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_analysis_buffernull214 function  vorbis_analysis_buffer(var v: vorbis_dsp_state; vals: cint): ppcfloat; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_analysis_wrotenull215 function  vorbis_analysis_wrote(var v: vorbis_dsp_state; vals: cint): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_analysis_blockoutnull216 function  vorbis_analysis_blockout(var v: vorbis_dsp_state; var vb: vorbis_block): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_analysisnull217 function  vorbis_analysis(var vb: vorbis_block; var op: ogg_packet): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
218 
vorbis_bitrate_addblocknull219 function  vorbis_bitrate_addblock(var vb: vorbis_block): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_bitrate_flushpacketnull220 function  vorbis_bitrate_flushpacket(var vd: vorbis_dsp_state; var op: ogg_packet): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
221 
222 { vorbislib PRIMITIVES: synthesis layer }
223 
vorbis_synthesis_headerinnull224 function  vorbis_synthesis_headerin(var vi: vorbis_info; var vc: vorbis_comment; var op: ogg_packet): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
225 
vorbis_synthesis_initnull226 function  vorbis_synthesis_init(var v: vorbis_dsp_state; var vi: vorbis_info): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_synthesis_restartnull227 function  vorbis_synthesis_restart(var v: vorbis_dsp_state): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_synthesisnull228 function  vorbis_synthesis(var vb: vorbis_block; var op: ogg_packet): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_synthesis_trackonlynull229 function  vorbis_synthesis_trackonly(var vb: vorbis_block; var op: ogg_packet): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_synthesis_blockinnull230 function  vorbis_synthesis_blockin(var v: vorbis_dsp_state; var vb: vorbis_block): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_synthesis_pcmoutnull231 function  vorbis_synthesis_pcmout(var v: vorbis_dsp_state; var pcm: ppcfloat): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_synthesis_lapoutnull232 function  vorbis_synthesis_lapout(var v: vorbis_dsp_state; var pcm: ppcfloat): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_synthesis_readnull233 function  vorbis_synthesis_read(var v: vorbis_dsp_state; samples: cint): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_packet_blocksizenull234 function  vorbis_packet_blocksize(var vi: vorbis_info; var op: ogg_packet): clong; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
235 
vorbis_synthesis_halfratenull236 function  vorbis_synthesis_halfrate(var v: vorbis_info; flag: cint): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
vorbis_synthesis_halfrate_pnull237 function  vorbis_synthesis_halfrate_p(var v: vorbis_info): cint; cdecl; external {$IFDEF DYNLINK}vorbislib{$ENDIF};
238 
239 { vorbislib ERRORS and return codes }
240 Const
241   OV_FALSE          = -1;
242   OV_EOF            = -2;
243   OV_HOLE           = -3;
244 
245   OV_EREAD          = -128;
246   OV_EFAULT         = -129;
247   OV_EIMPL          = -130;
248   OV_EINVAL         = -131;
249   OV_ENOTVORBIS     = -132;
250   OV_EBADHEADER     = -133;
251   OV_EVERSION       = -134;
252   OV_ENOTAUDIO      = -135;
253   OV_EBADPACKET     = -136;
254   OV_EBADLINK       = -137;
255   OV_ENOSEEK        = -138;
256 
257 
258 (***********************************************************************)
259 (* Header : vorbisfile.h                                               *)
260 (***********************************************************************)
261 
262 type
263 
264 {* The function prototypes for the callbacks are basically the same as for
265 
266  * the stdio functions fread, fseek, fclose, ftell.
267  * The one difference is that the FILE * arguments have been replaced with
268  * a void * - this is to be used as a pointer to whatever internal data these
269  * functions might need. In the stdio case, it's just a FILE * cast to a void *
270  *
271  * If you use other functions, check the docs for these functions and return
272  * the right values. For seek_func(), you *MUST* return -1 if the stream is
273  * unseekable
274  *}
275 
trnull276   read_func  = function(ptr: pointer; size, nmemb: csize_t; datasource: pointer): csize_t; cdecl;
atasourcenull277   seek_func  = function(datasource: pointer; offset: ogg_int64_t; whence: cint): cint; cdecl;
atasourcenull278   close_func = function(datasource: pointer): cint; cdecl;
atasourcenull279   tell_func  = function(datasource: pointer): clong; cdecl;
280 
281   pov_callbacks = ^ov_callbacks;
282   ov_callbacks = record
283     read            : read_func;
284     seek            : seek_func;
285     close           : close_func;
286     tell            : tell_func;
287   end;
288 
289 const
290   NOTOPEN           = 0;
291   PARTOPEN          = 1;
292   OPENED            = 2;
293   STREAMSET         = 3;
294   INITSET           = 4;
295 
296 type
297   POggVorbis_File = ^OggVorbis_File;
298   OggVorbis_File = record
299     datasource      : pointer; { pointer to a FILE *, etc. }
300     seekable        : cint;
301     offset          : ogg_int64_t;
302     end_            : ogg_int64_t;
303     oy              : ogg_sync_state;
304 
305   { If the FILE handle isn't seekable (eg, a pipe), only the current stream appears }
306     links           : cint;
307     offsets         : pogg_int64_t;
308     dataoffsets     : pogg_int64_t;
309     serialnos       : pclong;
310     pcmlengths      : pogg_int64_t; { overloaded to maintain binary compatability; x2 size, stores both beginning and end values }
311     vi              : pvorbis_info;
312     vc              : pvorbis_comment;
313 
314   { Decoding working state local storage }
315     pcm_offset      : ogg_int64_t;
316     ready_state     : cint;
317     current_serialno: clong;
318     current_link    : cint;
319 
320     bittrack        : cdouble;
321     samptrack       : cdouble;
322 
323     os              : ogg_stream_state; { take physical pages, weld into a logical stream of packets }
324     vd              : vorbis_dsp_state; { central working state for the packet->PCM decoder }
325     vb              : vorbis_block;     { local working space for packet->PCM decode }
326 
327     callbacks       : ov_callbacks;
328   end;
329 
330 
ov_clearnull331 function ov_clear(var vf: OggVorbis_File): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_opennull332 function ov_open(f: pointer; var vf: OggVorbis_File; initial: pointer; ibytes: clong): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_open_callbacksnull333 function ov_open_callbacks(datasource: pointer; var vf: OggVorbis_File; initial: pointer; ibytes: clong; callbacks: ov_callbacks): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
334 
ov_testnull335 function ov_test(f: pointer; var vf: OggVorbis_File; initial: pointer; ibytes: clong): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_test_callbacksnull336 function ov_test_callbacks(datasource: pointer; var vf: OggVorbis_File; initial: pointer; ibytes: clong; callbacks: ov_callbacks): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_test_opennull337 function ov_test_open(var vf: OggVorbis_File): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
338 
ov_bitratenull339 function ov_bitrate(var vf: OggVorbis_File; i: cint): clong; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_bitrate_instantnull340 function ov_bitrate_instant(var vf: OggVorbis_File): clong; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_streamsnull341 function ov_streams(var vf: OggVorbis_File): clong; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_seekablenull342 function ov_seekable(var vf: OggVorbis_File): clong; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_serialnumbernull343 function ov_serialnumber(var vf: OggVorbis_File; i: cint): clong; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
344 
ov_raw_totalnull345 function ov_raw_total(var vf: OggVorbis_File; i: cint): ogg_int64_t; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_pcm_totalnull346 function ov_pcm_total(var vf: OggVorbis_File; i: cint): ogg_int64_t; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_time_totalnull347 function ov_time_total(var vf: OggVorbis_File; i: cint): cdouble; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
348 
ov_raw_seeknull349 function ov_raw_seek(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_pcm_seeknull350 function ov_pcm_seek(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_pcm_seek_pagenull351 function ov_pcm_seek_page(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_time_seeknull352 function ov_time_seek(var vf: OggVorbis_File; pos: cdouble): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_time_seek_pagenull353 function ov_time_seek_page(var vf: OggVorbis_File; pos: cdouble): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
354 
ov_raw_seek_lapnull355 function ov_raw_seek_lap(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_pcm_seek_lapnull356 function ov_pcm_seek_lap(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_pcm_seek_page_lapnull357 function ov_pcm_seek_page_lap(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_time_seek_lapnull358 function ov_time_seek_lap(var vf: OggVorbis_File; pos: cdouble): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_time_seek_page_lapnull359 function ov_time_seek_page_lap(var vf: OggVorbis_File; pos: cdouble): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
360 
ov_raw_tellnull361 function ov_raw_tell(var vf: OggVorbis_File): ogg_int64_t; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_pcm_tellnull362 function ov_pcm_tell(var vf: OggVorbis_File): ogg_int64_t; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_time_tellnull363 function ov_time_tell(var vf: OggVorbis_File): cdouble; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
364 
ov_infonull365 function ov_info(var vf: OggVorbis_File; link: cint): pvorbis_info; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_commentnull366 function ov_comment(var vf: OggVorbis_File; link: cint): pvorbis_comment; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
367 
ov_read_floatnull368 function ov_read_float(var vf: OggVorbis_File; var pcm_channels: ppcfloat; samples: cint; bitstream: pcint): clong; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_readnull369 function ov_read(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool; bitstream: pcint): clong; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_crosslapnull370 function ov_crosslap(var vf1: OggVorbis_File; var vf2: OggVorbis_File): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
371 
ov_halfratenull372 function ov_halfrate(var vf: OggVorbis_File; flag: cint): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
ov_halfrate_pnull373 function ov_halfrate_p(var vf: OggVorbis_File): cint; cdecl; external {$IFDEF DYNLINK}vorbisfilelib{$ENDIF};
374 
375 
376 {
377   Developer of the A52 helpers for FreePascal
378   Copyright (C) 2006 by Ivo Steinmann
379 }
380 
ov_read_extnull381 function ov_read_ext(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool): clong;
382 
383 
384 (***********************************************************************)
385 (* Header : vorbisenc.h                                                *)
386 (***********************************************************************)
387 
388 const
389   OV_ECTL_RATEMANAGE_GET       = $10;
390 
391   OV_ECTL_RATEMANAGE_SET       = $11;
392   OV_ECTL_RATEMANAGE_AVG       = $12;
393   OV_ECTL_RATEMANAGE_HARD      = $13;
394 
395   OV_ECTL_LOWPASS_GET          = $20;
396   OV_ECTL_LOWPASS_SET          = $21;
397 
398   OV_ECTL_IBLOCK_GET           = $30;
399   OV_ECTL_IBLOCK_SET           = $31;
400 
401 type
402   povectl_ratemanage_arg = ^ovectl_ratemanage_arg;
403   ovectl_ratemanage_arg = record
404     management_active        : cint;
405 
406     bitrate_hard_min         : clong;
407     bitrate_hard_max         : clong;
408     bitrate_hard_window      : cdouble;
409 
410     bitrate_av_lo            : clong;
411     bitrate_av_hi            : clong;
412     bitrate_av_window        : cdouble;
413     bitrate_av_window_center : cdouble;
414   end;
415 
vorbis_encode_initnull416 function vorbis_encode_init(var vi: vorbis_info; channels, rate, max_bitrate, nominal_bitrate, min_bitrate: clong): cint; cdecl; external {$IFDEF DYNLINK}vorbisenclib{$ENDIF};
vorbis_encode_setup_managednull417 function vorbis_encode_setup_managed(var vi: vorbis_info; channels, rate, max_bitrate, nominal_bitrate, min_bitrate: clong): cint; cdecl; external {$IFDEF DYNLINK}vorbisenclib{$ENDIF};
vorbis_encode_setup_vbrnull418 function vorbis_encode_setup_vbr(var vi: vorbis_info; channels, rate: clong; quality: cfloat): cint; cdecl; external {$IFDEF DYNLINK}vorbisenclib{$ENDIF};
419 (* quality level from 0. (lo) to 1. (hi) *)
vorbis_encode_init_vbrnull420 function vorbis_encode_init_vbr(var vi: vorbis_info; channels, rate: clong; base_quality: cfloat): cint; cdecl; external {$IFDEF DYNLINK}vorbisenclib{$ENDIF};
vorbis_encode_setup_initnull421 function vorbis_encode_setup_init(var vi: vorbis_info): cint; cdecl; external {$IFDEF DYNLINK}vorbisenclib{$ENDIF};
vorbis_encode_ctlnull422 function vorbis_encode_ctl(var vi: vorbis_info; number: cint; arg: pointer): cint; cdecl; external {$IFDEF DYNLINK}vorbisenclib{$ENDIF};
423 
424 implementation
425 
ov_read_extnull426 function ov_read_ext(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool): clong;
427 var
428   ofs: cint;
429   Num: cint;
430   Res: cint;
431 begin
432   // check blocksize here!
433   {if length mod 4 <> 0 then
434     Exit(0);}
435 
436   ofs := 0;
437   num := length;
438 
439   while num > 0 do
440   begin
441     res := ov_read(vf, pointer(ptruint(buffer) + ofs), num, bigendianp, word, sgned, nil);
442     if res < 0 then
443       Exit(res);
444 
445     if res = 0 then
446       Break;
447 
448     ofs := ofs + res;
449     num := num - res;
450   end;
451 
452   Result := ofs;
453 end;
454 
455 end.
456 
457