Result of array of float ? lazarus / 62-General ---------------------------------------------------------------------- Fred vS · 2021-02-08 14:49 Hello. I am busy with a simple audio program. There is a thread-loop. Doing this, the sound is perfect: (Note that the fbuffer variable is part of the procedure) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure ThreadLoopProc();varfbuffer: array of float;i : integer;beginwhile something dobegin    setlength(fbuffer,1000);        // clean buffer (not needed but in case of)     for i := 0 to length(fbuffer) -1 do fbuffer[i] := 0.0;          Sf_read_float(HandleSF, @fbuffer[0], alength ) ; // read data    Pa_WriteStream(HandlePA, @fbuffer[0], alength) ; // write dataend; But if fbuffer is a public variable, the sound is scratchy and bad. Here procedure with bad sound: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i varfbuffer: array of float;... Procedure ThreadLoopProc();vari : integer;beginwhile something dobegin    setlength(fbuffer,1000);      // clean buffer (not needed but in case of)     for i := 0 to length(fbuffer) -1 do fbuffer[i] := 0.0;          Sf_read_float(HandleSF, @fbuffer[0], alength ) ; // read data    Pa_WriteStream(HandlePA, @fbuffer[0], alength) ; // write dataend;  Why is the result different if fbuffer is inside or outside the procedure? Thanks. Fre;D ---------------------------------------------------------------------- Fred vS · 2021-02-08 17:14 Hello. I find a solution to the scratchy sound. But I dont understand why it does the trick. In previous code, changing:  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fbuffer: array of float;with  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fbuffer: array of single; makes sound good even if the array is a global variable.  Why a array of float gives problems as global variable and array of single not? Strange. Fre;D ---------------------------------------------------------------------- MarkMLl · 2021-02-08 17:23 Wild guess: is "float" giving you an alignment exception on your hardware (whatever it is :-) which has to be handled by the OS (whatever it is :-) ? MarkMLl ---------------------------------------------------------------------- Fred vS · 2021-02-08 17:57 Quote from: MarkMLl on February 08, 2021, 06:23:29 pmWild guess: is "float" giving you an alignment exception on your hardware (whatever it is :-) which has to be handled by the OS (whatever it is :-) ? MarkMLl Yes, maybe. Fre;D ---------------------------------------------------------------------- winni · 2021-02-08 19:03 H Fred! * What OS??? * What is the definition of float? And where is it defined?? Winni ---------------------------------------------------------------------- Fred vS · 2021-02-08 22:49 Hello Winni. Quote from: winni on February 08, 2021, 08:03:34 pm* What OS  Linux 64 bit. Quote from: winni on February 08, 2021, 08:03:34 pm* What is the definition of float? And where is it defined?? Not sure to understand, float is defined by fpc, like single. This is not really important because single fixed perfectly the problem and I dont really need float in fact, single is ok. Fre;D ---------------------------------------------------------------------- winni · 2021-02-08 23:02 Hi! float is not defined in the system unit. I know some apps where one of the first type deinition is like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Type float = single; or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Type float = double; That is often used when the developers are not quiete shure which precision ist needed. So: Which float do you use? CTypes? Winni ---------------------------------------------------------------------- winni · 2021-02-08 23:17 Quote from: jamie on February 09, 2021, 12:06:19 am The math unit states that it produces the largest Float type the target handles basically.. That's why I asked. Allways trouble when some foreign definitions have to be mimiced. Winni ---------------------------------------------------------------------- wp · 2021-02-08 23:42 Quote from: Fred vS on February 08, 2021, 03:49:57 pmBut if fbuffer is a public variable, the sound is scratchy and bad. Here procedure with bad sound: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i varfbuffer: array of float;... Procedure ThreadLoopProc();vari : integer;beginwhile something dobegin    setlength(fbuffer,1000);      // clean buffer (not needed but in case of)     for i := 0 to length(fbuffer) -1 do fbuffer[i] := 0.0;          Sf_read_float(HandleSF, @fbuffer[0], alength ) ; // read data    Pa_WriteStream(HandlePA, @fbuffer[0], alength) ; // write dataend;Fred, is the fbuffer declared in the same unit in which it is used by ThreadLoopProc? If not the types indeed could be different. Suppose that this is one of your sound projects, and a sound units declares float as single (in fact, BASS does this). Unit math, on the other hand, declares float as "extended". So, when the unit which declares fbuffer uses"math", but the unit withThreadLoopProc uses the sound unit, then the representation of "float" will be different. ---------------------------------------------------------------------- Fred vS · 2021-02-09 02:49 Hello everybody. It is a project done with msegui widget. OK, I checked and float is declared in msetypes as float = float64. So, it seems to be a msegui issue. Anyway, with single all works as expected. @Wp: Indeed array of float to link with a library: libsndfile.    It is strange because with uos all the code use float without any problem, even if the array comes from outside, but in uos float comes from ctypes. So I think you touched something. @Winni: Yes you did touch something, it seems that there is a conflict between float from msetypes and float from ctypes. @Jamie: Yes, there is a conflict between 2 different float. Anyway, thanks to everybody for your bright light (and I will no more use float  ). Fre;D ---------------------------------------------------------------------- Blaazen · 2021-02-09 03:00 Fred, it looks like PortAudio, and it uses ctypes unit. You can use type "cfloat" which should work fine. ---------------------------------------------------------------------- PascalDragon · 2021-02-09 08:12 Quote from: Fred vS on February 09, 2021, 03:49:46 amIt is strange because with uos all the code use float without any problem, even if the array comes from outside, but in uos float comes from ctypes. So I think you touched something. The ctypes unit does not provide a float alias, it provides a cfloat alias. So your float alias must come from somewhere else. ---------------------------------------------------------------------- Fred vS · 2021-02-09 12:11 Quote from: Blaazen on February 09, 2021, 04:00:09 amFred, it looks like PortAudio, and it uses ctypes unit. You can use type "cfloat" which should work fine. Hello Blaazen. Yes, it is for PortAudio, libSndFile and mpg123. For uos it uses cfloat from the beginning, without any trouble. It is the relation between cfloat of ctypes and float of msegui, that is not optimal. But with cfloat and single from fpc, it is ok. Thanks. ---------------------------------------------------------------------- Fred vS · 2021-02-09 12:12 Quote from: PascalDragon on February 09, 2021, 09:12:20 amQuote from: Fred vS on February 09, 2021, 03:49:46 amIt is strange because with uos all the code use float without any problem, even if the array comes from outside, but in uos float comes from ctypes. So I think you touched something. The ctypes unit does not provide a float alias, it provides a cfloat alias. So your float alias must come from somewhere else. Yes, like explained before float comes from msegui type. Thanks.