1 /***************************************************************************
2         RateConverter.h  -  single channel sample rate converter
3                              -------------------
4     begin                : Sat Jul 11 2009
5     copyright            : (C) 2009 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 #ifndef RATE_CONVERTER_H
19 #define RATE_CONVERTER_H
20 
21 #include "config.h"
22 
23 #include <QtGlobal>
24 #include <QObject>
25 #include <QVarLengthArray>
26 #include <QVariant>
27 
28 #include <samplerate.h>
29 
30 #include "libkwave/SampleArray.h"
31 #include "libkwave/SampleSource.h"
32 
33 namespace Kwave
34 {
35 
36     class Q_DECL_EXPORT RateConverter: public Kwave::SampleSource
37     {
38 	Q_OBJECT
39     public:
40 
41 	/** Constructor */
42 	RateConverter();
43 
44 	/** Destructor */
45         virtual ~RateConverter() Q_DECL_OVERRIDE;
46 
47 	/** does nothing, processing is done in input() */
48         virtual void goOn() Q_DECL_OVERRIDE;
49 
50     signals:
51 
52 	/** emits a block with the filtered data */
53 	void output(Kwave::SampleArray data);
54 
55     public slots:
56 
57 	/** receives input data and also directly does the calculation */
58 	void input(Kwave::SampleArray data);
59 
60 	/**
61 	 * Sets the conversion ratio, ((new rate) / (old rate))
62 	 */
63 	void setRatio(const QVariant r);
64 
65     private:
66 
67 	/** conversion ratio, ((new rate) / (old rate)) */
68 	double m_ratio;
69 
70 	/** sample rate converter context for libsamplerate */
71 	SRC_STATE *m_converter;
72 
73 	/** input values for the sample rate converter */
74 	QVarLengthArray<float, 65536> m_converter_in;
75 
76 	/** output values for the sample rate converter */
77 	QVarLengthArray<float, 65536> m_converter_out;
78 
79     };
80 }
81 
82 #endif /* RATE_CONVERTER_H */
83 
84 //***************************************************************************
85 //***************************************************************************
86