summaryrefslogtreecommitdiff
path: root/libs/backends/wavesaudio/wavesapi/BasicTypes/WUComPtr.h
blob: e8e633d927fc31b2be4021d80d2d65029f1efed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
    Copyright (C) 2014 Waves Audio Ltd.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __WUComPtr_h__
#define __WUComPtr_h__

/* Copy to include
#include "BasicTypes/WUComPtr.h"
*/

#include "WavesPublicAPI/wstdint.h"

typedef int32_t wvComPtr[2];

// ConvertDPtr has the exact format of a vfp callback function, but it is a local function, native only.
// It converts a pointer in either 32 bits or 64 bits to a place-holder of 64 bits in coefs/states/external memory.
// pData is expected to point to a pre-allocate space enough for storing a pointer (posibly two single-precision coefs).
// Since pointers are not transferable between hardwares, at preset time no need for a shell callback.
// We keep this as a cALGORITHM for compatibility with the rest of the convert functions
//================================================================================
inline uint32_t vfpConvertDPtr(const void* InPointer, void* pData)
//================================================================================
{
    uint64_t *pL = (uint64_t *)pData;
    *pL = (uint64_t)InPointer;
    return (uint32_t)sizeof(uint64_t);
}


/*
{
	// data in that struct must be the same type of the Coefs/States type!
	int32_t LSW; // Least significant word
	int32_t MSW; // Most  significant word
};

inline wvComPtr PackToComPtr(const intptr_t in_PtrToPack)
// take ptr that hosted in intptr_t type
// and pack it to wvComPtr container type (MSW and LSW of 32bit each)
{
	wvComPtr retVal;
	int64_t t_PtrToPack = static_cast<int64_t>(in_PtrToPack);
	// This packing is xPlatform coding for x32 and x64
	// #ifdef for x64 - intptr_t is 64 bit
	retVal.LSW = static_cast<int32_t>(t_PtrToPack & intptr_t(0xFFFFFFFF));
	retVal.MSW = (static_cast<int32_t>(t_PtrToPack>>32));

	// #ifdef for x32 - intptr_t is 32 bit
//	retVal.LSW = int32_t(in_PtrToPack);
//	retVal.MSW = 0;

	return retVal;
}

inline intptr_t UnpackComPtr( const wvComPtr in_ComPtrToUnpack)
// take wvComPtr with MSW and LSW of 32bit each
// and unpack it to intptr_t type
{
	intptr_t retVal;

	// This unpacking is xPlatform coding for x32 and x64
	// #ifdef for x64 - intptr_t is 64 bit so use intptr_t instead of int64_t
	int64_t PtrAt64 = static_cast<int64_t>(in_ComPtrToUnpack.MSW);
	PtrAt64 <<= 32;
	PtrAt64	|= static_cast<int64_t>(in_ComPtrToUnpack.LSW);
	retVal = static_cast<intptr_t>(PtrAt64);


	// #ifdef for x32 - intptr_t is 32 bit
//	retVal = static_cast<intptr_t>(retVal.LSW);

	return retVal;
}


//////////////////////////////////////////////////////////////////////////
inline uint32_t  ComPtr_to_DSP( const intptr_t PtrToConvert, char* pDataStruct )
{

	*(reinterpret_cast<wvComPtr *>(pDataStruct)) = PackToComPtr(PtrToConvert);

	return uint32_t(sizeof(wvComPtr));
}
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
inline uint32_t  DSP_to_ComPtr( const char* pDataStruct, intptr_t *ThePtr)
// pDataStruct is pointing to wvComPtr in the Coefs/States
// the function reconstruct the pointer into ThePtr
{

	*ThePtr = UnpackComPtr(*(reinterpret_cast<const wvComPtr *>(pDataStruct)));

	return uint32_t(sizeof(wvComPtr));
}
//////////////////////////////////////////////////////////////////////////
*/

#endif //#if !defined(__WUComPtr_h__)