Link to home
Start Free TrialLog in
Avatar of jpdupont
jpdupont

asked on

How to translate from C to Delphi

I want to read a wav file in small buffers and to call a function in a DLL with this buffer. Here the sample code in C. How do this with Delphi ?
=========
FILE* essai=fopen("d:\\tri\\essai.wav","rb");

short buff[1024];
int count;
char answer[1024];
int number=1;
int dwarf;

        while ((count=fread(buff,2,1024,essai))>0)
        {
                BBTAsr_RecognizeBuffer16(asr, (short *)buff, count,
WRFMT_PCM16);
                if ( ((dwarf=BBTAsr_GetRecognizedString(asr,answer,1024)))==0)
                         fprintf(stderr,"Here :%s\n",answer);

        };
        BBTAsr_RecognizeBuffer16(asr,NULL,0,WRFMT_PCM16);

        answer[0] = '/0';
        fprintf(stdout,"%d %s %s\n",number,argv[1],answer);
fclose(essai);
=========
I want help to this part :
=====
        while ((count=fread(buff,2,1024,essai))>0)
        {
                BBTAsr_RecognizeBuffer16(asr, (short *)buff, count,
WRFMT_PCM16);
=====

The function is declared in a pas file :

  pSmallInt       = ^SmallInt;

function BBTAsr_RecognizeBuffer16(pAsr: LPASR; pData: pSmallInt; nb: integer; codingfmt: WRFMT_Coding): Integer; stdcall; external 'BabAsr.dll' name 'BBTAsr_RecognizeBuffer16';

Thanks for the help !

Jean-Pol
Avatar of Lischke
Lischke

Hi Jean-Pol,

here we go:

Count := Stream.Read(buff, 2048);
while Count > 0 do
begin
  BBTAsr_RecognizeBuffer16(asr, @buff, count, WRFMT_PCM16);
  :
  Count := Stream.Read(buff, 2048);
end;


Here I'd recommend that you use a file stream instead of the old style file handling. The value 2048 results from the fread call using 1024 items with an item size of 2 bytes.

Ciao, Mike
Avatar of jpdupont

ASKER

Mike,

thanks for the answer !

What's the type of "buff" ?

How translate :

short buff[1024]; ?

Jean-Pol
ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks !