kwave  18.07.70
CurveStreamAdapter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  CurveStreamAdapter_impl.cpp - converter from Curve to aRts sample stream
3  -------------------
4  begin : Wed Dec 12 2001
5  copyright : (C) 2001 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 
19 
20 /***************************************************************************/
22  sample_index_t length)
23  :Kwave::SampleSource(),
24  m_position(0), m_length(length),
25  m_interpolation(curve.interpolation()),
26  m_buffer(blockSize())
27 {
28 }
29 
30 /***************************************************************************/
32 {
33 }
34 
35 /***************************************************************************/
37 {
38  unsigned int offset;
39  double x_max = static_cast<double>(m_length);
40  const unsigned int samples = blockSize();
41 
42  // fill with interpolated points
43  for (offset = 0; offset < samples; ++offset) {
44  // x is [0.0 ... 1.0]
45  const double x = static_cast<double>(m_position) / x_max;
46  const double y = m_interpolation.singleInterpolation(x);
47  m_buffer[offset] = double2sample(y);
48  m_position++;
49 
50  // wrap-around, for periodic signals
51  if (m_position > m_length)
52  m_position = 0;
53  }
54 
55  emit output(m_buffer);
56 }
57 
58 /***************************************************************************/
59 /***************************************************************************/
Kwave::Interpolation & m_interpolation
Definition: App.h:33
void output(Kwave::SampleArray data)
quint64 sample_index_t
Definition: Sample.h:28
double singleInterpolation(double pos)
virtual void goOn() Q_DECL_OVERRIDE
virtual ~CurveStreamAdapter() Q_DECL_OVERRIDE
virtual unsigned int blockSize() const
static sample_t double2sample(const double f)
Definition: Sample.h:81
CurveStreamAdapter(Kwave::Curve &curve, sample_index_t length)
Kwave::SampleArray m_buffer