File: Filter.h

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (132 lines) | stat: -rw-r--r-- 4,163 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
               Filter.h  -  parameters of a digital IIR or FIR filter
                             -------------------
    begin                : Jan 21 2001
    copyright            : (C) 2001 by Thomas Eschenbacher
    email                : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef FILTER_H
#define FILTER_H

#include "config.h"
#include <QVector>

class QString;

namespace Kwave
{

    /**
     * @class Filter
     * Holds a set of parameters for a digital IIR or FIR filter.
     *
     * @todo use KIONetAccess in the load/save methods
     * @todo more error checks in load/save (current code is too optimistic)
     */
    class Filter
    {
    public:
        /**
         * Constructor, creates an empty filter with a given sample rate.
         * @param rate number of samples per second
         */
        explicit Filter(int rate);

        /**
         * Constructor, creates a filter from a Kwave command string.
         * @param command part of the Kwave command with parameters
         */
        explicit Filter(const QString &command);

        /** Destructor */
        virtual ~Filter();

        /**
         * Returns the Kwave command string from the
         * current parameters.
         */
        QString command();

        /**
         * Resizes the filter to a new number of coefficients.
         * @param newnum new number of coefficients [1..]
         * @return new number of coefficients or zero if failed
         */
        unsigned int resize(unsigned int newnum);

        /** Returns true if the filter is a FIR one, or false else */
        inline bool isFIR() const { return m_fir; }

        /** Returns the sample rate in samples/second */
        inline int rate() const { return m_rate; }

        /**
         * Returns the number of coefficients and
         * delay times (order) of the filter.
         */
        unsigned int count();

        /**
         * Returns a filter coefficient.
         * @param index internal index [0...count-1]
         */
        double coeff(unsigned int index);

        /**
         * Sets a filter coefficient to a new value.
         * @param index internal index [0...count-1]
         * @param newval new coefficient
         */
        void setCoeff(unsigned int index, double newval);

        /**
         * Returns a delay time of the filter.
         * @param index internal index [0...count-1]
         */
        unsigned int delay(unsigned int index);

        /**
         * Sets a delay value to a new value.
         * @param index internal index [0...count-1]
         * @param newval new delay value
         */
        void setDelay(unsigned int index, unsigned int newval);

        /** Loads the filter parameters from a URL */
        void load(const QString &filename);

        /** Saves the filter parameters to a URL */
        void save(const QString &filename);

    private:

        /** boolean if filter is FIR or IIR */
        bool m_fir;

        /** sample rate in samples/second */
        unsigned int m_rate;

        /** array of coefficients */
        QVector<double> m_coeff;

        /** array of delay times */
        QVector<int> m_delay;

    };

}

#endif /* FILTER_H */

//*****************************************************************************
//*****************************************************************************