Re: [fpc-pascal] (Unix) serial port handling

2011-03-09 Thread Mark Morgan Lloyd

greim wrote:

Hi Mark,


Can anybody say whether there is a good reason that serial.pp lacks a
function to read the CD signal?

i would recommend the synaser library, more sophisticated then the 
serial.pp


http://www.ararat.cz/synapse/doku.php/download


I know you would. There are cases where it is not appropriate, for 
example when one needs to enqueue no only the received character but 
also a timestamp plus the instantaneous values of the control signals.



there is a function getCarrier, i guess this is what you need.

If you are working on a ARM system you have to modify some lines in 
synaser. Please check my previous messages.


Thanks, noted.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] (Unix) serial port handling

2011-03-09 Thread Henry Vermaak

On 08/03/11 10:30, Mark Morgan Lloyd wrote:

Can anybody say whether there is a good reason that serial.pp lacks a
function to read the CD signal?

Is SerFlush, which calls fpfsync, intended to discard input data, output
data or both?


fsync just makes sure all the in-kernel caches are written to the 
device.  Flushing input data is just a matter of reading it.


Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] (Unix) serial port handling

2011-03-09 Thread Mark Morgan Lloyd

Henry Vermaak wrote:

On 08/03/11 10:30, Mark Morgan Lloyd wrote:

Can anybody say whether there is a good reason that serial.pp lacks a
function to read the CD signal?

Is SerFlush, which calls fpfsync, intended to discard input data, output
data or both?


fsync just makes sure all the in-kernel caches are written to the 
device.  Flushing input data is just a matter of reading it.


Thanks for that Henry. Obviously there's scope for confusion here with 
the kernel's tcflush() and tcdrain() functions, where tcflush discards 
input and/or output data.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] (Unix) serial port handling

2011-03-09 Thread Marco van de Voort
In our previous episode, Mark Morgan Lloyd said:
> > fsync just makes sure all the in-kernel caches are written to the 
> > device.  Flushing input data is just a matter of reading it.
> 
> Thanks for that Henry. Obviously there's scope for confusion here with 
> the kernel's tcflush() and tcdrain() functions, where tcflush discards 
> input and/or output data.

(For *nix, implementations of that are in unit termio)

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] (Unix) serial port handling

2011-03-09 Thread Henry Vermaak

On 09/03/11 11:30, Mark Morgan Lloyd wrote:

Henry Vermaak wrote:

On 08/03/11 10:30, Mark Morgan Lloyd wrote:

Can anybody say whether there is a good reason that serial.pp lacks a
function to read the CD signal?

Is SerFlush, which calls fpfsync, intended to discard input data, output
data or both?


fsync just makes sure all the in-kernel caches are written to the
device. Flushing input data is just a matter of reading it.


Thanks for that Henry. Obviously there's scope for confusion here with
the kernel's tcflush() and tcdrain() functions, where tcflush discards
input and/or output data.


You're right.  Thinking about it, I don't know what the use of an fsync 
is in SerFlush, since you still don't know if it's been transmitted. 
I'd consider this a bug, SerFlush should use tcdrain.


Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Converting .m4a to .wav

2011-03-09 Thread Leonardo M . Ramé
Hi, does anyone knows if there's a library/class/function to handle .m4a 
(IPhone sound files)? also, if it allows conversion to other formats, such as 
.wav?

Thanks in advance,
Leonardo M. Ramé
http://leonardorame.blogspot.com



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting .m4a to .wav

2011-03-09 Thread Jonas Maebe


On 09 Mar 2011, at 13:52, Leonardo M. Ramé wrote:

Hi, does anyone knows if there's a library/class/function to  
handle .m4a (IPhone sound files)?


m4a is a plain mp4 container with an aac-encoded soundtrack (and no  
video). There is nothing iPhone-specific about it. Any library that  
can handle mp4 containers and the aac audio codec will do (such as  
ffmpeg).



Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] (Unix) serial port handling

2011-03-09 Thread Mark Morgan Lloyd

Henry Vermaak wrote:

On 09/03/11 11:30, Mark Morgan Lloyd wrote:

Henry Vermaak wrote:

On 08/03/11 10:30, Mark Morgan Lloyd wrote:

Can anybody say whether there is a good reason that serial.pp lacks a
function to read the CD signal?

Is SerFlush, which calls fpfsync, intended to discard input data, 
output

data or both?


fsync just makes sure all the in-kernel caches are written to the
device. Flushing input data is just a matter of reading it.


Thanks for that Henry. Obviously there's scope for confusion here with
the kernel's tcflush() and tcdrain() functions, where tcflush discards
input and/or output data.


You're right.  Thinking about it, I don't know what the use of an fsync 
is in SerFlush, since you still don't know if it's been transmitted. I'd 
consider this a bug, SerFlush should use tcdrain.


I was using this to communicate with an HP instrument a few weeks ago, 
so have my own re-implementation of some of the stuff. I'll look at 
doing a patch, preparatory to seeing if I can hack a complementary 
Win-32 equivalent.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting .m4a to .wav

2011-03-09 Thread Matt Emson

On 09/03/2011 12:52, Leonardo M. Ramé wrote:

Hi, does anyone knows if there's a library/class/function to handle .m4a 
(IPhone sound files)? also, if it allows conversion to other formats, such as 
.wav?


m4a is basically aac, so I'd look down that route. However, m4a files 
can be protected by DRM, and those files will be much harder, maybe even 
impossible, to convert. Though, I believe the extension becomes m4p when 
protected, and also m4b when an audio book. The format is much richer 
than MP3 or WAV as it can contain meta data such as notes, images and 
chapter markers. You'll lose these when converting.


M
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting .m4a to .wav

2011-03-09 Thread Leonardo M . Ramé
--- On Wed, 3/9/11, Matt Emson  wrote:

> From: Matt Emson 
> Subject: Re: [fpc-pascal] Converting .m4a to .wav
> To: "FPC-Pascal users discussions" 
> Date: Wednesday, March 9, 2011, 1:08 PM
> On 09/03/2011 12:52, Leonardo M.
> Ramé wrote:
> > Hi, does anyone knows if there's a
> library/class/function to handle .m4a (IPhone sound files)?
> also, if it allows conversion to other formats, such as
> .wav?
> 
> m4a is basically aac, so I'd look down that route. However,
> m4a files can be protected by DRM, and those files will be
> much harder, maybe even impossible, to convert. Though, I
> believe the extension becomes m4p when protected, and also
> m4b when an audio book. The format is much richer than MP3
> or WAV as it can contain meta data such as notes, images and
> chapter markers. You'll lose these when converting.
> 
> M

Thanks, I tested a sample file sent by my customer, and it was easy to convert 
with mplayer using this command:

mplayer -ao pcm test.m4a -ao pcm:file="output.wav" 

As mplayer uses ffmpeg library I'm sure I can use it from fpc.

Leonardo M. Ramé
http://leonardorame.blogspot.com




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting 32bit intel asm to Pascal or 64bit at&t asm

2011-03-09 Thread Andrew Haines
On 03/08/11 19:58, Andrew Haines wrote:
> Hi,
> 
> I'm trying to convert the following 32bit asm to pascal so it's
> portable. Also to 64bit asm.
> 
> It's from ACS audio component suite.
> 
> What am I doing wrong?
> 

For anyone who's interested I fixed the 64bit assembly version which is
good enough for me but I had hoped to write pascal code for the function.

I converted the intel32 asm to att32 asm which showed my first problem
"FDIVP" on intel becomes "FDIVRP" but on att it stays the same which
causes a different result. Beyond that, there wern't many problems. I
had some fun wondering why the RCX register wasn't a reasonable value
until I realized I was copying 64bits from a 32bit variable.

The following is my result. The 32bit and 64bit asm work but the pascal
still does not. Any suggestions are welcome.

 procedure LgMagnitude(InData : PACSComplex; OutData : PDouble;
DataSize, Shift : Integer);
  {$IFDEF CPUI386}
  var
LogBase  : Double;
  begin
asm
FLD1;
FLDL2T;
FDIVrP;
FSTPQ LogBase;
MOVL DataSize, %ecx;
MOVL OutData, %edi;
MOVL InData, %esi;
  .Ltest:   DEC %ecx
JZ .Lout;
FLDQ (%esi);
FMULQ %ST(0), %ST(0);
ADDL $8, %esi;
FLDQ (%esi);
FMULQ %ST(0), %ST(0);
FADDP;
FSQRTQ;
FTSTQ;
FSTSW %AX;

SAHF;
JE .Lskip;

FLDQ LogBase;
FXCH;
FYL2X;
FIADDL Shift;
FTSTQ;
FSTSW %AX;

SAHF;
JAE .Lskip;

FSTPQ (%edi);
FLDZ;
  .Lskip:
ADDL $8, %esi;
FSTPQ (%edi);
ADDL $8, %edi;
JMP .Ltest;
  .Lout: ;
end;
  end;
  {$ELSE} {$IFDEF CPUX86_64}
  var
LogBase  : Double;
  begin
SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
exOverflow, exUnderflow, exPrecision]);
asm
FLD1;
FLDL2T;
FDIVrP;
FSTPQ   LogBase;
MOV DataSize, %ecx;
MOV OutData,  %rdi;
MOV InData,   %rsi;
  .Ltest:   DEC %ecx
JZ .Lout;
FLDL(%rsi);
FMUL%ST(0),   %ST(0);
ADD $8,   %rsi;
FLDL(%rsi);
FMUL%ST(0),   %ST(0);
FADDP;
FSQRT;
FTST;
FSTSW   %AX;

// SAHF is not available on all x86_64 processors so
this is the workaround
bt  $14,  %ax; // // copy fpu C3 flag to cpu
carry flag
JC .Lskip;

FLD LogBase;
FXCH;
FYL2X;
FIADDL  Shift;
FTST;
FSTSW   %AX;

// SAHF is not available on all x86_64 processors so
this is the workaround
bt  $8,%ax // copy fpu C0 flag to cpu carry flag
JNC .Lskip

FSTPL   (%rdi);
FLDZ;
  .Lskip:
ADDL$8,%rsi;
FSTPL   (%rdi);
ADDL$8,%rdi;
JMP .Ltest;
  .Lout: ;
end;
  end;
  {$ELSE}
  {$ERROR LgMagnitude Unimplemented}
  // the following is not correct but was my best effort at pascalizing
the asm code
  var
LogBase  : Double;
i: Integer;
Im, Re: Double;
Tmp: Double;
  begin
asm
  FLD1;
  FLDL2T;
  FDIVRP;
  FSTP LogBase;
end;
for i := 0 to DataSize-1 do
begin
  Im := InData[i].Im*InData[i].Im;
  Re := InData[i].Re*InData[i].Re;
  Tmp := sqr(Im+Re);

  if Tmp <> Im then
  begin
//Tmp := ln(Tmp)*LogBase+Shift; // same as the following asm proc?
asm
  FLD LogBase;
  FLD Tmp;
  FYL2X;
  FIADD Shift;
  FSTP Tmp;
end;
if Tmp <> 0.0 then
begin
  if 0.0 >= Tmp then
  begin
Tmp := 0;
  end;
end;
  end;
  OutData[i] := Tmp;
end;
  end;
  {$ENDIF CPUX86_64}
  {$ENDIF CPUI386}
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting 32bit intel asm to Pascal or 64bit at&t asm

2011-03-09 Thread Thomas Schatzl

Hi,

On Wed, 09 Mar 2011 11:58:08 -0500, Andrew Haines wrote:

  if Tmp <> Im then
  begin
//Tmp := ln(Tmp)*LogBase+Shift; // same as the following asm 
proc?

asm
  FLD LogBase;
  FLD Tmp;
  FYL2X;


FYL2X calculates the log to the base 2 of tmp, not log to the base e of 
tmp? Just a guess.


Thomas

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting 32bit intel asm to Pascal or 64bit at&t asm

2011-03-09 Thread Andrew Haines
On 03/09/11 12:26, Thomas Schatzl wrote:
> Hi,
> 
> On Wed, 09 Mar 2011 11:58:08 -0500, Andrew Haines wrote:
>>   if Tmp <> Im then
>>   begin
>> //Tmp := ln(Tmp)*LogBase+Shift; // same as the following asm
>> proc?
>> asm
>>   FLD LogBase;
>>   FLD Tmp;
>>   FYL2X;
> 
> FYL2X calculates the log to the base 2 of tmp, not log to the base e of
> tmp? Just a guess.
> 
> Thomas
> 

I originally used log2(Tmp) but switched to ln to check if it was
correct. Thanks for noticing that, I changed it back to log2.

The current output with the pascal code looks like it did when FLDS was
used instead of FLDL to load (%rdi). The intel code was "FLD QWORD[EDI]"
I changed this to "FLDQ (%edi)". on x32 it became FLDL and on x64 it
became FLDS. changing the line to "FLDL (%rdi)" on x86_64 fixed the last
problem I had with the asm translation.

It's all very confusing. Is fldl loading a 32bit floating number? The
variable at (%rdi) is a double. flds makes me think it's loading a single.

Andrew

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Converting 32bit intel asm to Pascal or 64bit at&t asm

2011-03-09 Thread Thomas Schatzl

On Wed, 09 Mar 2011 13:23:55 -0500, Andrew Haines wrote:

On 03/09/11 12:26, Thomas Schatzl wrote:

Hi,

On Wed, 09 Mar 2011 11:58:08 -0500, Andrew Haines wrote:

  if Tmp <> Im then
  begin
//Tmp := ln(Tmp)*LogBase+Shift; // same as the following 
asm

proc?
asm
  FLD LogBase;
  FLD Tmp;
  FYL2X;


FYL2X calculates the log to the base 2 of tmp, not log to the base e 
of

tmp? Just a guess.

Thomas



I originally used log2(Tmp) but switched to ln to check if it was
correct. Thanks for noticing that, I changed it back to log2.

The current output with the pascal code looks like it did when FLDS 
was
used instead of FLDL to load (%rdi). The intel code was "FLD 
QWORD[EDI]"

I changed this to "FLDQ (%edi)". on x32 it became FLDL and on x64 it
became FLDS. changing the line to "FLDL (%rdi)" on x86_64 fixed the 
last

problem I had with the asm translation.


Suffixes for gas for floating point are (from 
http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax)


-s 32 bit/single
-l 64 bit/double
-t 80 bit/extended

With Intel syntax you can only hope that the compiler guesses 
correctly, or add an explicit override.


So you suggest that the assembler changes an inlined "fldq (%edi)" into 
"flds (%edi)" on x86-64? This looks like a bug if true - it should 
reject the "q" suffix for floating point operations.
At least gas 2.19 on solaris x64 rejects "fldq"; actually the 2.4.2 
release compiler transforms "fldq" into "fld" here, which gas rejects 
too :)


I will write a bug report.

Thomas

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal