[fpc-pascal] Array as result in function.

silvioprog silvioprog at gmail.com
Sat Jan 21 01:06:10 CET 2017


On Fri, Jan 20, 2017 at 7:36 PM, fredvs <fiens at hotmail.com> wrote:

> Re-hello.
>
> Ok, thanks Silvio, I will take this one from your advice, it works like
> charm:
>
> type
>   TOggOpusFile = THandle;
>

Hm... you should keep the same C data types. :-) I took a look at
`OggOpusFile` type, it is a struct:

https://github.com/gcp/opusfile/blob/9a9825df0319138fe845cbb19c250b642965c4b1/include/opusfile.h#L133

so on Pascal it makes more sense declared as:

type
  POggOpusFile = ^OggOpusFile;
  OggOpusFile = record
  end;

and finally:

op_read: function(OpusFile: POggOpusFile; ...

`PDArFloat` seems OK to `op_read_float`, but notice last comment regarding
`_pcm`.

"li: pointer" should be "li: pcint" in both funcs.

go slowly: these changes can raise new errors on your code. :-)

  TDArFloat = array of cfloat;
>   PDArFloat = ^TDArFloat;
>
> op_read: function(OpusFile: TOggOpusFile; pcm : PDArFloat; SampleCount:
> Integer; li: pointer): Integer;
>

`_pcm` on original code is an `int16` buffer... consider to using `cint16`:

https://github.com/gcp/opusfile/blob/9a9825df0319138fe845cbb19c250b642965c4b1/include/opusfile.h#L1873

op_read_float: function(OpusFile: TOggOpusFile; pcm : PDArFloat;
> SampleCount: Integer; li: pointer): Integer;
>
> Many thanks.
>
> Fre;D


-- 
Silvio Cl├ęcio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170120/36d0d82d/attachment.html>


More information about the fpc-pascal mailing list