From 2d289acb4cb4cef37b53ecf37b79f5331e5b9dec Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Fri, 20 Sep 2019 06:26:25 +0300 Subject: [PATCH] fixed ogg/vorbis reader for 32-bit SSE2-enabled systems --- src/lib/vorbis/vorbis.pas | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/lib/vorbis/vorbis.pas b/src/lib/vorbis/vorbis.pas index a4a21b5..81b026f 100644 --- a/src/lib/vorbis/vorbis.pas +++ b/src/lib/vorbis/vorbis.pas @@ -416,11 +416,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 +438,27 @@ begin ofs := 0; num := length; + bptr := @buf; + while ((LongWord(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; -- 2.29.2