FactoryXCode / MfPack

Delphi translations for Microsoft Media Foundation and related API's
Mozilla Public License 2.0
80 stars 22 forks source link

Wrong translation WinApi.DirectX.XAudio2.XAudio2 #21

Closed AndrewBJ closed 2 years ago

AndrewBJ commented 2 years ago

Unit WinApi.DirectX.XAudio2.XAudio2:417

The problem of field XAUDIO2_VOICE_SENDS.pSends. It should be Pointer, not a static array

https://docs.microsoft.com/en-us/windows/win32/api/xaudio2/ns-xaudio2-xaudio2_voice_sends

typedef struct XAUDIO2_VOICE_SENDS {
  UINT32                  SendCount;
  XAUDIO2_SEND_DESCRIPTOR *pSends; // <<----
} XAUDIO2_VOICE_SENDS;

Proposed changes:


@@ -409,6 +409,7 @@
   {$EXTERNALSYM XAUDIO2_SEND_DESCRIPTOR}
   // If you don't want to use pointer array's
   TXAudio2SendDescriptor = array [0..65535] of XAUDIO2_SEND_DESCRIPTOR;
+  PXAudio2SendDescriptor = ^TXAudio2SendDescriptor;
   {$EXTERNALSYM TXAudio2SendDescriptor}

   // Used in the voice creation functions and in IXAudio2Voice.SetOutputVoices
@@ -415,7 +416,7 @@
   PXAUDIO2_VOICE_SENDS = ^XAUDIO2_VOICE_SENDS;
   XAUDIO2_VOICE_SENDS = record
     SendCount: UINT32;                  // Number of sends from this voice.
-    pSends: TXAudio2SendDescriptor;     // PXAUDIO2_SEND_DESCRIPTOR;   // Array of SendCount send descriptors.
+    pSends: PXAudio2SendDescriptor;     // PXAUDIO2_SEND_DESCRIPTOR;   // Array of SendCount send descriptors.
   end;

XAUDIO2_EFFECT_CHAIN has the same problem

FactoryXCode commented 2 years ago

Thank you. I updated the following files:

Tony.

AndrewBJ commented 2 years ago

A few more places in XAudio2:

Line 405:

  XAUDIO2_SEND_DESCRIPTOR = record
    Flags: UINT32;                   // Either 0 or XAUDIO2_SEND_USEFILTER.
    pOutputVoice: PIXAudio2Voice;          // <<--- Should be IXAudio2Voice
  end;

Line 608:

    function CreateSourceVoice(out ppSourceVoice: IXAudio2SourceVoice;
                               pSourceFormat: PWAVEFORMATEX;     // <<--- Should be PWAVEFORMATEX

Line 690:

    procedure SetDebugConfiguration(pDebugConfiguration: XAUDIO2_DEBUG_CONFIGURATION; // <<--- Should be PXAUDIO2_DEBUG_CONFIGURATION
                                    pReserved: Pointer = nil); stdcall;

Line 747 (class IXAudio2Voice):

754:
procedure GetVoiceDetails(out pVoiceDetails: XAUDIO2_VOICE_DETAILS); virtual; stdcall; abstract; // <<--- Skipped <out>

762:
function SetOutputVoices(pSendList: XAUDIO2_VOICE_SENDS): HRESULT; virtual; stdcall; abstract; // <<--- PXAUDIO2_VOICE_SENDS

769:
function SetEffectChain(pEffectChain: XAUDIO2_EFFECT_CHAIN): HRESULT; virtual; stdcall; abstract; <<--- PXAUDIO2_EFFECT_CHAIN

833:
function SetFilterParameters(pParameters: XAUDIO2_FILTER_PARAMETERS; // <<--- PXAUDIO2_FILTER_PARAMETERS

850:
function SetOutputFilterParameters(pDestinationVoice: IXAudio2Voice;
                                       pParameters: XAUDIO2_FILTER_PARAMETERS; // <<--- PXAUDIO2_FILTER_PARAMETERS

Line 984:

    function SubmitSourceBuffer(pBuffer: XAUDIO2_BUFFER; // <<--- PXAUDIO2_BUFFER
AndrewBJ commented 2 years ago

Thanks a lot for fixing sources. But there are the new wrong translations occurs: Any "out" parameter must be a static type in the code. "out" already send it by pointer.

for example PType=^TType (param: PType) and (out param: TType) are equivalent

I hope that the next fixes will be the last

754: GetVoiceDetails(out pVoiceDetails: XAUDIO2_VOICE_DETAILS) // not PXAUDIO2_VOICE_DETAILS because used "out"

841: GetFilterParameters(out pParameters: XAUDIO2_FILTER_PARAMETERS)

861: procedure GetOutputFilterParameters(pDestinationVoice: IXAudio2Voice; out pParameters: XAUDIO2_FILTER_PARAMETERS); virtual; stdcall; abstract;

FactoryXCode commented 2 years ago

Thanks a lot for fixing sources. But there are the new wrong translations occurs: Any "out" parameter must be a static type in the code. "out" already send it by pointer.

for example PType=^TType (param: PType) and (out param: TType) are equivalent

I hope that the next fixes will be the last

754: GetVoiceDetails(out pVoiceDetails: XAUDIO2_VOICE_DETAILS) // not PXAUDIO2_VOICE_DETAILS because used "out"

841: GetFilterParameters(out pParameters: XAUDIO2_FILTER_PARAMETERS)

861: procedure GetOutputFilterParameters(pDestinationVoice: IXAudio2Voice; out pParameters: XAUDIO2_FILTER_PARAMETERS); virtual; stdcall; abstract;

I hope so too. thank you!

FactoryXCode commented 2 years ago

Any "out" parameter must be a static type in the code. "out" already send it by pointer.

I Know, but not always. When the annotation is [out] followed by a pointer, [out] is commented out as {out} . Some times it's confusing to translate C++ pointers to Delphi equivalents, because Delphi treats params as pointers internally. That's why in the original code static arrays were implemented as an option if a developer doesn't want to get involved with pointers. An interesting article about this is published by Rudi Velthuis Pitfalls of converting. We tested this behavior within different Api's, and it works. As a purist I would go for pointer use, but it's not really necessary as has been tested with compilers since XE2.

Greetings, Tony.

FactoryXCode commented 2 years ago

The classes in XAudio2 should be interfaced, as has been done in the latest update.