Re: [fpc-pascal] Array as result in function.

2017-01-21 Thread fredvs
And this one ? op_read: function(OpusFile: TOggOpusFile; pcm : pcint; SampleCount: Integer; li: pcint): Integer; op_read_float: function(OpusFile: TOggOpusFile; pcm : pcfloat; SampleCount: Integer; li: pcint): Integer; op_read_stereo: function(OpusFile: TOggOpusFile; pcm : pcint; SampleCount:

Re: [fpc-pascal] Array as result in function.

2017-01-21 Thread silvioprog
On Sat, Jan 21, 2017 at 11:11 AM, fredvs wrote: > Hello everybody. > > Do you agree with this ? : > > type > TOggOpusFile = ^OggOpusFile; > OggOpusFile = record > end; > > op_read: function(OpusFile: TOggOpusFile; pcm : pcfloat; SampleCount: > Integer; li: pointer):

Re: [fpc-pascal] Array as result in function.

2017-01-21 Thread fredvs
Hello everybody. Do you agree with this ? : type TOggOpusFile = ^OggOpusFile; OggOpusFile = record end; op_read: function(OpusFile: TOggOpusFile; pcm : pcfloat; SampleCount: Integer; li: pointer): Integer; op_read_float: function(OpusFile: TOggOpusFile; pcm : pcfloat; SampleCount:

Re: [fpc-pascal] Array as result in function.

2017-01-21 Thread Vojtěch Čihák
1.2017 12:29 Předmět: Re: [fpc-pascal] Array as result in function. If the C code however is the one allocating the array (in which case the type is usually a pointer to a pointer, like "float**" or "^pcfloat" in Pascal) then you *must not* use a Pascal array, but instead

Re: [fpc-pascal] Array as result in function.

2017-01-21 Thread fredvs
@ Silvio > Try two tests: >$ echo -e '#include \nint main(){printf("size of float: %zu\\n", sizeof(float));return 0;}' > fredvs.c && gcc -o fredvs fredvs.c && clear && ./fredvs # it prints "size > of float: 4" on your terminal ==> size of float: 4 > $ echo "program fredvs;begin writeln('sizeof

Re: [fpc-pascal] Array as result in function.

2017-01-21 Thread Sven Barth
On 20.01.2017 23:36, fredvs wrote: > Re-hello. > > Ok, thanks Silvio, I will take this one from your advice, it works like > charm: > > type > TOggOpusFile = THandle; > TDArFloat = array of cfloat; > PDArFloat = ^TDArFloat; > > op_read: function(OpusFile: TOggOpusFile; pcm : PDArFloat;

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 9:06 PM, silvioprog wrote: [...] > `_pcm` on original code is an `int16` buffer... consider to using `cint16`: > Damn Gmail's Ctrl+Enter. -.-' I meant: "`_pcm` on original code is an `int16` buffer... consider to using `*pcint16*`:" -- Silvio

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 7:36 PM, fredvs 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

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 7:11 PM, fredvs wrote: > Hello Silvio. > > Wow, thanks, I will study it deep. > > By the way, the Opus Pascal wrappers are working. > You may listen, seek, saving to file, apply dsp,.. to Opus files. > You may try SimplePlayer demo in uos (all libraries

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread fredvs
Re-hello. Ok, thanks Silvio, I will take this one from your advice, it works like charm: type TOggOpusFile = THandle; TDArFloat = array of cfloat; PDArFloat = ^TDArFloat; op_read: function(OpusFile: TOggOpusFile; pcm : PDArFloat; SampleCount: Integer; li: pointer): Integer; op_read_float:

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread fredvs
Hello Silvio. Wow, thanks, I will study it deep. By the way, the Opus Pascal wrappers are working. You may listen, seek, saving to file, apply dsp,.. to Opus files. You may try SimplePlayer demo in uos (all libraries and Opus-audiofile included): https://github.com/fredvs/uos PS: BufferIn is

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 5:14 PM, silvioprog wrote: [...] > > It seems that function just increment the address of a (float) buffer, so: > I meant "It seems that function just fill a (float) buffer". ^^' -- Silvio Clécio ___

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 3:45 PM, fredvs wrote: > > Here, for example from OpusFile.h => > > OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of, > float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1); > > Translated in fpc with: > > op_read: function(OpusFile:

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread fredvs
Here, for example from OpusFile.h => OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of, float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1); Translated in fpc with: op_read: function(OpusFile: TOggOpusFile; var pcm; SampleCount: Integer; li: pointer): Integer; And used like this:

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 1:12 PM, fredvs wrote: [...] Please look at Sven's warn regarding Pascal arrays mixed with C arrays. Could you show us the original C function? -- Silvio Clécio ___ fpc-pascal maillist -

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread fredvs
Hello. Hum,... I am guilty. ;-( There was a SetLength(Bufferin, x) hidden. So the length of bufferin into the function was not the same as the "pure" one. So, to resume: If using: function arraycopy(arrayin : Tarrayfloat): Tarrayfloat; begin result := arrayin; end; ==> Perfect, the

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread fredvs
Hello. Some more investigations. Let say we have a array of float of length = 100 (arrayin): setlength(arrayin,100); A external library fill this array with 80 samples (ouframes). When using that arrayin pure (without any dsp) the sound is pure too. If using: function arraycopy(arrayin :

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread Sven Barth
Am 20.01.2017 13:18 schrieb "fredvs" : > > Thanks very much for answers. > > @ silvioprog: > > > using that function as callback with some (C/C++) library? > > Yes and check its parameter calling convention is ok. You shouldn't use Pascal arrays when interfacing with C/C++

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread fredvs
Thanks very much for answers. @ silvioprog: > using that function as callback with some (C/C++) library? Yes and check its parameter calling convention is ok. @ Martin. > result:= copy(arrayin); Ha, I did not know this one. I will try it (and write you asap). Many thanks. Fre;D -

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread Jürgen Hestermann
Am 2017-01-20 um 07:52 schrieb Martin Schreiber: > On Thursday 19 January 2017 22:50:36 fredvs wrote: >> function array_in_out(arrayin: TArFloat): TArFloat; >> begin >> result := arrayin; >> end; > Do you change items of "arrayin" later? If so the items of the result array > will be changed too,

Re: [fpc-pascal] Array as result in function.

2017-01-19 Thread Martin Schreiber
On Thursday 19 January 2017 22:50:36 fredvs wrote: > function array_in_out(arrayin: TArFloat): TArFloat; > begin > result := arrayin; > end; > Do you change items of "arrayin" later? If so the items of the result array will be changed too, dynamic array assignment copies the data pointer only.

Re: [fpc-pascal] Array as result in function.

2017-01-19 Thread silvioprog
On Thu, Jan 19, 2017 at 6:50 PM, fredvs wrote: > Hello. > > With this code, the result of the function does not have same format as the > array input: > > Why ? > > type > TArFloat = array of cfloat; > > function array_in_out(arrayin: TArFloat): TArFloat; > begin > result :=

[fpc-pascal] Array as result in function.

2017-01-19 Thread fredvs
Hello. With this code, the result of the function does not have same format as the array input: Why ? type TArFloat = array of cfloat; function array_in_out(arrayin: TArFloat): TArFloat; begin result := arrayin; end; Some more explaination. If in a code I use: var thebuffer: TArFloat;