kwave  18.07.70
Delay.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Delay.cpp - delay line for small delays
3  -------------------
4  begin : Sun Nov 11 2007
5  copyright : (C) 2007 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 #include <QString>
20 
21 #include "libkwave/modules/Delay.h"
22 
23 //***************************************************************************
25  :Kwave::SampleSource(), m_fifo(), m_out_buffer(blockSize()), m_delay(0)
26 {
27 }
28 
29 //***************************************************************************
31 {
32 }
33 
34 //***************************************************************************
36 {
38  emit output(m_out_buffer);
39 }
40 
41 //***************************************************************************
43 {
44  m_fifo.put(data);
45 }
46 
47 //***************************************************************************
48 void Kwave::Delay::setDelay(const QVariant &d)
49 {
50  unsigned int new_delay = QVariant(d).toUInt();
51  if (new_delay == m_delay) return; // nothing to do
52 
53  // fill it with zeroes, up to the delay time
54  m_fifo.flush();
55  Kwave::SampleArray zeroes(blockSize());
56  Q_ASSERT(zeroes.size() == blockSize());
57  for (unsigned int pos=0; pos < blockSize(); ++pos)
58  zeroes[pos] = 0;
59  unsigned int rest = new_delay;
60  while (rest) {
61  bool ok = true;
62  unsigned int len = blockSize();
63  if (rest < len) {
64  ok = zeroes.resize(rest);
65  Q_ASSERT(ok);
66  }
67  if (ok) m_fifo.put(zeroes);
68  rest -= zeroes.size();
69  }
70 }
71 
72 //***************************************************************************
73 //***************************************************************************
unsigned int m_delay
Definition: Delay.h:71
Definition: App.h:33
virtual ~Delay() Q_DECL_OVERRIDE
Definition: Delay.cpp:30
Kwave::SampleFIFO m_fifo
Definition: Delay.h:65
virtual void put(const Kwave::SampleArray &source)
Definition: SampleFIFO.cpp:54
void input(Kwave::SampleArray data)
Definition: Delay.cpp:42
virtual unsigned int get(Kwave::SampleArray &buffer)
Definition: SampleFIFO.cpp:70
Kwave::SampleArray m_out_buffer
Definition: Delay.h:68
virtual void flush()
Definition: SampleFIFO.cpp:45
virtual unsigned int blockSize() const
void output(Kwave::SampleArray data)
unsigned int size() const
virtual void goOn() Q_DECL_OVERRIDE
Definition: Delay.cpp:35
bool resize(unsigned int size) Q_REQUIRED_RESULT
void setDelay(const QVariant &d)
Definition: Delay.cpp:48