DEADSOFTWARE

fix non portable pointer conversion
[d2df-sdl.git] / src / lib / vorbis / vorbis.pas
1 {
2 Translation of the vorbis headers for FreePascal
3 Copyright (C) 2006 by Ivo Steinmann
4 }
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 ********************************************************************)
18 unit vorbis;
20 {$MODE OBJFPC}
21 {$MINENUMSIZE 4}
22 {$PACKRECORDS C}
24 interface
26 uses
27 ctypes, ogg;
29 {$IF DEFINED(WINDOWS)}
30 {$IFDEF VORBIS_WINDOZE_STATIC}
31 {$LINKLIB libvorbisfile.a}
32 {$LINKLIB libvorbis.a}
33 {$ELSE}
34 {$DEFINE OGG_DYNAMIC}
35 const vorbislib = 'libvorbis-0.dll';
36 const vorbisfilelib = 'libvorbisfile-3.dll';
37 {$ENDIF}
38 {$ELSEIF DEFINED(UNIX)}
39 {$DEFINE OGG_DYNAMIC}
40 const vorbislib = 'libvorbis.so';
41 const vorbisfilelib = 'libvorbisfile.so';
42 {$ELSE}
43 {$ERROR libvorbis not supported on this platform. Fix it!}
44 {$ENDIF}
46 (***********************************************************************)
47 (* Header : codec.h *)
48 (***********************************************************************)
50 type
51 ppcfloat = ^pcfloat;
53 pvorbis_info = ^vorbis_info;
54 vorbis_info = record
55 version : cint;
56 channels : cint;
57 rate : clong;
59 { The below bitrate declarations are *hints*.
60 Combinations of the three values carry the following implications:
62 all three set to the same value:
63 implies a fixed rate bitstream
64 only nominal set:
65 implies a VBR stream that averages the nominal bitrate. No hard
66 upper/lower limit
67 upper and or lower set:
68 implies a VBR bitstream that obeys the bitrate limits. nominal
69 may also be set to give a nominal rate.
70 none set:
71 the coder does not care to speculate.
72 }
74 bitrate_upper : clong;
75 bitrate_nominal : clong;
76 bitrate_lower : clong;
77 bitrate_window : clong;
78 codec_setup : pointer;
79 end;
81 { vorbis_dsp_state buffers the current vorbis audio analysis/synthesis state. The DSP state belongs to a specific logical bitstream }
83 pvorbis_dsp_state = ^vorbis_dsp_state;
84 vorbis_dsp_state = record
85 analysisp : cint;
86 vi : pvorbis_info;
88 pcm : ppcfloat;
89 pcmret : ppcfloat;
90 pcm_storage : cint;
91 pcm_current : cint;
92 pcm_returned : cint;
94 preextrapolate : cint;
95 eofflag : cint;
97 lW : clong;
98 W : clong;
99 nW : clong;
100 centerW : clong;
102 granulepos : ogg_int64_t;
103 sequence : ogg_int64_t;
105 glue_bits : ogg_int64_t;
106 time_bits : ogg_int64_t;
107 floor_bits : ogg_int64_t;
108 res_bits : ogg_int64_t;
110 backend_state : pointer;
111 end;
113 { vorbis_block is a single block of data to be processed as part of
114 the analysis/synthesis stream; it belongs to a specific logical
115 bitstream, but is independant from other vorbis_blocks belonging to
116 that logical bitstream. }
118 palloc_chain = ^alloc_chain;
119 alloc_chain = record
120 ptr : pointer;
121 next : palloc_chain;
122 end;
124 pvorbis_block = ^vorbis_block;
125 vorbis_block = record
126 { necessary stream state for linking to the framing abstraction }
127 pcm : ppcfloat; { this is a pointer into local storage }
128 opb : oggpack_buffer;
130 lW : clong;
131 W : clong;
132 nW : clong;
133 pcmend : cint;
134 mode : cint;
136 eofflag : cint;
137 granulepos : ogg_int64_t;
138 sequence : ogg_int64_t;
139 vd : pvorbis_dsp_state; { For read-only access of configuration }
141 { local storage to avoid remallocing; it's up to the mapping to structure it }
142 localstore : pointer;
143 localtop : clong;
144 localalloc : clong;
145 totaluse : clong;
146 reap : palloc_chain;
148 { bitmetrics for the frame }
149 glue_bits : clong;
150 time_bits : clong;
151 floor_bits : clong;
152 res_bits : clong;
154 internal : pointer;
155 end;
157 { vorbis_info contains all the setup information specific to the
158 specific compression/decompression mode in progress (eg,
159 psychoacoustic settings, channel setup, options, codebook
160 etc). vorbis_info and substructures are in backends.h. }
162 { the comments are not part of vorbis_info so that vorbis_info can be static storage }
164 pvorbis_comment = ^vorbis_comment;
165 vorbis_comment = record
166 { unlimited user comment fields. libvorbis writes 'libvorbis' whatever vendor is set to in encode }
167 user_comments : ^pcchar;
168 comment_lengths : pcint;
169 comments : cint;
170 vendor : pcchar;
171 end;
174 { libvorbis encodes in two abstraction layers; first we perform DSP
175 and produce a packet (see docs/analysis.txt). The packet is then
176 coded into a framed OggSquish bitstream by the second layer (see
177 docs/framing.txt). Decode is the reverse process; we sync/frame
178 the bitstream and extract individual packets, then decode the
179 packet back into PCM audio.
181 The extra framing/packetizing is used in streaming formats, such as
182 files. Over the net (such as with UDP), the framing and
183 packetization aren't necessary as they're provided by the transport
184 and the streaming layer is not used }
186 { Vorbis PRIMITIVES: general }
188 procedure vorbis_info_init(var vi: vorbis_info); cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
189 procedure vorbis_info_clear(var vi: vorbis_info); cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
190 function vorbis_info_blocksize(var vi: vorbis_info; zo: cint): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
191 procedure vorbis_comment_init(var vc: vorbis_comment); cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
192 procedure vorbis_comment_add(var vc: vorbis_comment; comment: pchar); cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
193 procedure vorbis_comment_add_tag(var vc: vorbis_comment; tag: pchar; contents: pchar); cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
194 function vorbis_comment_query(var vc: vorbis_comment; tag: pchar; count: cint): pchar; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
195 function vorbis_comment_query_count(var vc: vorbis_comment; tag: pchar): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
196 procedure vorbis_comment_clear(var vc: vorbis_comment); cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
198 function vorbis_block_init(var v: vorbis_dsp_state; var vb: vorbis_block): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
199 function vorbis_block_clear(var vb: vorbis_block): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
200 procedure vorbis_dsp_clear(var v: vorbis_dsp_state); cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
201 function vorbis_granule_time(var v: vorbis_dsp_state; granulepos: ogg_int64_t): cdouble; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
203 { vorbislib PRIMITIVES: analysis/DSP layer }
205 function vorbis_analysis_init(var v: vorbis_dsp_state; var vi: vorbis_info): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
206 function vorbis_commentheader_out(var vc: vorbis_comment; var op: ogg_packet): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
207 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 OGG_DYNAMIC}vorbislib{$ENDIF};
208 function vorbis_analysis_buffer(var v: vorbis_dsp_state; vals: cint): ppcfloat; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
209 function vorbis_analysis_wrote(var v: vorbis_dsp_state; vals: cint): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
210 function vorbis_analysis_blockout(var v: vorbis_dsp_state; var vb: vorbis_block): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
211 function vorbis_analysis(var vb: vorbis_block; var op: ogg_packet): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
213 function vorbis_bitrate_addblock(var vb: vorbis_block): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
214 function vorbis_bitrate_flushpacket(var vd: vorbis_dsp_state; var op: ogg_packet): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
216 { vorbislib PRIMITIVES: synthesis layer }
218 function vorbis_synthesis_headerin(var vi: vorbis_info; var vc: vorbis_comment; var op: ogg_packet): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
220 function vorbis_synthesis_init(var v: vorbis_dsp_state; var vi: vorbis_info): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
221 function vorbis_synthesis_restart(var v: vorbis_dsp_state): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
222 function vorbis_synthesis(var vb: vorbis_block; var op: ogg_packet): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
223 function vorbis_synthesis_trackonly(var vb: vorbis_block; var op: ogg_packet): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
224 function vorbis_synthesis_blockin(var v: vorbis_dsp_state; var vb: vorbis_block): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
225 function vorbis_synthesis_pcmout(var v: vorbis_dsp_state; var pcm: ppcfloat): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
226 function vorbis_synthesis_lapout(var v: vorbis_dsp_state; var pcm: ppcfloat): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
227 function vorbis_synthesis_read(var v: vorbis_dsp_state; samples: cint): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
228 function vorbis_packet_blocksize(var vi: vorbis_info; var op: ogg_packet): clong; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
230 function vorbis_synthesis_halfrate(var v: vorbis_info; flag: cint): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
231 function vorbis_synthesis_halfrate_p(var v: vorbis_info): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbislib{$ENDIF};
233 { vorbislib ERRORS and return codes }
234 Const
235 OV_FALSE = -1;
236 OV_EOF = -2;
237 OV_HOLE = -3;
239 OV_EREAD = -128;
240 OV_EFAULT = -129;
241 OV_EIMPL = -130;
242 OV_EINVAL = -131;
243 OV_ENOTVORBIS = -132;
244 OV_EBADHEADER = -133;
245 OV_EVERSION = -134;
246 OV_ENOTAUDIO = -135;
247 OV_EBADPACKET = -136;
248 OV_EBADLINK = -137;
249 OV_ENOSEEK = -138;
252 (***********************************************************************)
253 (* Header : vorbisfile.h *)
254 (***********************************************************************)
256 type
258 {* The function prototypes for the callbacks are basically the same as for
260 * the stdio functions fread, fseek, fclose, ftell.
261 * The one difference is that the FILE * arguments have been replaced with
262 * a void * - this is to be used as a pointer to whatever internal data these
263 * functions might need. In the stdio case, it's just a FILE * cast to a void *
265 * If you use other functions, check the docs for these functions and return
266 * the right values. For seek_func(), you *MUST* return -1 if the stream is
267 * unseekable
268 *}
270 read_func = function(ptr: pointer; size, nmemb: csize_t; datasource: pointer): csize_t; cdecl;
271 seek_func = function(datasource: pointer; offset: ogg_int64_t; whence: cint): cint; cdecl;
272 close_func = function(datasource: pointer): cint; cdecl;
273 tell_func = function(datasource: pointer): clong; cdecl;
275 pov_callbacks = ^ov_callbacks;
276 ov_callbacks = record
277 read : read_func;
278 seek : seek_func;
279 close : close_func;
280 tell : tell_func;
281 end;
283 const
284 NOTOPEN = 0;
285 PARTOPEN = 1;
286 OPENED = 2;
287 STREAMSET = 3;
288 INITSET = 4;
290 type
291 POggVorbis_File = ^OggVorbis_File;
292 OggVorbis_File = record
293 datasource : pointer; { pointer to a FILE *, etc. }
294 seekable : cint;
295 offset : ogg_int64_t;
296 end_ : ogg_int64_t;
297 oy : ogg_sync_state;
299 { If the FILE handle isn't seekable (eg, a pipe), only the current stream appears }
300 links : cint;
301 offsets : pogg_int64_t;
302 dataoffsets : pogg_int64_t;
303 serialnos : pclong;
304 pcmlengths : pogg_int64_t; { overloaded to maintain binary compatability; x2 size, stores both beginning and end values }
305 vi : pvorbis_info;
306 vc : pvorbis_comment;
308 { Decoding working state local storage }
309 pcm_offset : ogg_int64_t;
310 ready_state : cint;
311 current_serialno: clong;
312 current_link : cint;
314 bittrack : cdouble;
315 samptrack : cdouble;
317 os : ogg_stream_state; { take physical pages, weld into a logical stream of packets }
318 vd : vorbis_dsp_state; { central working state for the packet->PCM decoder }
319 vb : vorbis_block; { local working space for packet->PCM decode }
321 callbacks : ov_callbacks;
322 end;
325 function ov_clear(var vf: OggVorbis_File): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
326 function ov_open(f: pointer; var vf: OggVorbis_File; initial: pointer; ibytes: clong): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
327 function ov_open_callbacks(datasource: pointer; var vf: OggVorbis_File; initial: pointer; ibytes: clong; callbacks: ov_callbacks): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
329 function ov_test(f: pointer; var vf: OggVorbis_File; initial: pointer; ibytes: clong): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
330 function ov_test_callbacks(datasource: pointer; var vf: OggVorbis_File; initial: pointer; ibytes: clong; callbacks: ov_callbacks): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
331 function ov_test_open(var vf: OggVorbis_File): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
333 function ov_bitrate(var vf: OggVorbis_File; i: cint): clong; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
334 function ov_bitrate_instant(var vf: OggVorbis_File): clong; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
335 function ov_streams(var vf: OggVorbis_File): clong; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
336 function ov_seekable(var vf: OggVorbis_File): clong; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
337 function ov_serialnumber(var vf: OggVorbis_File; i: cint): clong; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
339 function ov_raw_total(var vf: OggVorbis_File; i: cint): ogg_int64_t; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
340 function ov_pcm_total(var vf: OggVorbis_File; i: cint): ogg_int64_t; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
341 function ov_time_total(var vf: OggVorbis_File; i: cint): cdouble; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
343 function ov_raw_seek(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
344 function ov_pcm_seek(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
345 function ov_pcm_seek_page(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
346 function ov_time_seek(var vf: OggVorbis_File; pos: cdouble): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
347 function ov_time_seek_page(var vf: OggVorbis_File; pos: cdouble): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
349 function ov_raw_seek_lap(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
350 function ov_pcm_seek_lap(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
351 function ov_pcm_seek_page_lap(var vf: OggVorbis_File; pos: ogg_int64_t): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
352 function ov_time_seek_lap(var vf: OggVorbis_File; pos: cdouble): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
353 function ov_time_seek_page_lap(var vf: OggVorbis_File; pos: cdouble): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
355 function ov_raw_tell(var vf: OggVorbis_File): ogg_int64_t; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
356 function ov_pcm_tell(var vf: OggVorbis_File): ogg_int64_t; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
357 function ov_time_tell(var vf: OggVorbis_File): cdouble; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
359 function ov_info(var vf: OggVorbis_File; link: cint): pvorbis_info; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
360 function ov_comment(var vf: OggVorbis_File; link: cint): pvorbis_comment; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
362 function ov_read_float(var vf: OggVorbis_File; var pcm_channels: ppcfloat; samples: cint; bitstream: pcint): clong; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
363 function ov_read(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool; bitstream: pcint): clong; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
364 function ov_crosslap(var vf1: OggVorbis_File; var vf2: OggVorbis_File): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
366 function ov_halfrate(var vf: OggVorbis_File; flag: cint): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
367 function ov_halfrate_p(var vf: OggVorbis_File): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisfilelib{$ENDIF};
371 Developer of the A52 helpers for FreePascal
372 Copyright (C) 2006 by Ivo Steinmann
375 function ov_read_ext(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool): clong;
377 (***********************************************************************)
378 (* Header : vorbisenc.h *)
379 (***********************************************************************)
381 const
382 OV_ECTL_RATEMANAGE_GET = $10;
384 OV_ECTL_RATEMANAGE_SET = $11;
385 OV_ECTL_RATEMANAGE_AVG = $12;
386 OV_ECTL_RATEMANAGE_HARD = $13;
388 OV_ECTL_LOWPASS_GET = $20;
389 OV_ECTL_LOWPASS_SET = $21;
391 OV_ECTL_IBLOCK_GET = $30;
392 OV_ECTL_IBLOCK_SET = $31;
394 type
395 povectl_ratemanage_arg = ^ovectl_ratemanage_arg;
396 ovectl_ratemanage_arg = record
397 management_active : cint;
399 bitrate_hard_min : clong;
400 bitrate_hard_max : clong;
401 bitrate_hard_window : cdouble;
403 bitrate_av_lo : clong;
404 bitrate_av_hi : clong;
405 bitrate_av_window : cdouble;
406 bitrate_av_window_center : cdouble;
407 end;
409 // function vorbis_encode_init(var vi: vorbis_info; channels, rate, max_bitrate, nominal_bitrate, min_bitrate: clong): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisenclib{$ENDIF};
410 // function vorbis_encode_setup_managed(var vi: vorbis_info; channels, rate, max_bitrate, nominal_bitrate, min_bitrate: clong): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisenclib{$ENDIF};
411 // function vorbis_encode_setup_vbr(var vi: vorbis_info; channels, rate: clong; quality: cfloat): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisenclib{$ENDIF};
412 // (* quality level from 0. (lo) to 1. (hi) *)
413 // function vorbis_encode_init_vbr(var vi: vorbis_info; channels, rate: clong; base_quality: cfloat): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisenclib{$ENDIF};
414 // function vorbis_encode_setup_init(var vi: vorbis_info): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisenclib{$ENDIF};
415 // function vorbis_encode_ctl(var vi: vorbis_info; number: cint; arg: pointer): cint; cdecl; external {$IFDEF OGG_DYNAMIC}vorbisenclib{$ENDIF};
417 implementation
419 //k8: sighs. you HAVE to have a 16-byte aligned buffer, otherwise
420 // 32-bit SSE2-enabled builds *WILL* fail.
421 // it means that you *CANNOT* simply use a passed pointer.
422 // therefore this fuckery with internal buffer (because
423 // i am not sure that FPC will align stack variables
424 // correctly).
425 function ov_read_ext(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool): clong;
426 var
427 ofs: cint;
428 Num: cint;
429 Res: cint;
430 buf: array[0..3000] of Byte;
431 rd: cint;
432 bptr: ^Byte;
433 begin
434 // check blocksize here!
435 {if length mod 4 <> 0 then
436 Exit(0);}
438 ofs := 0;
439 num := length;
441 bptr := @buf;
442 while ((PtrUInt(bptr) and $0f) <> 0) do Inc(bptr);
444 while num > 0 do
445 begin
446 rd := num;
447 if (rd > 2048) then rd := 2048;
448 res := ov_read(vf, bptr, rd, bigendianp, word, sgned, nil);
449 //res := ov_read(vf, buffer + ofs, num, bigendianp, word, sgned, nil);
450 if res < 0 then
451 Exit(res);
453 if res = 0 then
454 Break;
456 //ofs := ofs + res;
457 //num := num - res;
458 Move(bptr^, buffer^, res);
459 buffer := buffer+res;
460 ofs := ofs+res;
461 num := num-res;
462 end;
464 Result := ofs;
465 end;
467 end.