kwave  18.07.70
Kwave::SampleArray Class Reference

#include <SampleArray.h>

Inheritance diagram for Kwave::SampleArray:
Inheritance graph
Collaboration diagram for Kwave::SampleArray:
Collaboration graph

Classes

class  SampleStorage
 

Public Member Functions

 SampleArray ()
 
 SampleArray (unsigned int size)
 
virtual ~SampleArray ()
 
const sample_tconstData () const
 
sample_tdata ()
 
void setRawData (sample_t *data, unsigned int size)
 
void resetRawData ()
 
void fill (sample_t value)
 
sample_toperator[] (unsigned int index)
 
const sample_toperator[] (unsigned int index) const
 
bool resize (unsigned int size) Q_REQUIRED_RESULT
 
unsigned int size () const
 
bool isEmpty () const
 

Private Attributes

QSharedDataPointer< SampleStoragem_storage
 

Detailed Description

array with sample_t, for use in KwaveSampleSource, KwaveSampleSink and other streaming classes.

Definition at line 36 of file SampleArray.h.

Constructor & Destructor Documentation

◆ SampleArray() [1/2]

Kwave::SampleArray::SampleArray ( )

Default constructor, creates an empty array

Definition at line 27 of file SampleArray.cpp.

References m_storage.

28 {
29  m_storage = new(std::nothrow) SampleStorage;
30 }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152

◆ SampleArray() [2/2]

Kwave::SampleArray::SampleArray ( unsigned int  size)
explicit

Constructor, creates an array with predefined size (not initialized)

Parameters
sizenumber of samples to hold

Definition at line 33 of file SampleArray.cpp.

References m_storage, and resize().

34 {
35  m_storage = new(std::nothrow) SampleStorage;
36  bool ok = resize(size);
37  if (!ok)
38  qWarning("Kwave::SampleArray::SampleArray(%u) - FAILED, OOM?", size);
39 }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
unsigned int size() const
bool resize(unsigned int size) Q_REQUIRED_RESULT
Here is the call graph for this function:

◆ ~SampleArray()

Kwave::SampleArray::~SampleArray ( )
virtual

Destructor

Definition at line 42 of file SampleArray.cpp.

43 {
44 }

Member Function Documentation

◆ constData()

const sample_t* Kwave::SampleArray::constData ( ) const
inline

returns a const pointer to the raw data (non-mutable)

Definition at line 54 of file SampleArray.h.

Referenced by Kwave::Stripe::combine(), Kwave::SampleEncoderLinear::encode(), Kwave::MP3Encoder::encode(), Kwave::VorbisEncoder::encode(), Kwave::SampleFIFO::get(), Kwave::SampleBuffer::get(), Kwave::RateConverter::input(), Kwave::Stripe::minMax(), Kwave::ChannelMixer::mix(), Kwave::Mul::multiply(), operator[](), and Kwave::PlayBackPulseAudio::write().

55  {
56  if (Q_UNLIKELY(!m_storage)) return Q_NULLPTR;
57  if (m_storage->m_raw_data) return m_storage->m_raw_data;
58  return m_storage->m_data;
59  }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
Here is the caller graph for this function:

◆ data()

sample_t* Kwave::SampleArray::data ( )
inline

returns a pointer to the raw data (mutable)

Definition at line 62 of file SampleArray.h.

Referenced by Kwave::Stripe::combine(), Kwave::SampleDecoderLinear::decode(), Kwave::FlacEncoder::encode(), fill(), Kwave::SampleFIFO::get(), Kwave::RateConverter::input(), Kwave::ChannelMixer::mix(), Kwave::Mul::multiply(), operator[](), Kwave::Stripe::resize(), Kwave::ReversePlugin::reverse(), setRawData(), Kwave::Stripe::Stripe(), and Kwave::FlacDecoder::write_callback().

63  {
64  if (Q_UNLIKELY(!m_storage)) return Q_NULLPTR;
65  if (m_storage->m_raw_data) return m_storage->m_raw_data;
66  return m_storage->m_data;
67  }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
Here is the caller graph for this function:

◆ fill()

void Kwave::SampleArray::fill ( sample_t  value)

fills the array with a sample value

Definition at line 68 of file SampleArray.cpp.

References data(), and m_storage.

Referenced by Kwave::ZeroPlugin::run(), and Kwave::DebugPlugin::run().

69 {
70  if (!m_storage) return;
71  sample_t *p = data();
72  Q_ASSERT(p);
73  if (!p) return;
74  for (unsigned int count = m_storage->m_size; Q_LIKELY(count); count--) {
75  *p = value;
76  p++;
77  }
78 }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
sample_t * data()
Definition: SampleArray.h:62
qint32 sample_t
Definition: Sample.h:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEmpty()

bool Kwave::SampleArray::isEmpty ( ) const
inline

Returns whether the array is empty. The same as (size() == 0).

Returns
true if empty, false if not

Definition at line 118 of file SampleArray.h.

Referenced by Kwave::SampleReader::fillBuffer(), Kwave::RateConverter::input(), Kwave::SampleBuffer::isEmpty(), and Kwave::SampleFIFO::put().

118 { return (size() == 0); }
unsigned int size() const
Here is the caller graph for this function:

◆ operator[]() [1/2]

sample_t & Kwave::SampleArray::operator[] ( unsigned int  index)

operator [], non-const.

Parameters
indexsample index [0...count()-1]
Returns
reference to the requested sample (read/write)

Definition at line 81 of file SampleArray.cpp.

References data().

82 {
83  static sample_t dummy = 0;
84  sample_t *p = data();
85 
86  if (Q_LIKELY(p))
87  return (*(p + index));
88  else
89  return dummy;
90 }
sample_t * data()
Definition: SampleArray.h:62
qint32 sample_t
Definition: Sample.h:37
Here is the call graph for this function:

◆ operator[]() [2/2]

const sample_t & Kwave::SampleArray::operator[] ( unsigned int  index) const

operator [], non-const.

Parameters
indexsample index [0...count()-1]
Returns
reference to the requested sample (read only)

Definition at line 93 of file SampleArray.cpp.

References constData().

94 {
95  static const sample_t dummy = 0;
96  const sample_t *p = constData();
97 
98  if (Q_LIKELY(p))
99  return (*(p + index));
100  else
101  return dummy;
102 }
const sample_t * constData() const
Definition: SampleArray.h:54
qint32 sample_t
Definition: Sample.h:37
Here is the call graph for this function:

◆ resetRawData()

void Kwave::SampleArray::resetRawData ( )

Resets the raw data set with setRawData() and resizes this array to zero-size

Definition at line 60 of file SampleArray.cpp.

References m_storage.

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

61 {
62  if (!m_storage) return;
63  m_storage->m_raw_data = Q_NULLPTR;
64  m_storage->m_size = 0;
65 }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
Here is the caller graph for this function:

◆ resize()

bool Kwave::SampleArray::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
Returns
true if succeeded, false if failed

Definition at line 105 of file SampleArray.cpp.

References m_storage.

Referenced by Kwave::FlacEncoder::encode(), Kwave::SampleBuffer::finished(), Kwave::NoiseGenerator::input(), Kwave::LowPassFilter::input(), Kwave::PitchShiftFilter::input(), Kwave::NotchFilter::input(), Kwave::BandPass::input(), Kwave::SampleBuffer::input(), Kwave::ChannelMixer::mix(), Kwave::Mul::multiply(), Kwave::PlayBackOSS::open(), Kwave::SampleReader::operator>>(), Kwave::SampleBuffer::put(), Kwave::TrackPixmap::resizeBuffer(), Kwave::ReversePlugin::reverseSlice(), Kwave::ZeroPlugin::run(), Kwave::DebugPlugin::run(), SampleArray(), Kwave::Delay::setDelay(), setRawData(), and Kwave::StreamWriter::write().

106 {
107  if (!m_storage) return false;
108  if (size == m_storage->m_size) return true;
109 
110  Q_ASSERT(m_storage->m_raw_data == Q_NULLPTR);
111  m_storage->resize(size);
112  if (size && (m_storage->m_size > size)) {
113  qWarning("Kwave::SampleArray::resize(): shrinking from %u to %u "
114  "failed, keeping old memory", m_storage->m_size, size);
115  return true;
116  }
117  return (m_storage->m_size == size);
118 }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
unsigned int size() const
Here is the caller graph for this function:

◆ setRawData()

void Kwave::SampleArray::setRawData ( sample_t data,
unsigned int  size 
)

Sets a pointer to some raw data

Parameters
datapointer to an array of sample_t
sizenumber of samples in the array

Definition at line 47 of file SampleArray.cpp.

References data(), m_storage, resize(), and size().

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

48 {
49  if (!m_storage) return;
50  bool ok = resize(0);
51  if (!ok) qWarning("Kwave::SampleArray::setRawData(...) - OOM?");
52  Q_ASSERT(m_storage->m_raw_data == Q_NULLPTR);
53  Q_ASSERT(m_storage->m_data == Q_NULLPTR);
54  Q_ASSERT(m_storage->m_size == 0);
55  m_storage->m_raw_data = data;
56  m_storage->m_size = size;
57 }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
unsigned int size() const
sample_t * data()
Definition: SampleArray.h:62
bool resize(unsigned int size) Q_REQUIRED_RESULT
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

unsigned int Kwave::SampleArray::size ( ) const

Returns the number of samples.

Returns
samples [0...N]

Definition at line 121 of file SampleArray.cpp.

References m_storage.

Referenced by Kwave::Stripe::append(), Kwave::Track::appendAfter(), Kwave::SampleBuffer::available(), Kwave::RecordPlugin::checkTrigger(), Kwave::Stripe::combine(), Kwave::TrackPixmap::drawOverview(), Kwave::TrackPixmap::drawPolyLineSignal(), Kwave::FlacEncoder::encode(), Kwave::SampleReader::fillBuffer(), Kwave::SampleBuffer::finished(), Kwave::SampleFIFO::get(), Kwave::SampleBuffer::get(), Kwave::Osc::goOn(), Kwave::NoiseGenerator::input(), Kwave::Normalizer::input(), Kwave::LowPassFilter::input(), Kwave::RateConverter::input(), Kwave::MultiPlaybackSink::input(), Kwave::PitchShiftFilter::input(), Kwave::NotchFilter::input(), Kwave::BandPass::input(), Kwave::SampleBuffer::input(), Kwave::Writer::input(), Kwave::ChannelMixer::mix(), Kwave::Mul::multiply(), Kwave::Writer::operator<<(), Kwave::Stripe::operator<<(), Kwave::SampleReader::operator>>(), Kwave::RecordPlugin::processBuffer(), Kwave::SampleReader::read(), Kwave::SampleReader::readSamples(), Kwave::Stripe::resize(), Kwave::SampleArray::SampleStorage::resize(), Kwave::ReversePlugin::reverse(), Kwave::ZeroPlugin::run(), Kwave::DebugPlugin::run(), Kwave::Delay::setDelay(), Kwave::TrackPixmap::setOffset(), setRawData(), Kwave::Stripe::Stripe(), Kwave::SampleFIFO::unlockedLength(), Kwave::RecordDialog::updateEffects(), Kwave::LevelMeter::updateTrack(), Kwave::TrackPixmap::validateBuffer(), Kwave::PlayBackOSS::write(), Kwave::StreamWriter::write(), Kwave::PlayBackQt::write(), and Kwave::TrackWriter::write().

122 {
123  return (m_storage) ? m_storage->m_size : 0;
124 }
QSharedDataPointer< SampleStorage > m_storage
Definition: SampleArray.h:152
Here is the caller graph for this function:

Member Data Documentation

◆ m_storage

QSharedDataPointer<SampleStorage> Kwave::SampleArray::m_storage
private

Definition at line 152 of file SampleArray.h.

Referenced by fill(), resetRawData(), resize(), SampleArray(), setRawData(), and size().


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