kwave  18.07.70
Kwave::StreamWriter Class Reference

#include <StreamWriter.h>

Inheritance diagram for Kwave::StreamWriter:
Inheritance graph
Collaboration diagram for Kwave::StreamWriter:
Collaboration graph

Signals

void output (Kwave::SampleArray data)
 
- Signals inherited from Kwave::Writer
void sigSamplesWritten (sample_index_t)
 
void proceeded ()
 
- Signals inherited from Kwave::StreamObject
void attributeChanged (const QVariant value)
 

Public Member Functions

 StreamWriter ()
 
virtual ~StreamWriter () Q_DECL_OVERRIDE
 
virtual bool write (const Kwave::SampleArray &buffer, unsigned int &count) Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::Writer
 Writer ()
 
 Writer (Kwave::InsertMode mode, sample_index_t left=0, sample_index_t right=0)
 
virtual ~Writer () Q_DECL_OVERRIDE
 
virtual Writeroperator<< (const Kwave::SampleArray &samples)
 
virtual Writeroperator<< (const sample_t &sample)
 
Writeroperator<< (Writer &(*modifier)(Writer &))
 
Writeroperator<< (Kwave::SampleReader &reader)
 
bool flush ()
 
virtual bool eof () const
 
virtual bool done () const Q_DECL_OVERRIDE
 
sample_index_t first () const
 
sample_index_t last () const
 
sample_index_t position () const
 
Kwave::InsertMode mode () const
 
- Public Member Functions inherited from Kwave::SampleSink
 SampleSink (QObject *parent=Q_NULLPTR)
 
virtual ~SampleSink ()
 
- Public Member Functions inherited from Kwave::StreamObject
 StreamObject (QObject *parent=Q_NULLPTR)
 
virtual ~StreamObject ()
 
virtual unsigned int tracks () const
 
virtual Kwave::StreamObjectoperator[] (unsigned int track)
 
virtual unsigned int tracksOfPort (const char *port) const
 
virtual Kwave::StreamObjectport (const char *port, unsigned int track)
 
virtual unsigned int blockSize () const
 
void setAttribute (const char *attribute, const QVariant &value)
 

Additional Inherited Members

- Public Slots inherited from Kwave::Writer
void input (Kwave::SampleArray data)
 
- Static Public Member Functions inherited from Kwave::StreamObject
static void setInteractive (bool interactive)
 
- Protected Attributes inherited from Kwave::Writer
sample_index_t m_first
 
sample_index_t m_last
 
Kwave::InsertMode m_mode
 
sample_index_t m_position
 
Kwave::SampleArray m_buffer
 
unsigned int m_buffer_size
 
unsigned int m_buffer_used
 

Detailed Description

Input stream for transferring samples into a Track.

Warning
THIS CLASS IS NOT THREADSAFE! It is intended to be owned by and used from only one thread.

Definition at line 42 of file StreamWriter.h.

Constructor & Destructor Documentation

◆ StreamWriter()

Kwave::StreamWriter::StreamWriter ( )

Constructor

Definition at line 25 of file StreamWriter.cpp.

26  :Kwave::Writer()
27 {
28 }

◆ ~StreamWriter()

Kwave::StreamWriter::~StreamWriter ( )
virtual

Destructor.

Definition at line 31 of file StreamWriter.cpp.

References Kwave::Writer::m_buffer_used.

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 }
unsigned int m_buffer_used
Definition: Writer.h:167

Member Function Documentation

◆ output

void Kwave::StreamWriter::output ( Kwave::SampleArray  data)
signal

emits a block with sine wave data

Referenced by write().

Here is the caller graph for this function:

◆ write()

bool Kwave::StreamWriter::write ( const Kwave::SampleArray buffer,
unsigned int &  count 
)
virtual

Flush the content of a buffer. Normally the buffer is the internal intermediate buffer used for single-sample writes. When using block transfers, the internal buffer is bypassed and the written block is passed instead.

Parameters
bufferreference to the buffer to be flushed
countnumber of samples in the buffer to be flushed, will be internally set to zero if successful
Returns
true if successful, false if failed (e.g. out of memory)

Implements Kwave::Writer.

Definition at line 42 of file StreamWriter.cpp.

References output(), Kwave::SampleArray::resize(), and Kwave::SampleArray::size().

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 }
void output(Kwave::SampleArray data)
unsigned int size() const
bool resize(unsigned int size) Q_REQUIRED_RESULT
Here is the call graph for this function:

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