Version
menu_open
link
Wwise SDK 2023.1.4
AkBytesMem.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Copyright (c) 2024 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 // AkBytesMem.h
28 
29 /// \file
30 /// IReadBytes / IWriteBytes implementation on a growing memory buffer. This
31 /// version uses the AK::MemoryMgr allocator.
32 
33 #pragma once
34 
35 #include <AK/IBytes.h>
38 
39 namespace AK
40 {
42  : public AK::IReadBytes
43  {
44  public:
45 
48  const void * in_pBytes,
49  AkInt32 in_cBytes
50  );
52 
53  // IReadBytes implementation
54 
56  void * in_pData,
57  AkInt32 in_cBytes,
58  AkInt32 & out_cRead
59  );
60 
61  // Public methods
62 
64  const void * in_pBytes,
65  AkInt32 in_cBytes
66  );
67 
68  private:
69  AkInt32 m_cBytes;
70  const AkUInt8 * m_pBytes;
71 
72  AkInt32 m_cPos;
73  };
74 
76  : public AK::IWriteBuffer
77  {
78  public:
79 
82 
83  // IWriteBytes implementation
84 
86  const void * in_pData,
87  AkInt32 in_cBytes,
88  AkInt32& out_cWritten);
89 
90  // IWriteBuffer implementation
91 
92  AKSOUNDENGINE_API virtual bool Reserve(
93  AkInt32 in_cBytes
94  );
95 
96  AKSOUNDENGINE_API virtual AkInt32 Count() const;
97 
99  AkInt32 in_cBytes
100  );
101 
103 
104  AKSOUNDENGINE_API virtual AkUInt8 * Bytes() const;
105 
107 
108  AKSOUNDENGINE_API virtual void Clear();
109 
110  // Public methods
111 
113 
115 
116  // Reserves space for writing in_cBytes and returns the location, advancing the write pointer.
118  {
119  AkInt32 cPos = m_cPos;
120  AkInt32 cNewPos = cPos + in_cBytes;
121 
122  if ((m_cBytes >= cNewPos) || Grow(cNewPos))
123  {
124  m_cPos = cNewPos;
125  return m_pBytes + cPos;
126  }
127  else
128  return nullptr;
129  }
130 
131  template<class T>
133  {
134  static_assert(alignof(T) == 1, "T must have an alignment of 1 to avoid crashes due to unaligned writes on 32-bit ARM targets. Use Write<T> instead.");
135  return reinterpret_cast<T*>(GetWritePtr(sizeof(T)));
136  }
137 
138  template<class T>
139  bool Write(const T & in_data)
140  {
141  if (AkUInt8* pWrite = GetWritePtr(sizeof(T)))
142  {
143  AK::WriteUnaligned<T>(pWrite, in_data);
144  return true;
145  }
146  else
147  return false;
148  }
149 
150  private:
151  bool Grow(
152  AkInt32 in_cBytes
153  );
154 
155  AkInt32 m_cBytes;
156  AkUInt8 * m_pBytes;
157 
158  AkInt32 m_cPos;
159 
160  AkMemPoolId m_pool;
161  };
162 
164  : public AK::IWriteBytes
165  {
166  public:
167 
169 
171 
172  AKSOUNDENGINE_API void SetBuffer(AkUInt8* in_pBytes, AkInt32 in_cSize);
173 
174  // IWriteBytes implementation
175 
177  const void* in_pData,
178  AkInt32 in_cBytes,
179  AkInt32& out_cWritten);
180 
182 
184 
185  private:
186 
187  AkUInt8* m_pBytes;
188  AkInt32 m_cSize;
189  AkInt32 m_cPos;
190  };
191 }
virtual bool Reserve(AkInt32 in_cBytes)
Audiokinetic namespace.
void Attach(const void *in_pBytes, AkInt32 in_cBytes)
virtual AkUInt8 * Detach()
Return pointer to buffer and clear internal pointer.
virtual ~ReadBytesMem()
AkInt32 AkMemPoolId
Memory pool ID.
Definition: AkTypes.h:62
uint8_t AkUInt8
Unsigned 8-bit integer.
virtual bool WriteBytes(const void *in_pData, AkInt32 in_cBytes, AkInt32 &out_cWritten)
int32_t AkInt32
Signed 32-bit integer.
#define AKSOUNDENGINE_API
bool Write(const T &in_data)
Definition: AkBytesMem.h:139
virtual ~WriteBytesBuffer()
AkInt32 GetPos() const
void SetBuffer(AkUInt8 *in_pBytes, AkInt32 in_cSize)
ReadBytesMem(const void *in_pBytes, AkInt32 in_cBytes)
virtual void SetCount(AkInt32 in_cBytes)
Set number of bytes written.
AkInt32 Size() const
virtual ~WriteBytesMem()
virtual AkUInt8 * Bytes() const
virtual AkInt32 Count() const
virtual bool ReadBytes(void *in_pData, AkInt32 in_cBytes, AkInt32 &out_cRead)
virtual bool WriteBytes(const void *in_pData, AkInt32 in_cBytes, AkInt32 &out_cWritten)
virtual void Clear()
Clear the buffer contents.
void SetMemPool(AkMemPoolId in_pool)
AkUInt8 * GetWritePtr(AkInt32 in_cBytes)
Definition: AkBytesMem.h:117

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise