20 #include <QApplication> 32 #define MIN_PROGRESS_INTERVAL 500 37 :m_mode(mode), m_stripes(stripes),
38 m_src_position(stripes.left()), m_first(stripes.left()),
39 m_last(stripes.right()), m_buffer(blockSize()),
40 m_buffer_used(0), m_buffer_position(0),
41 m_progress_time(), m_last_seek_pos(stripes.right())
63 unsigned int offset,
unsigned int len)
69 memset((&buffer[offset]), 0x00,
70 len *
sizeof(const_cast<const Kwave::SampleArray &>(buffer)[0]));
91 Q_ASSERT(len == rest);
98 QApplication::sendPostedEvents();
111 if (!s.
length())
continue;
115 if (end < first)
continue;
116 if (start > last)
break;
123 (first > start) ? (first - start) : 0);
125 (last < end) ? (last - start) : (end - start));
126 s.
minMax(s1, s2, min, max);
141 if (
eof() || !length)
return 0;
144 Q_ASSERT(buffer.
size());
145 Q_ASSERT(dstoff < buffer.
size());
146 if (dstoff >= buffer.
size())
return 0;
148 unsigned int count = 0;
149 unsigned int rest = length;
150 if (dstoff + rest > buffer.
size()) rest = buffer.
size() - dstoff;
156 unsigned int cnt = rest;
158 unsigned int dst = dstoff;
163 m_buffer_position += cnt;
167 qDebug(
"filling from buffer dstoff=%u, cnt=%u",dstoff,cnt);
187 QApplication::sendPostedEvents();
196 if (dstoff + rest > buffer.
size())
197 rest = buffer.
size() - dstoff;
198 Q_ASSERT(dstoff + rest <= buffer.
size());
200 Q_ASSERT(len == rest);
207 QApplication::sendPostedEvents();
242 if (pos == current_pos)
return;
244 if (pos < current_pos) {
271 skip(pos - current_pos);
292 unsigned int size = buffer.
size();
293 unsigned int count =
read(buffer, 0, size);
295 bool ok = buffer.
resize(count);
298 qWarning(
"Kwave::SampleReader::operator >> - OOM?");
315 unsigned int buf_offset,
319 if (!length)
return 0;
320 Q_ASSERT(buf_offset + length <= buffer.
size());
322 unsigned int rest = length;
327 if (!s.
length())
continue;
334 if (pad > rest) pad = rest;
342 if (start > right)
break;
346 Q_ASSERT(left >= start);
349 if (len > rest) len = rest;
350 unsigned int count = s.
read(buffer, buf_offset, ofs, len);
351 Q_ASSERT(count == len);
360 if (rest)
padBuffer(buffer, buf_offset, rest);
unsigned int length() const
void skip(sample_index_t count)
virtual void goOn() Q_DECL_OVERRIDE
unsigned int read(Kwave::SampleArray &buffer, unsigned int dstoff, unsigned int offset, unsigned int length)
unsigned int m_buffer_position
void output(Kwave::SampleArray data)
sample_index_t m_src_position
void seek(sample_index_t pos)
sample_index_t last() const
Kwave::SampleArray m_buffer
void minMax(sample_index_t first, sample_index_t last, sample_t &min, sample_t &max)
sample_index_t start() const
sample_index_t first() const
sample_index_t pos() const
sample_index_t end() const
QList< Kwave::Stripe > m_stripes
virtual unsigned int blockSize() const
#define MIN_PROGRESS_INTERVAL
virtual ~SampleReader() Q_DECL_OVERRIDE
static void padBuffer(Kwave::SampleArray &buffer, unsigned int offset, unsigned int len)
SampleReader(Kwave::ReaderMode mode, Kwave::Stripe::List stripes)
unsigned int size() const
unsigned int read(Kwave::SampleArray &buffer, unsigned int dstoff, unsigned int length)
SampleReader & operator>>(sample_t &sample)
unsigned int readSamples(sample_index_t offset, Kwave::SampleArray &buffer, unsigned int buf_offset, unsigned int length)
bool resize(unsigned int size) Q_REQUIRED_RESULT
unsigned int m_buffer_used
void minMax(unsigned int first, unsigned int last, sample_t &min, sample_t &max)
sample_index_t m_last_seek_pos