kwave  18.07.70
StreamWriter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  StreamWriter.cpp - adapter between writers and sample source
3  -------------------
4  begin : Sun Aug 23 2009
5  copyright : (C) 2009 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "config.h"
20 
21 #include "libkwave/SampleArray.h"
22 #include "libkwave/StreamWriter.h"
23 
24 //***************************************************************************
26  :Kwave::Writer()
27 {
28 }
29 
30 //***************************************************************************
32 {
33  // If this assert gets hit, you deleted a writer without calling
34  // flush() before. Flushing in the destructor is problematic and
35  // might be too late when the derived classes' destructor was
36  // already done and signal/slot connections were already released!
37  Q_ASSERT(!m_buffer_used);
38  if (m_buffer_used) qWarning("StreamWriter was not flushed!?");
39 }
40 
41 //***************************************************************************
43  unsigned int &count)
44 {
45  // NOTE: even zero length input has to be passed, needed for flushing!
46 
47  if (count < buffer.size()) {
48  // have to work with a resized copy - slow :-(
49  Kwave::SampleArray data = buffer;
50  if (!data.resize(count))
51  return false; // out-of-memory ?
52 
53  // emit the resized copy
54  emit output(data);
55  } else {
56  // directly emit the buffer - fast :-)
57  emit output(buffer);
58  }
59 
60  count = 0;
61  return true;
62 }
63 
64 //***************************************************************************
65 //***************************************************************************
Definition: App.h:33
void output(Kwave::SampleArray data)
unsigned int m_buffer_used
Definition: Writer.h:167
virtual ~StreamWriter() Q_DECL_OVERRIDE
virtual bool write(const Kwave::SampleArray &buffer, unsigned int &count) Q_DECL_OVERRIDE
unsigned int size() const
bool resize(unsigned int size) Q_REQUIRED_RESULT