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
|
/***************************************************************************
StreamWriter.cpp - adapter between writers and sample source
-------------------
begin : Sun Aug 23 2009
copyright : (C) 2009 by Thomas Eschenbacher
email : Thomas Eschenbacher <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. *
* *
***************************************************************************/
#include "config.h"
#include "libkwave/SampleArray.h"
#include "libkwave/StreamWriter.h"
//***************************************************************************
Kwave::StreamWriter::StreamWriter()
:Kwave::Writer()
{
}
//***************************************************************************
Kwave::StreamWriter::~StreamWriter()
{
// If this assert gets hit, you deleted a writer without calling
// flush() before. Flushing in the destructor is problematic and
// might be too late when the derived classes' destructor was
// already done and signal/slot connections were already released!
Q_ASSERT(!m_buffer_used);
if (m_buffer_used) qWarning("StreamWriter was not flushed!?");
}
//***************************************************************************
bool Kwave::StreamWriter::write(const Kwave::SampleArray &buffer,
unsigned int &count)
{
// NOTE: even zero length input has to be passed, needed for flushing!
if (count < buffer.size()) {
// have to work with a resized copy - slow :-(
Kwave::SampleArray data = buffer;
if (!data.resize(count))
return false; // out-of-memory ?
// emit the resized copy
emit output(data);
} else {
// directly emit the buffer - fast :-)
emit output(buffer);
}
count = 0;
return true;
}
//***************************************************************************
//***************************************************************************
#include "moc_StreamWriter.cpp"
|