DEADSOFTWARE

fix link libraries on osx
[d2df-sdl.git] / src / lib / vorbis / vorbis.pas
index a4a21b5dc86e5b195f987a55a8340d3298895f40..87833bd69edbc81911bd7d4dbae16ca81022252e 100644 (file)
@@ -37,8 +37,10 @@ uses
   {$ENDIF}
 {$ELSEIF DEFINED(UNIX)}
   {$DEFINE OGG_DYNAMIC}
-  const vorbislib = 'libvorbis.so';
-  const vorbisfilelib = 'libvorbisfile.so';
+  {$LINKLIB libvorbis}
+  {$LINKLIB libvorbisfile}
+  const vorbislib = 'libvorbis';
+  const vorbisfilelib = 'libvorbisfile';
 {$ELSE}
   {$ERROR libvorbis not supported on this platform. Fix it!}
 {$ENDIF}
@@ -416,11 +418,20 @@ type
 
 implementation
 
+//k8: sighs. you HAVE to have a 16-byte aligned buffer, otherwise
+//    32-bit SSE2-enabled builds *WILL* fail.
+//    it means that you *CANNOT* simply use a passed pointer.
+//    therefore this fuckery with internal buffer (because
+//    i am not sure that FPC will align stack variables
+//    correctly).
 function ov_read_ext(var vf: OggVorbis_File; buffer: pointer; length: cint; bigendianp: cbool; word: cint; sgned: cbool): clong;
 var
   ofs: cint;
   Num: cint;
   Res: cint;
+  buf: array[0..3000] of Byte;
+  rd: cint;
+  bptr: ^Byte;
 begin
   // check blocksize here!
   {if length mod 4 <> 0 then
@@ -429,17 +440,27 @@ begin
   ofs := 0;
   num := length;
 
+  bptr := @buf;
+  while ((PtrUInt(bptr) and $0f) <> 0) do Inc(bptr);
+
   while num > 0 do
   begin
-    res := ov_read(vf, buffer + ofs, num, bigendianp, word, sgned, nil);
+    rd := num;
+    if (rd > 2048) then rd := 2048;
+    res := ov_read(vf, bptr, rd, bigendianp, word, sgned, nil);
+    //res := ov_read(vf, buffer + ofs, num, bigendianp, word, sgned, nil);
     if res < 0 then
       Exit(res);
 
     if res = 0 then
       Break;
 
-    ofs := ofs + res;
-    num := num - res;
+    //ofs := ofs + res;
+    //num := num - res;
+    Move(bptr^, buffer^, res);
+    buffer := buffer+res;
+    ofs := ofs+res;
+    num := num-res;
   end;
 
   Result := ofs;