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 
18 #include "libkwave/modules/CurveStreamAdapter.h"
19 
20 /***************************************************************************/
CurveStreamAdapter(Kwave::Curve & curve,sample_index_t length)21 Kwave::CurveStreamAdapter::CurveStreamAdapter(Kwave::Curve &curve,
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 /***************************************************************************/
~CurveStreamAdapter()31 Kwave::CurveStreamAdapter::~CurveStreamAdapter()
32 {
33 }
34 
35 /***************************************************************************/
goOn()36 void Kwave::CurveStreamAdapter::goOn()
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 /***************************************************************************/
60