2 Copyright (C) 2014 Waves Audio Ltd.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __WUComPtr_h__
21 #define __WUComPtr_h__
24 #include "BasicTypes/WUComPtr.h"
27 #include "WavesPublicAPI/wstdint.h"
29 typedef int32_t wvComPtr[2];
31 // ConvertDPtr has the exact format of a vfp callback function, but it is a local function, native only.
32 // It converts a pointer in either 32 bits or 64 bits to a place-holder of 64 bits in coefs/states/external memory.
33 // pData is expected to point to a pre-allocate space enough for storing a pointer (posibly two single-precision coefs).
34 // Since pointers are not transferable between hardwares, at preset time no need for a shell callback.
35 // We keep this as a cALGORITHM for compatibility with the rest of the convert functions
36 //================================================================================
37 inline uint32_t vfpConvertDPtr(const void* InPointer, void* pData)
38 //================================================================================
40 uint64_t *pL = (uint64_t *)pData;
41 *pL = (uint64_t)InPointer;
42 return (uint32_t)sizeof(uint64_t);
48 // data in that struct must be the same type of the Coefs/States type!
49 int32_t LSW; // Least significant word
50 int32_t MSW; // Most significant word
53 inline wvComPtr PackToComPtr(const intptr_t in_PtrToPack)
54 // take ptr that hosted in intptr_t type
55 // and pack it to wvComPtr container type (MSW and LSW of 32bit each)
58 int64_t t_PtrToPack = static_cast<int64_t>(in_PtrToPack);
59 // This packing is xPlatform coding for x32 and x64
60 // #ifdef for x64 - intptr_t is 64 bit
61 retVal.LSW = static_cast<int32_t>(t_PtrToPack & intptr_t(0xFFFFFFFF));
62 retVal.MSW = (static_cast<int32_t>(t_PtrToPack>>32));
64 // #ifdef for x32 - intptr_t is 32 bit
65 // retVal.LSW = int32_t(in_PtrToPack);
71 inline intptr_t UnpackComPtr( const wvComPtr in_ComPtrToUnpack)
72 // take wvComPtr with MSW and LSW of 32bit each
73 // and unpack it to intptr_t type
77 // This unpacking is xPlatform coding for x32 and x64
78 // #ifdef for x64 - intptr_t is 64 bit so use intptr_t instead of int64_t
79 int64_t PtrAt64 = static_cast<int64_t>(in_ComPtrToUnpack.MSW);
81 PtrAt64 |= static_cast<int64_t>(in_ComPtrToUnpack.LSW);
82 retVal = static_cast<intptr_t>(PtrAt64);
85 // #ifdef for x32 - intptr_t is 32 bit
86 // retVal = static_cast<intptr_t>(retVal.LSW);
92 //////////////////////////////////////////////////////////////////////////
93 inline uint32_t ComPtr_to_DSP( const intptr_t PtrToConvert, char* pDataStruct )
96 *(reinterpret_cast<wvComPtr *>(pDataStruct)) = PackToComPtr(PtrToConvert);
98 return uint32_t(sizeof(wvComPtr));
100 //////////////////////////////////////////////////////////////////////////
102 //////////////////////////////////////////////////////////////////////////
103 inline uint32_t DSP_to_ComPtr( const char* pDataStruct, intptr_t *ThePtr)
104 // pDataStruct is pointing to wvComPtr in the Coefs/States
105 // the function reconstruct the pointer into ThePtr
108 *ThePtr = UnpackComPtr(*(reinterpret_cast<const wvComPtr *>(pDataStruct)));
110 return uint32_t(sizeof(wvComPtr));
112 //////////////////////////////////////////////////////////////////////////
115 #endif //#if !defined(__WUComPtr_h__)