[3e4acc]: libkwave / KwaveSampleArray.h Maximize Restore History

Download this file

KwaveSampleArray.h    155 lines (123 with data), 4.1 kB

  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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*************************************************************************
KwaveSampleArray.h - array with Kwave's internal sample_t
-------------------
begin : Sun Oct 07 2007
copyright : (C) 2007 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef _KWAVE_SAMPLE_ARRAY_H_
#define _KWAVE_SAMPLE_ARRAY_H_
#include "config.h"
#include <QSharedData>
#include <QSharedDataPointer>
#include <kdemacros.h>
#include "libkwave/Sample.h"
namespace Kwave {
/**
* array with sample_t, for use in KwaveSampleSource, KwaveSampleSink
* and other streaming classes.
*/
class KDE_EXPORT SampleArray
{
public:
/** Default constructor, creates an empty array */
SampleArray();
/**
* Constructor, creates an array with predefined size
* (not initialized)
* @param size number of samples to hold
*/
SampleArray(unsigned int size);
/** Destructor */
virtual ~SampleArray();
/** returns a const pointer to the raw data (non-mutable) */
inline const sample_t * data() const
{
if (!m_storage) return 0;
if (m_storage->m_raw_data) return m_storage->m_raw_data;
return m_storage->m_data;
}
/** returns a pointer to the raw data (mutable) */
inline sample_t *data()
{
if (!m_storage) return 0;
return (!m_storage->m_raw_data) ?
m_storage->m_data : m_storage->m_raw_data;
}
/**
* Sets a pointer to some raw data
* @param data pointer to an array of sample_t
* @param size number of samples in the array
*/
void setRawData(sample_t *data, unsigned int size);
/**
* Resets the raw data set with setRawData() and resizes this
* array to zero-size
*/
void resetRawData();
/** fills the array with a sample value */
void fill(sample_t value);
/**
* operator [], non-const.
* @param index sample index [0...count()-1]
* @return reference to the requested sample (read only)
*/
sample_t & operator [] (unsigned int index);
/**
* operator [], non-const.
* @param index sample index [0...count()-1]
* @return reference to the requested sample (read/write)
*/
const sample_t & operator [] (unsigned int index) const;
/**
* Resizes the array. Using raw data mode is not allowed and will
* lead to an assert!
* @param size new number of samples
*/
void resize(unsigned int size);
/**
* Returns the number of samples.
* @return samples [0...N]
*/
unsigned int size() const;
/**
* Returns whether the array is empty.
* The same as (size() == 0).
* @return true if empty, false if not
*/
inline bool isEmpty() const { return (size() == 0); }
private:
class SampleStorage: public QSharedData {
public:
/** default constructor */
SampleStorage();
/** copy constructor */
SampleStorage(const SampleStorage &other);
/** destructor */
virtual ~SampleStorage();
/**
* Resizes the array. Using raw data mode is not allowed and will
* lead to an assert!
* @param size new number of samples
*/
void resize(unsigned int size);
public:
/** size in samples */
unsigned int m_size;
/** pointer to the area with the samples (allocated) */
sample_t *m_data;
/** pointer to some raw data that has been set */
sample_t *m_raw_data;
};
QSharedDataPointer<SampleStorage> m_storage;
};
}
#endif /* _KWAVE_SAMPLE_ARRAY_H_ */