[fpc-pascal] Array as result in function.

fredvs fiens at hotmail.com
Fri Jan 20 15:59:33 CET 2017


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 : Tarrayfloat): Tarrayfloat;
begin
result := arrayin;
end;

==> Bad noisy sound, even using

but if using:

function arraycopy(arrayin : Tarrayfloat; outfames: integer): Tarrayfloat;
begin
SetLength(arrayin, outframes); 
result := arrayin;
end;

===> OK, perfect sound.

Why ?

_____________________________________

> You shouldn't use Pascal arrays when interfacing with C/C++ code as
> especially dynamic arrays have a different format (though you can pass a
> pointer to the first array element).

Huh, what do you propose instead, I am totally open to new idea ?
(But using dynamic arrays gives me lovely results).

> Maybe show us how the original C function looks like.

All the audio-wrappers use buffers to store the data.
I use dynamic arrays for that buffers.

In https://github.com/fredvs/uos there are Pascal wrappers to C libraries:

uos_Portaudio.pas
uos_Mpg123.pas
uos_SoundFile.pas
uos_Opus.pas
uos_AAC.pas
uos_SoundTouch.pas

...

Thanks.

Fre;D




Thanks.

Fre;D





-----
Many thanks ;-)
--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Array-as-result-in-function-tp5727366p5727378.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.



More information about the fpc-pascal mailing list