kwave  18.07.70
Kwave::SampleArray::SampleStorage Class Reference
Inheritance diagram for Kwave::SampleArray::SampleStorage:
Inheritance graph
Collaboration diagram for Kwave::SampleArray::SampleStorage:
Collaboration graph

Public Member Functions

 SampleStorage ()
 
 SampleStorage (const SampleStorage &other)
 
virtual ~SampleStorage ()
 
void resize (unsigned int size)
 

Public Attributes

unsigned int m_size
 
sample_tm_data
 
sample_tm_raw_data
 

Detailed Description

Definition at line 122 of file SampleArray.h.

Constructor & Destructor Documentation

◆ SampleStorage() [1/2]

Kwave::SampleArray::SampleStorage::SampleStorage ( )

default constructor

Definition at line 127 of file SampleArray.cpp.

References m_data, m_raw_data, and m_size.

128  :QSharedData()
129 {
130  m_size = 0;
131  m_data = Q_NULLPTR;
132  m_raw_data = Q_NULLPTR;
133 }

◆ SampleStorage() [2/2]

Kwave::SampleArray::SampleStorage::SampleStorage ( const SampleStorage other)

copy constructor

Definition at line 136 of file SampleArray.cpp.

References m_data, m_raw_data, m_size, and MEMCPY.

137  :QSharedData(other)
138 {
139  m_size = 0;
140  m_data = Q_NULLPTR;
141  m_raw_data = Q_NULLPTR;
142  Q_ASSERT(other.m_raw_data == Q_NULLPTR);
143 
144  if (other.m_size) {
145  m_data = static_cast<sample_t *>(
146  ::malloc(other.m_size * sizeof(sample_t))
147  );
148  if (m_data) {
149  m_size = other.m_size;
150  MEMCPY(m_data,
151  (other.m_raw_data) ? other.m_raw_data : other.m_data,
152  m_size * sizeof(sample_t)
153  );
154  }
155  }
156 }
#define MEMCPY
Definition: memcpy.h:37
qint32 sample_t
Definition: Sample.h:37

◆ ~SampleStorage()

Kwave::SampleArray::SampleStorage::~SampleStorage ( )
virtual

destructor

Definition at line 159 of file SampleArray.cpp.

References m_data, and m_raw_data.

160 {
161  Q_ASSERT(m_raw_data == Q_NULLPTR);
162  if (m_data) ::free(m_data);
163 }

Member Function Documentation

◆ resize()

void Kwave::SampleArray::SampleStorage::resize ( unsigned int  size)

Resizes the array. Using raw data mode is not allowed and will lead to an assert!

Parameters
sizenew number of samples

Definition at line 166 of file SampleArray.cpp.

References m_data, m_raw_data, m_size, and Kwave::SampleArray::size().

167 {
168  Q_ASSERT(m_raw_data == Q_NULLPTR);
169 
170  if (size) {
171  // resize using realloc, keep existing data
172  sample_t *new_data = static_cast<sample_t *>(
173  ::realloc(m_data, size * sizeof(sample_t)));
174  if (new_data) {
175  // successful
176  // NOTE: if we grew, the additional memory is *not* initialized!
177  m_data = new_data;
178  m_size = size;
179  } else {
180  qWarning("Kwave::SampleArray::SampleStorage::resize(%u): OOM! "
181  "- keeping old size %u", size, m_size);
182  }
183  } else {
184  // resize to zero == delete/free memory
185  Q_ASSERT(m_data);
186  ::free(m_data);
187  m_data = Q_NULLPTR;
188  m_size = 0;
189  }
190 }
unsigned int size() const
qint32 sample_t
Definition: Sample.h:37
Here is the call graph for this function:

Member Data Documentation

◆ m_data

sample_t* Kwave::SampleArray::SampleStorage::m_data

pointer to the area with the samples (allocated)

Definition at line 146 of file SampleArray.h.

Referenced by resize(), SampleStorage(), and ~SampleStorage().

◆ m_raw_data

sample_t* Kwave::SampleArray::SampleStorage::m_raw_data

pointer to some raw data that has been set

Definition at line 149 of file SampleArray.h.

Referenced by resize(), SampleStorage(), and ~SampleStorage().

◆ m_size

unsigned int Kwave::SampleArray::SampleStorage::m_size

size in samples

Definition at line 143 of file SampleArray.h.

Referenced by resize(), and SampleStorage().


The documentation for this class was generated from the following files: