DCTReduce.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Tipic
5 
6  Centre for Digital Music, Queen Mary, University of London.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #ifndef DCTREDUCE_H
16 #define DCTREDUCE_H
17 
18 #include "dsp/transforms/DCT.h"
19 
20 #include <vector>
21 
22 class DCTReduce
23 {
24 public:
25  DCTReduce(int size, int coefficientsToDrop) :
26  m_size(size),
27  m_dct(size),
28  m_dctOut(size),
29  m_coefficientsToDrop(coefficientsToDrop)
30  { }
31 
32  std::vector<double> process(std::vector<double> in) {
33  std::vector<double> out(in.size());
34  m_dct.forward(in.data(), m_dctOut.data());
35  for (int i = 0; i < m_coefficientsToDrop && i < m_size; ++i) {
36  m_dctOut[i] = 0.0;
37  }
38  m_dct.inverse(m_dctOut.data(), out.data());
39  return out;
40  }
41 
42 private:
43  int m_size;
44  DCT m_dct;
45  std::vector<double> m_dctOut;
46  int m_coefficientsToDrop;
47 };
48 
49 #endif
50 
Definition: DCTReduce.h:22