DEADSOFTWARE

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