kwave  18.07.70
Kwave::Stripe Class Reference

#include <Stripe.h>

Collaboration diagram for Kwave::Stripe:
Collaboration graph

Classes

class  List
 
class  MappedArray
 
class  StripeStorage
 

Public Member Functions

 Stripe ()
 
 Stripe (const Stripe &other)
 
 Stripe (sample_index_t start)
 
 Stripe (sample_index_t start, const Kwave::SampleArray &samples)
 
 Stripe (sample_index_t start, Stripe &stripe, unsigned int offset)
 
virtual ~Stripe ()
 
sample_index_t start () const
 
void setStart (sample_index_t start)
 
unsigned int length () const
 
sample_index_t end () const
 
unsigned int resize (unsigned int length, bool initialize=true)
 
unsigned int append (const Kwave::SampleArray &samples, unsigned int offset, unsigned int count)
 
void deleteRange (unsigned int offset, unsigned int length)
 
void overwrite (unsigned int offset, const Kwave::SampleArray &source, unsigned int srcoff, unsigned int srclen)
 
bool combine (unsigned int offset, Kwave::Stripe &other)
 
unsigned int read (Kwave::SampleArray &buffer, unsigned int dstoff, unsigned int offset, unsigned int length)
 
void minMax (unsigned int first, unsigned int last, sample_t &min, sample_t &max)
 
Stripeoperator<< (const Kwave::SampleArray &samples)
 
bool operator== (const Stripe &other) const
 
Stripeoperator= (const Stripe &other)
 

Private Member Functions

unsigned int resizeStorage (unsigned int length)
 
sample_tmapStorage ()
 
void unmapStorage ()
 

Private Attributes

QMutex m_lock
 
QExplicitlySharedDataPointer< StripeStoragem_data
 

Detailed Description

Definition at line 35 of file Stripe.h.

Constructor & Destructor Documentation

◆ Stripe() [1/5]

Kwave::Stripe::Stripe ( )

Default constructor. Creates an empty stripe with zero-length.

Definition at line 204 of file Stripe.cpp.

205  :m_lock(), m_data(new(std::nothrow) StripeStorage)
206 {
207 }
QMutex m_lock
Definition: Stripe.h:355
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358

◆ Stripe() [2/5]

Kwave::Stripe::Stripe ( const Stripe other)

Copy constructor

Definition at line 210 of file Stripe.cpp.

References m_data.

211  :m_lock(), m_data(Q_NULLPTR)
212 {
213  m_data = other.m_data;
214 }
QMutex m_lock
Definition: Stripe.h:355
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358

◆ Stripe() [3/5]

Kwave::Stripe::Stripe ( sample_index_t  start)

Constructor. Creates a new zero-length stripe.

Parameters
startposition within the track

Definition at line 217 of file Stripe.cpp.

References m_data, and start().

218  :m_lock(), m_data(new(std::nothrow) StripeStorage)
219 {
220  if (m_data) m_data->m_start = start;
221 }
sample_index_t start() const
Definition: Stripe.cpp:262
QMutex m_lock
Definition: Stripe.h:355
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:

◆ Stripe() [4/5]

Kwave::Stripe::Stripe ( sample_index_t  start,
const Kwave::SampleArray samples 
)

Constructor. Creates a stripe that already contains samples, copied from a buffer with samples.

Parameters
startposition within the track
samplesarray with initial samples

Definition at line 224 of file Stripe.cpp.

References append(), m_data, Kwave::SampleArray::size(), and start().

225  :m_lock(), m_data(new(std::nothrow) StripeStorage)
226 {
227  if (m_data) m_data->m_start = start;
228  if (samples.size()) append(samples, 0, samples.size());
229 }
unsigned int append(const Kwave::SampleArray &samples, unsigned int offset, unsigned int count)
Definition: Stripe.cpp:381
sample_index_t start() const
Definition: Stripe.cpp:262
QMutex m_lock
Definition: Stripe.h:355
unsigned int size() const
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:

◆ Stripe() [5/5]

Kwave::Stripe::Stripe ( sample_index_t  start,
Kwave::Stripe stripe,
unsigned int  offset 
)

Constructor. Creates a stripe that already contains samples, copied from another stripe with offset.

Parameters
startposition within the track
stripesource stripe to copy from
offsetoffset within the source stripe

Definition at line 232 of file Stripe.cpp.

References Kwave::SampleArray::data(), length(), m_data, read(), resize(), resizeStorage(), and start().

235  :m_lock(), m_data(new(std::nothrow) StripeStorage)
236 {
237  if (!m_data) return;
238 
239  m_data->m_start = start;
240 
241  Q_ASSERT(offset < stripe.length());
242  if (offset >= stripe.length()) return;
243 
244  unsigned int length = stripe.length() - offset;
245  if (resizeStorage(length) != length) return; // out of memory
246 
247  if (length) {
248  MappedArray _samples(*this);
249  Q_ASSERT(_samples.data());
250  if (!_samples.data()) return; // OOM
251  if (!stripe.read(_samples, 0, offset, length)) resize(0);
252  }
253 }
unsigned int length() const
Definition: Stripe.cpp:276
unsigned int read(Kwave::SampleArray &buffer, unsigned int dstoff, unsigned int offset, unsigned int length)
Definition: Stripe.cpp:502
unsigned int resizeStorage(unsigned int length)
Definition: Stripe.cpp:289
unsigned int resize(unsigned int length, bool initialize=true)
Definition: Stripe.cpp:339
sample_index_t start() const
Definition: Stripe.cpp:262
QMutex m_lock
Definition: Stripe.h:355
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:

◆ ~Stripe()

Kwave::Stripe::~Stripe ( )
virtual

Destructor.

Definition at line 256 of file Stripe.cpp.

References m_lock.

257 {
258  QMutexLocker lock(&m_lock);
259 }
QMutex m_lock
Definition: Stripe.h:355

Member Function Documentation

◆ append()

unsigned int Kwave::Stripe::append ( const Kwave::SampleArray samples,
unsigned int  offset,
unsigned int  count 
)

Appends an array of samples to the end of the stripe.

Parameters
samplesarray with the samples
offsetthe offset within the array
countnumber of samples in the array
Returns
number of samples appended

Definition at line 381 of file Stripe.cpp.

References Kwave::MemoryManager::instance(), m_data, m_lock, resizeStorage(), Kwave::SampleArray::size(), and Kwave::MemoryManager::writeTo().

Referenced by Kwave::Track::appendAfter(), operator<<(), and Stripe().

384 {
385  if (!count) return 0; // nothing to do
386  Q_ASSERT(offset + count <= samples.size());
387  if (offset + count > samples.size()) return 0;
388 
389 // qDebug("Stripe::append: adding %d samples", count);
390  QMutexLocker lock(&m_lock);
391  m_data.detach();
392  if (!m_data) return 0; // OOM when detaching
393 
394  unsigned int old_length = m_data->m_length;
395  unsigned int new_length = old_length + count;
396  Q_ASSERT(!m_data->mapCount());
397  if (resizeStorage(new_length) != new_length)
398  return 0; // out of memory
399 
400  // append to the end of the area
401  unsigned int cnt = new_length - old_length;
402  Q_ASSERT(!m_data->mapCount());
403  int bytes_appended = Kwave::MemoryManager::instance().writeTo(
404  m_data->m_storage,
405  old_length * sizeof(sample_t),
406  &(samples[offset]), cnt * sizeof(sample_t)
407  );
408 
409 // qDebug("Stripe::append(): resized to %d", m_length);
410  return (bytes_appended > 0) ? (bytes_appended / sizeof(sample_t)) : 0;
411 }
static MemoryManager & instance() Q_DECL_EXPORT
unsigned int resizeStorage(unsigned int length)
Definition: Stripe.cpp:289
QMutex m_lock
Definition: Stripe.h:355
unsigned int size() const
int writeTo(Kwave::Handle handle, unsigned int offset, const void *buffer, unsigned int length) Q_DECL_EXPORT
qint32 sample_t
Definition: Sample.h:37
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ combine()

bool Kwave::Stripe::combine ( unsigned int  offset,
Kwave::Stripe other 
)

Combine this stripe with another stripe

Parameters
offsetthe offset within this stripe to put the other stripe
otherreference to another stripe
Returns
true if succeeded or false if failed (e.g. out of memory)

Definition at line 457 of file Stripe.cpp.

References Kwave::SampleArray::constData(), Kwave::SampleArray::data(), length(), m_data, m_lock, MEMCPY, resizeStorage(), and Kwave::SampleArray::size().

Referenced by Kwave::Track::defragment().

458 {
459  QMutexLocker lock(&m_lock);
460  m_data.detach();
461  if (!m_data) return false; // OOM when detaching
462 
463  if (m_data->mapCount()) return false; // data is mapped
464 
465  const unsigned int old_len = m_data->m_length;
466  const unsigned int combined_len = offset + other.length();
467  if (old_len < combined_len) {
468  // resize the storage if necessary
469  if (resizeStorage(combined_len) != combined_len)
470  return false; // resizing failed, maybe OOM ?
471  }
472 
473  // copy the data from the other stripe
474  MappedArray _src(other);
475  MappedArray _dst(*this);
476  const sample_t *src = _src.constData();
477  sample_t *dst = _dst.data();
478  unsigned int len = _src.size() * sizeof(sample_t);
479  if (!src || !dst) return false; // mmap of src or dst failed
480 
481  MEMCPY(dst + offset, src, len);
482 
483  return true;
484 }
unsigned int length() const
Definition: Stripe.cpp:276
unsigned int resizeStorage(unsigned int length)
Definition: Stripe.cpp:289
QMutex m_lock
Definition: Stripe.h:355
#define MEMCPY
Definition: memcpy.h:37
qint32 sample_t
Definition: Sample.h:37
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteRange()

void Kwave::Stripe::deleteRange ( unsigned int  offset,
unsigned int  length 
)

Deletes a range of samples

Parameters
offsetindex of the first sample, relative to the start of the stripe [0...length()-1]
lengthnumber of samples

Definition at line 414 of file Stripe.cpp.

References Kwave::Stripe::MappedArray::copy(), m_data, m_lock, and resizeStorage().

Referenced by Kwave::Track::stripes(), and Kwave::Track::unlockedDelete().

415 {
416 // qDebug(" Stripe::deleteRange(offset=%u, length=%u)", offset, length);
417  if (!length) return; // nothing to do
418 
419  QMutexLocker lock(&m_lock);
420  m_data.detach();
421  if (!m_data) return; // OOM when detaching
422 
423  const unsigned int size = m_data->m_length;
424  if (!size) return;
425 
426  unsigned int first = offset;
427  unsigned int last = offset + length - 1;
428 // qDebug(" Stripe::deleteRange, me=[%u ... %u] del=[%u ... %u]",
429 // m_start, m_start+size-1, m_start + first, m_start + last);
430 
431  Q_ASSERT(first < size);
432  if (first >= size) return;
433 
434  // put first/last into our area
435  if (last >= size) last = size - 1;
436  Q_ASSERT(last >= first);
437  if (last < first) return;
438 
439  // move all samples after the deleted area to the left
440  unsigned int dst = first;
441  unsigned int src = last+1;
442  unsigned int len = size - src;
443 // qDebug(" Stripe: deleting %u ... %u", dst, src-1);
444  if (len) {
445  MappedArray _samples(*this);
446 
447  Q_ASSERT(src + len <= size);
448  Q_ASSERT(dst + len <= size);
449  if (!_samples.copy(dst, src, len)) return;
450  }
451 
452  // resize the buffer to it's new size
453  resizeStorage(size - length);
454 }
unsigned int length() const
Definition: Stripe.cpp:276
unsigned int resizeStorage(unsigned int length)
Definition: Stripe.cpp:289
QMutex m_lock
Definition: Stripe.h:355
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

sample_index_t Kwave::Stripe::end ( ) const

Returns the position of the last sample of the stripe, same as (start() + length() ? (length() - 1))

Definition at line 282 of file Stripe.cpp.

References m_data.

Referenced by Kwave::Track::appendAfter(), Kwave::Track::defragment(), Kwave::Track::dump(), Kwave::Track::insertSpace(), Kwave::Track::mergeStripe(), Kwave::SampleReader::minMax(), operator==(), Kwave::SampleReader::readSamples(), Kwave::DebugPlugin::run(), Kwave::Track::stripes(), Kwave::Track::unlockedDelete(), and Kwave::Track::writeSamples().

283 {
284  return (m_data) ? (m_data->m_start +
285  ((m_data->m_length) ? (m_data->m_length - 1) : 0)) : 0;
286 }
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the caller graph for this function:

◆ length()

unsigned int Kwave::Stripe::length ( ) const

◆ mapStorage()

sample_t * Kwave::Stripe::mapStorage ( )
private

maps the storage into memory

Definition at line 601 of file Stripe.cpp.

References m_data.

Referenced by Kwave::Stripe::MappedArray::MappedArray().

602 {
603  return (m_data) ? m_data->map() : Q_NULLPTR;
604 }
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the caller graph for this function:

◆ minMax()

void Kwave::Stripe::minMax ( unsigned int  first,
unsigned int  last,
sample_t min,
sample_t max 
)

Returns the minimum and maximum sample value within a range of samples.

Parameters
firstindex of the first sample
lastindex of the last sample
minreceives the lowest value (must be initialized)
maxreceives the highest value (must be initialized)

Definition at line 537 of file Stripe.cpp.

References Kwave::SampleArray::constData(), m_data, and m_lock.

Referenced by Kwave::SampleReader::minMax().

539 {
540  QMutexLocker lock(&m_lock);
541  if (!m_data) return;
542 
543  MappedArray _samples(*this);
544  const sample_t *buffer = _samples.constData();
545  if (!buffer) return;
546 
547  // loop over the mapped storage to get min/max
548  sample_t lo = min;
549  sample_t hi = max;
550  Q_ASSERT(first < m_data->m_length);
551  Q_ASSERT(first <= last);
552  Q_ASSERT(last < m_data->m_length);
553  buffer += first;
554  unsigned int remaining = last - first + 1;
555 
556  // speedup: process a block of 8 samples at once, to allow loop unrolling
557  const unsigned int block = 8;
558  while (Q_LIKELY(remaining >= block)) {
559  for (unsigned int count = 0; Q_LIKELY(count < block); count++) {
560  sample_t s = *(buffer++);
561  if (Q_UNLIKELY(s < lo)) lo = s;
562  if (Q_UNLIKELY(s > hi)) hi = s;
563  }
564  remaining -= block;
565  }
566  while (Q_LIKELY(remaining)) {
567  sample_t s = *(buffer++);
568  if (Q_UNLIKELY(s < lo)) lo = s;
569  if (Q_UNLIKELY(s > hi)) hi = s;
570  remaining--;
571  }
572  min = lo;
573  max = hi;
574 }
QMutex m_lock
Definition: Stripe.h:355
qint32 sample_t
Definition: Sample.h:37
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<()

Kwave::Stripe & Kwave::Stripe::operator<< ( const Kwave::SampleArray samples)

Operator for appending an array of samples to the end of the stripe.

Definition at line 577 of file Stripe.cpp.

References append(), and Kwave::SampleArray::size().

578 {
579  unsigned int appended = append(samples, 0, samples.size());
580  if (appended != samples.size()) {
581  qWarning("Stripe::operator << FAILED");
582  }
583  return *this;
584 }
unsigned int append(const Kwave::SampleArray &samples, unsigned int offset, unsigned int count)
Definition: Stripe.cpp:381
unsigned int size() const
Here is the call graph for this function:

◆ operator=()

Kwave::Stripe & Kwave::Stripe::operator= ( const Stripe other)

assignment operator

Definition at line 594 of file Stripe.cpp.

References m_data.

595 {
596  m_data = other.m_data;
597  return *this;
598 }
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358

◆ operator==()

bool Kwave::Stripe::operator== ( const Stripe other) const

compare operator

Definition at line 587 of file Stripe.cpp.

References end(), and start().

588 {
589  return ((start() == other.start()) &&
590  (end() == other.end()));
591 }
sample_index_t start() const
Definition: Stripe.cpp:262
sample_index_t end() const
Definition: Stripe.cpp:282
Here is the call graph for this function:

◆ overwrite()

void Kwave::Stripe::overwrite ( unsigned int  offset,
const Kwave::SampleArray source,
unsigned int  srcoff,
unsigned int  srclen 
)

Copies the content of an array of samples into the stripe.

Parameters
offsetthe offset within the stripe (target)
sourcearray of samples to be copied
srcoffoffset within the source array
srclenlength of the data in the source array
Warning
this method is intended to be used only internally and lacks any error-checking in order to be fast!

Definition at line 487 of file Stripe.cpp.

References Kwave::MemoryManager::instance(), m_data, m_lock, and Kwave::MemoryManager::writeTo().

490 {
491  QMutexLocker lock(&m_lock);
492  m_data.detach();
493  if (!m_data) return; // OOM when detaching
494 
495  Q_ASSERT(!m_data->mapCount());
497  offset * sizeof(sample_t),
498  &(source[srcoff]), srclen * sizeof(sample_t));
499 }
static MemoryManager & instance() Q_DECL_EXPORT
QMutex m_lock
Definition: Stripe.h:355
int writeTo(Kwave::Handle handle, unsigned int offset, const void *buffer, unsigned int length) Q_DECL_EXPORT
qint32 sample_t
Definition: Sample.h:37
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:

◆ read()

unsigned int Kwave::Stripe::read ( Kwave::SampleArray buffer,
unsigned int  dstoff,
unsigned int  offset,
unsigned int  length 
)

Reads out samples from the stripe into a buffer

Parameters
bufferarray for samples to be read (destination)
dstoffoffset within the destination buffer
offsetthe offset within the stripe (source)
lengthnumber of samples to read
Returns
number of samples read
Warning
this method is intended to be used only internally and lacks any error-checking in order to be fast!

Definition at line 502 of file Stripe.cpp.

References Kwave::MemoryManager::instance(), m_data, m_lock, and Kwave::MemoryManager::readFrom().

Referenced by Kwave::SampleReader::readSamples(), Stripe(), and Kwave::Stripe::StripeStorage::StripeStorage().

506 {
507  QMutexLocker lock(&m_lock);
508  if (!length || !m_data) return 0; // nothing to do !?
509 
510 // for (unsigned int x=dstoff; (dstoff+x < length) && (x < buffer.size()); x++)
511 // buffer[x] = -(SAMPLE_MAX >> 2);
512 
513 // qDebug("Stripe::read(), me=[%u ... %u] (size=%u), offset=%u, length=%u",
514 // m_start, m_start+m_length-1, m_length, offset, length);
515 
516  Q_ASSERT(offset < m_data->m_length);
517  if (offset >= m_data->m_length) return 0;
518  if ((offset + length) > m_data->m_length)
519  length = m_data->m_length - offset;
520  Q_ASSERT(length);
521 // if (!length) qDebug("--- [%u ... %u] (%u), offset=%u",
522 // m_start, m_start+m_length-1, m_length, offset);
523  if (!length) return 0;
524 
525  // read directly through the memory manager, fastest path
526  int bytes_read = Kwave::MemoryManager::instance().readFrom(
527  m_data->m_storage,
528  offset * sizeof(sample_t),
529  &buffer[dstoff], length * sizeof(sample_t)
530  );
531 
532 // qDebug("read done, length=%u", read_len);
533  return (bytes_read > 0) ? (bytes_read / sizeof(sample_t)) : 0;
534 }
unsigned int length() const
Definition: Stripe.cpp:276
int readFrom(Kwave::Handle handle, unsigned int offset, void *buffer, unsigned int length) Q_DECL_EXPORT
static MemoryManager & instance() Q_DECL_EXPORT
QMutex m_lock
Definition: Stripe.h:355
qint32 sample_t
Definition: Sample.h:37
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize()

unsigned int Kwave::Stripe::resize ( unsigned int  length,
bool  initialize = true 
)

Resizes the stripe to a new number of samples. If the array size is reduced, samples from the end are thrown away. If the size is increased, samples with zero value will be added to the end.

Parameters
lengthnew length of the array [samples]
initializeif true, initialize all new areas with zeroes if the size has been increased (default = true)
Returns
new length [samples]

Definition at line 339 of file Stripe.cpp.

References Kwave::SampleArray::data(), length(), m_data, m_lock, resizeStorage(), and Kwave::SampleArray::size().

Referenced by Kwave::Track::appendStripe(), Kwave::Track::insertSpace(), Kwave::Track::splitStripe(), Stripe(), Kwave::Track::stripes(), and Kwave::Track::Track().

340 {
341  QMutexLocker lock(&m_lock);
342  m_data.detach();
343  if (!m_data) return 0; // OOM when detaching
344 
345  unsigned int old_length = m_data->m_length;
346  if (m_data->m_length == length) return old_length; // nothing to do
347 
348 // qDebug("Stripe::resize() from %d to %d samples", old_length, length);
349  Q_ASSERT(!m_data->mapCount());
350  if (resizeStorage(length) != length) {
351  qWarning("Stripe::resize(%u) failed, out of memory ?", length);
352  return m_data->m_length;
353  }
354 
355  // fill new samples with zero
356  if (initialize && length) {
357  Q_ASSERT(!m_data->mapCount());
358  unsigned int pos = old_length;
359 
360 #ifdef STRICTLY_QT
361  MappedArray _samples(*this);
362  if (_samples.size() != m_data->m_length) return 0;
363 
364  while (pos < length) {
365  _samples[pos++] = 0;
366  }
367 #else
368  MappedArray _map(*this);
369  sample_t *samples = _map.data();
370  if (!samples) return 0;
371  if (pos < length) {
372  memset(&(samples[pos]), 0, (length - pos) * sizeof(sample_t));
373  }
374 #endif
375  }
376 
377  return length;
378 }
unsigned int length() const
Definition: Stripe.cpp:276
unsigned int resizeStorage(unsigned int length)
Definition: Stripe.cpp:289
QMutex m_lock
Definition: Stripe.h:355
qint32 sample_t
Definition: Sample.h:37
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resizeStorage()

unsigned int Kwave::Stripe::resizeStorage ( unsigned int  length)
private

Resizes the internal storage.

Parameters
lengththe new length in samples
Returns
the length after the resize operation. Should be equal to the length that has been given as parameter. If not, something has failed.
Note
called internally only, under lock. It is made sure that m_data is already detached and not null

Definition at line 289 of file Stripe.cpp.

References Kwave::MemoryManager::free(), Kwave::MemoryManager::instance(), length(), and m_data.

Referenced by append(), combine(), deleteRange(), resize(), and Stripe().

290 {
291  Q_ASSERT(m_data); // (just paranoia)
292 
293  if (m_data->m_length == length) return length; // nothing to do
294 // qDebug("Stripe::resizeStorage(%u)", length);
295 
296  // check: must not be mapped!
297  Q_ASSERT(!m_data->mapCount());
298  if (m_data->mapCount()) return m_data->m_length;
299 
301 
302  // special case: zero length means delete
303  if (length == 0) {
304  // delete the array
305  mem.free(m_data->m_storage);
306  m_data->m_storage = 0;
307  m_data->m_length = 0;
308  return 0;
309  }
310 
311  if (!m_data->m_length || !m_data->m_storage) {
312  // allocate new storage
313  Kwave::Handle new_storage = mem.allocate(length * sizeof(sample_t));
314  if (!new_storage) {
315  // allocation failed
316  qWarning("Stripe::resizeStorage(%u) failed! (1)", length);
317  return m_data->m_length;
318  }
319 
320  Q_ASSERT(!m_data->m_storage);
321  m_data->m_storage = new_storage;
322  m_data->m_length = length;
323  return length;
324  }
325 
326  // resize the array to another size
327  if (!mem.resize(m_data->m_storage, length * sizeof(sample_t))) {
328  // resize failed
329  qWarning("Stripe::resizeStorage(%u) failed! (2)", length);
330  return m_data->m_length;
331  }
332 
333  // succeeded
334  m_data->m_length = length;
335  return length;
336 }
unsigned int length() const
Definition: Stripe.cpp:276
static MemoryManager & instance() Q_DECL_EXPORT
void free(Kwave::Handle &handle) Q_DECL_EXPORT
int Handle
Definition: MemoryManager.h:34
qint32 sample_t
Definition: Sample.h:37
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setStart()

void Kwave::Stripe::setStart ( sample_index_t  start)

Sets a new start position for the stripe

Definition at line 268 of file Stripe.cpp.

References m_data, m_lock, and start().

Referenced by Kwave::Track::moveRight(), Kwave::Track::stripes(), and Kwave::Track::unlockedDelete().

269 {
270  QMutexLocker lock(&m_lock);
271  m_data.detach();
272  if (m_data) m_data->m_start = start;
273 }
sample_index_t start() const
Definition: Stripe.cpp:262
QMutex m_lock
Definition: Stripe.h:355
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start()

sample_index_t Kwave::Stripe::start ( ) const

Returns the start position of the stripe within the track.

Definition at line 262 of file Stripe.cpp.

References m_data.

Referenced by Kwave::Track::defragment(), Kwave::Track::dump(), Kwave::Track::insertSpace(), Kwave::Track::mergeStripe(), Kwave::SampleReader::minMax(), Kwave::Track::moveRight(), operator==(), Kwave::SampleReader::readSamples(), Kwave::DebugPlugin::run(), setStart(), Kwave::Track::splitStripe(), Stripe(), Kwave::Track::stripes(), Kwave::Track::unlockedDelete(), Kwave::Track::unlockedLength(), and Kwave::Track::writeSamples().

263 {
264  return (m_data) ? m_data->m_start : 0;
265 }
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the caller graph for this function:

◆ unmapStorage()

void Kwave::Stripe::unmapStorage ( )
private

unmaps the storage from memory

Definition at line 607 of file Stripe.cpp.

References m_data.

Referenced by Kwave::Stripe::MappedArray::~MappedArray().

608 {
609  if (m_data) m_data->unmap();
610 }
QExplicitlySharedDataPointer< StripeStorage > m_data
Definition: Stripe.h:358
Here is the caller graph for this function:

Member Data Documentation

◆ m_data

QExplicitlySharedDataPointer<StripeStorage> Kwave::Stripe::m_data
private

◆ m_lock

QMutex Kwave::Stripe::m_lock
private

mutex for locking map/unmap

Definition at line 355 of file Stripe.h.

Referenced by append(), combine(), deleteRange(), minMax(), overwrite(), read(), resize(), setStart(), and ~Stripe().


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