TFM_TheMask
22nd May 2006, 19:28
I'm trying to translate the Aud-X SDK Library to Delphi but I don't get it to work. Is there anyone with knowledge of C++ and Delphi that can help me.
Here is my translation of the header file:
unit AUDXLIB1;
interface
uses
{$IFDEF WIN32}
Windows;
{$ELSE}
Wintypes, WinProcs;
{$ENDIF}
{$IFNDEF AUDXLIB_H}
{$DEFINE AUDXLIB_H}
{$IFDEF __cplusplus }
{$ENDIF}
{///============================================================================ }
{///:::::::::::::::::::::::::::::::ENCODER:::::::::::::::::::::::::::::::::::::: }
{+//* }
{-* Initializes audx encoding }
{-* Input: }
{-* quality - values: 0 (STRQ 80 kbps), 1 (STDQ 128 kbps), 2 (HGHQ 192 kbps) or 3 (SPBQ 192 kbps) }
{-* Returns: }
{-* 0 - couldn't start new encoding process, }
{-* nonzero - handler of the newly initialized encoding process }
{= }
var
initEncoding: function(quality: Integer): LongInt cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{+//* }
{-* Encodes audx frame. }
{-* Input: }
{-* henc - handler of an encoding process, }
{-* pcm_block - input buffer containing pcm data to be encoded (must be nonNULL) with 6912 samples (1152 per each channel), }
{-* the interlaced channel order MUST be: [0: FL] [1: FR] [2: C] [3: LFE] [4: SL] [5: SR]. }
{-* Output: }
{-* audx_frame - output buffer filled with audx stream data }
{-* }
{-* Returns: }
{-* -1 - handler of an uninitialized encoding process, invalid input data or error in processing, }
{-* 0 - input data and processing correct - needs more input, }
{-* frameLength - frame length (in bytes) - the data int audx_frame can be consumed. }
{= }
var
encodeAudXframe: function(henc: LongInt;
var pcm_block: SmallInt;
var audx_frame: Byte): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{+//* }
{-* Flushing internal buffers. Should be called after all PCM input samples have been consumed. }
{-* Output: }
{-* henc - handler of an encoding process, }
{-* audx_frame - output buffer filled with audx stream data. }
{-* }
{-* Returns: }
{-* -1 - flushing finished - all internal buffers are empty and encoding process is reset }
{-* (henc is no longer a handler of the process), }
{-* or uninitialized encoding process, }
{-* 0 - flushing should be called once again - no output data produced, }
{-* frameLength - frame length (in bytes) - the data in audx_frame can be consumed. }
{= }
var
flushEncoder: function(henc: LongInt;
var audx_frame: Byte): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///============================================================================ }
{///============================================================================ }
{///:::::::::::::::::::::::::::::::DECODER:::::::::::::::::::::::::::::::::::::: }
{+//* }
{-* Initializes audx decoding }
{-* Input: }
{-* quality - values: 0 (STRQ 80 kbps), 1 (STDQ 128 kbps), 2 (HGHQ 192 kbps) or 3 (SPBQ 192 kbps) }
{-* Returns: }
{-* 0 - couldn't initilize ne decoding process }
{-* nonzero - handler of the newly initialized decoding process }
{= }
var
initDecoding: function: LongInt cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{+//* }
{-* Decodes audx/mp3 frame. }
{-* Input: }
{-* hdec - handler of a decoding process, }
{-* audx_frame - input buffer containing data to be decoded (must be nonNULL), }
{-* audx_frame_size - size of the input buffer in bytes (must be > 0) }
{-* }
{-* Output: }
{-* dec_pcm_block - output buffer filled with 16bits PCM samples (must be nonNULL) }
{-* dec_pcm_block_size - size of the output buffer in bytes (must be nonNULL) }
{-* is_audx - indicates whether input data contained an audx frame or regular mp3 (must be nonNULL) }
{-* }
{-* Returns: }
{-* -1 - handler of an uninitialized decoding process, invalid input data or error in processing, }
{-* 0 - input data and processing correct, input data was not consumed (should be supplied once again) }
{-* 1 - input data and processing correct, input data was consumed (new input portion can be supplied) }
{= }
var
decodeAudXframe: function(hdec: LongInt;
var audx_frame: array of char;
audx_frame_size: LongInt;
var dec_pcm_block: SmallInt;
var dec_pcm_block_size: LongInt;
var is_audx: Integer): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{+//* }
{-* Resets an initialized decoding process }
{-* (puts the process in a uninitialized state, hdec is no longer a handler of the process), }
{-* or does nothing if a decoding process is uninitialized }
{-* Input: }
{-* hdec - handler to a decoding process }
{= }
var
resetDecoder: procedure(hdec: LongInt) cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///============================================================================ }
{$IFDEF __cplusplus}
{$ENDIF}
{$ENDIF}
var
DLLLoaded: Boolean { is DLL (dynamically) loaded already? }
{$IFDEF WIN32} = False; {$ENDIF}
implementation
var
SaveExit: pointer;
DLLHandle: THandle;
{$IFNDEF MSDOS}
ErrorMode: Integer;
{$ENDIF}
procedure NewExit; far;
begin
ExitProc := SaveExit;
FreeLibrary(DLLHandle)
end {NewExit};
procedure LoadDLL;
begin
if DLLLoaded then Exit;
{$IFNDEF MSDOS}
ErrorMode := SetErrorMode($8000{SEM_NoOpenFileErrorBox});
{$ENDIF}
DLLHandle := LoadLibrary('AUDXLIB.DLL');
if DLLHandle >= 32 then
begin
DLLLoaded := True;
SaveExit := ExitProc;
ExitProc := @NewExit;
@initEncoding := GetProcAddress(DLLHandle,'initEncoding');
{$IFDEF WIN32}
Assert(@initEncoding <> nil);
{$ENDIF}
@encodeAudXframe := GetProcAddress(DLLHandle,'encodeAudXframe');
{$IFDEF WIN32}
Assert(@encodeAudXframe <> nil);
{$ENDIF}
@flushEncoder := GetProcAddress(DLLHandle,'flushEncoder');
{$IFDEF WIN32}
Assert(@flushEncoder <> nil);
{$ENDIF}
@initDecoding := GetProcAddress(DLLHandle,'initDecoding');
{$IFDEF WIN32}
Assert(@initDecoding <> nil);
{$ENDIF}
@decodeAudXframe := GetProcAddress(DLLHandle,'decodeAudXframe');
{$IFDEF WIN32}
Assert(@decodeAudXframe <> nil);
{$ENDIF}
@resetDecoder := GetProcAddress(DLLHandle,'resetDecoder');
{$IFDEF WIN32}
Assert(@resetDecoder <> nil);
{$ENDIF}
end
else
begin
DLLLoaded := False;
{ Error: AUDXLIB.DLL could not be loaded !! }
end;
{$IFNDEF MSDOS}
SetErrorMode(ErrorMode)
{$ENDIF}
end {LoadDLL};
begin
LoadDLL;
end.
And here is the sample program to get it to work. I am specially interested in de decoder functionality and the way to tell if the mp3 is Aud-X:
program TestAudX;
uses
AUDXLIB1 in 'AUDXLIB1.PAS',
Classes, SysUtils, dialogs;
var
Handle : THandle;
stream : TFileStream;
size : Longint;
Buffer: array [1..2048] of char;
IsAudX : integer;
mp3fill : longint;
pcm : smallint;
res : integer;
begin
IsAudX := 0;
mp3fill := 102400;
pcm := sizeof(mp3fill);
Handle := InitDecoding;
stream := TFileStream.Create('d:\audx.mp3', fmOpenReadWrite or fmShareDenyWrite);
Fillchar(Buffer, sizeof(Buffer), #0);
size := stream.Read(Buffer, sizeof(buffer));
res := decodeAudXframe(handle, buffer, size , pcm, mp3fill, IsAudX);
if (IsAudX = 1) then
showmessage('AudX');
Fillchar(Buffer, sizeof(Buffer), #0);
size := stream.Read(Buffer, sizeof(buffer));
ResetDecoder(handle);
end.
Here is my translation of the header file:
unit AUDXLIB1;
interface
uses
{$IFDEF WIN32}
Windows;
{$ELSE}
Wintypes, WinProcs;
{$ENDIF}
{$IFNDEF AUDXLIB_H}
{$DEFINE AUDXLIB_H}
{$IFDEF __cplusplus }
{$ENDIF}
{///============================================================================ }
{///:::::::::::::::::::::::::::::::ENCODER:::::::::::::::::::::::::::::::::::::: }
{+//* }
{-* Initializes audx encoding }
{-* Input: }
{-* quality - values: 0 (STRQ 80 kbps), 1 (STDQ 128 kbps), 2 (HGHQ 192 kbps) or 3 (SPBQ 192 kbps) }
{-* Returns: }
{-* 0 - couldn't start new encoding process, }
{-* nonzero - handler of the newly initialized encoding process }
{= }
var
initEncoding: function(quality: Integer): LongInt cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{+//* }
{-* Encodes audx frame. }
{-* Input: }
{-* henc - handler of an encoding process, }
{-* pcm_block - input buffer containing pcm data to be encoded (must be nonNULL) with 6912 samples (1152 per each channel), }
{-* the interlaced channel order MUST be: [0: FL] [1: FR] [2: C] [3: LFE] [4: SL] [5: SR]. }
{-* Output: }
{-* audx_frame - output buffer filled with audx stream data }
{-* }
{-* Returns: }
{-* -1 - handler of an uninitialized encoding process, invalid input data or error in processing, }
{-* 0 - input data and processing correct - needs more input, }
{-* frameLength - frame length (in bytes) - the data int audx_frame can be consumed. }
{= }
var
encodeAudXframe: function(henc: LongInt;
var pcm_block: SmallInt;
var audx_frame: Byte): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{+//* }
{-* Flushing internal buffers. Should be called after all PCM input samples have been consumed. }
{-* Output: }
{-* henc - handler of an encoding process, }
{-* audx_frame - output buffer filled with audx stream data. }
{-* }
{-* Returns: }
{-* -1 - flushing finished - all internal buffers are empty and encoding process is reset }
{-* (henc is no longer a handler of the process), }
{-* or uninitialized encoding process, }
{-* 0 - flushing should be called once again - no output data produced, }
{-* frameLength - frame length (in bytes) - the data in audx_frame can be consumed. }
{= }
var
flushEncoder: function(henc: LongInt;
var audx_frame: Byte): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///============================================================================ }
{///============================================================================ }
{///:::::::::::::::::::::::::::::::DECODER:::::::::::::::::::::::::::::::::::::: }
{+//* }
{-* Initializes audx decoding }
{-* Input: }
{-* quality - values: 0 (STRQ 80 kbps), 1 (STDQ 128 kbps), 2 (HGHQ 192 kbps) or 3 (SPBQ 192 kbps) }
{-* Returns: }
{-* 0 - couldn't initilize ne decoding process }
{-* nonzero - handler of the newly initialized decoding process }
{= }
var
initDecoding: function: LongInt cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{+//* }
{-* Decodes audx/mp3 frame. }
{-* Input: }
{-* hdec - handler of a decoding process, }
{-* audx_frame - input buffer containing data to be decoded (must be nonNULL), }
{-* audx_frame_size - size of the input buffer in bytes (must be > 0) }
{-* }
{-* Output: }
{-* dec_pcm_block - output buffer filled with 16bits PCM samples (must be nonNULL) }
{-* dec_pcm_block_size - size of the output buffer in bytes (must be nonNULL) }
{-* is_audx - indicates whether input data contained an audx frame or regular mp3 (must be nonNULL) }
{-* }
{-* Returns: }
{-* -1 - handler of an uninitialized decoding process, invalid input data or error in processing, }
{-* 0 - input data and processing correct, input data was not consumed (should be supplied once again) }
{-* 1 - input data and processing correct, input data was consumed (new input portion can be supplied) }
{= }
var
decodeAudXframe: function(hdec: LongInt;
var audx_frame: array of char;
audx_frame_size: LongInt;
var dec_pcm_block: SmallInt;
var dec_pcm_block_size: LongInt;
var is_audx: Integer): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{+//* }
{-* Resets an initialized decoding process }
{-* (puts the process in a uninitialized state, hdec is no longer a handler of the process), }
{-* or does nothing if a decoding process is uninitialized }
{-* Input: }
{-* hdec - handler to a decoding process }
{= }
var
resetDecoder: procedure(hdec: LongInt) cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///============================================================================ }
{$IFDEF __cplusplus}
{$ENDIF}
{$ENDIF}
var
DLLLoaded: Boolean { is DLL (dynamically) loaded already? }
{$IFDEF WIN32} = False; {$ENDIF}
implementation
var
SaveExit: pointer;
DLLHandle: THandle;
{$IFNDEF MSDOS}
ErrorMode: Integer;
{$ENDIF}
procedure NewExit; far;
begin
ExitProc := SaveExit;
FreeLibrary(DLLHandle)
end {NewExit};
procedure LoadDLL;
begin
if DLLLoaded then Exit;
{$IFNDEF MSDOS}
ErrorMode := SetErrorMode($8000{SEM_NoOpenFileErrorBox});
{$ENDIF}
DLLHandle := LoadLibrary('AUDXLIB.DLL');
if DLLHandle >= 32 then
begin
DLLLoaded := True;
SaveExit := ExitProc;
ExitProc := @NewExit;
@initEncoding := GetProcAddress(DLLHandle,'initEncoding');
{$IFDEF WIN32}
Assert(@initEncoding <> nil);
{$ENDIF}
@encodeAudXframe := GetProcAddress(DLLHandle,'encodeAudXframe');
{$IFDEF WIN32}
Assert(@encodeAudXframe <> nil);
{$ENDIF}
@flushEncoder := GetProcAddress(DLLHandle,'flushEncoder');
{$IFDEF WIN32}
Assert(@flushEncoder <> nil);
{$ENDIF}
@initDecoding := GetProcAddress(DLLHandle,'initDecoding');
{$IFDEF WIN32}
Assert(@initDecoding <> nil);
{$ENDIF}
@decodeAudXframe := GetProcAddress(DLLHandle,'decodeAudXframe');
{$IFDEF WIN32}
Assert(@decodeAudXframe <> nil);
{$ENDIF}
@resetDecoder := GetProcAddress(DLLHandle,'resetDecoder');
{$IFDEF WIN32}
Assert(@resetDecoder <> nil);
{$ENDIF}
end
else
begin
DLLLoaded := False;
{ Error: AUDXLIB.DLL could not be loaded !! }
end;
{$IFNDEF MSDOS}
SetErrorMode(ErrorMode)
{$ENDIF}
end {LoadDLL};
begin
LoadDLL;
end.
And here is the sample program to get it to work. I am specially interested in de decoder functionality and the way to tell if the mp3 is Aud-X:
program TestAudX;
uses
AUDXLIB1 in 'AUDXLIB1.PAS',
Classes, SysUtils, dialogs;
var
Handle : THandle;
stream : TFileStream;
size : Longint;
Buffer: array [1..2048] of char;
IsAudX : integer;
mp3fill : longint;
pcm : smallint;
res : integer;
begin
IsAudX := 0;
mp3fill := 102400;
pcm := sizeof(mp3fill);
Handle := InitDecoding;
stream := TFileStream.Create('d:\audx.mp3', fmOpenReadWrite or fmShareDenyWrite);
Fillchar(Buffer, sizeof(Buffer), #0);
size := stream.Read(Buffer, sizeof(buffer));
res := decodeAudXframe(handle, buffer, size , pcm, mp3fill, IsAudX);
if (IsAudX = 1) then
showmessage('AudX');
Fillchar(Buffer, sizeof(Buffer), #0);
size := stream.Read(Buffer, sizeof(buffer));
ResetDecoder(handle);
end.