2nd attempt at updated Waves audio backend, with added -fms-extensions as previously...
[ardour.git] / libs / backends / wavesaudio / wavesapi / BasicTypes / WUComPtr.h
1 #ifndef __WUComPtr_h__
2 #define __WUComPtr_h__
3         
4 /* Copy to include
5 #include "BasicTypes/WUComPtr.h"
6 */
7
8 #include "WavesPublicAPI/wstdint.h"
9
10 typedef int32_t wvComPtr[2]; 
11
12 // ConvertDPtr has the exact format of a vfp callback function, but it is a local function, native only.
13 // It converts a pointer in either 32 bits or 64 bits to a place-holder of 64 bits in coefs/states/external memory.
14 // pData is expected to point to a pre-allocate space enough for storing a pointer (posibly two single-precision coefs).
15 // Since pointers are not transferable between hardwares, at preset time no need for a shell callback.
16 // We keep this as a cALGORITHM for compatibility with the rest of the convert functions
17 //================================================================================
18 inline uint32_t vfpConvertDPtr(const void* InPointer, void* pData)
19 //================================================================================
20 {       
21     uint64_t *pL = (uint64_t *)pData;
22     *pL = (uint64_t)InPointer;
23     return (uint32_t)sizeof(uint64_t);
24 }
25
26
27 /*
28 {
29         // data in that struct must be the same type of the Coefs/States type!
30         int32_t LSW; // Least significant word
31         int32_t MSW; // Most  significant word
32 };
33
34 inline wvComPtr PackToComPtr(const intptr_t in_PtrToPack)
35 // take ptr that hosted in intptr_t type
36 // and pack it to wvComPtr container type (MSW and LSW of 32bit each)
37 {
38         wvComPtr retVal;
39         int64_t t_PtrToPack = static_cast<int64_t>(in_PtrToPack);
40         // This packing is xPlatform coding for x32 and x64
41         // #ifdef for x64 - intptr_t is 64 bit
42         retVal.LSW = static_cast<int32_t>(t_PtrToPack & intptr_t(0xFFFFFFFF));
43         retVal.MSW = (static_cast<int32_t>(t_PtrToPack>>32));
44
45         // #ifdef for x32 - intptr_t is 32 bit
46 //      retVal.LSW = int32_t(in_PtrToPack);
47 //      retVal.MSW = 0;
48         
49         return retVal;
50 }
51
52 inline intptr_t UnpackComPtr( const wvComPtr in_ComPtrToUnpack)
53 // take wvComPtr with MSW and LSW of 32bit each
54 // and unpack it to intptr_t type
55 {
56         intptr_t retVal;
57         
58         // This unpacking is xPlatform coding for x32 and x64
59         // #ifdef for x64 - intptr_t is 64 bit so use intptr_t instead of int64_t
60         int64_t PtrAt64 = static_cast<int64_t>(in_ComPtrToUnpack.MSW);
61         PtrAt64 <<= 32;
62         PtrAt64 |= static_cast<int64_t>(in_ComPtrToUnpack.LSW);
63         retVal = static_cast<intptr_t>(PtrAt64);
64
65
66         // #ifdef for x32 - intptr_t is 32 bit
67 //      retVal = static_cast<intptr_t>(retVal.LSW);
68
69         return retVal;
70 }
71
72
73 //////////////////////////////////////////////////////////////////////////
74 inline uint32_t  ComPtr_to_DSP( const intptr_t PtrToConvert, char* pDataStruct )
75 {
76
77         *(reinterpret_cast<wvComPtr *>(pDataStruct)) = PackToComPtr(PtrToConvert);
78
79         return uint32_t(sizeof(wvComPtr));
80 }
81 //////////////////////////////////////////////////////////////////////////
82
83 //////////////////////////////////////////////////////////////////////////
84 inline uint32_t  DSP_to_ComPtr( const char* pDataStruct, intptr_t *ThePtr)
85 // pDataStruct is pointing to wvComPtr in the Coefs/States
86 // the function reconstruct the pointer into ThePtr 
87 {
88
89         *ThePtr = UnpackComPtr(*(reinterpret_cast<const wvComPtr *>(pDataStruct)));
90
91         return uint32_t(sizeof(wvComPtr));
92 }
93 //////////////////////////////////////////////////////////////////////////
94 */
95
96 #endif //#if !defined(__WUComPtr_h__)
97
98
99