| 23 | MfccDct::MfccDct() : initialized_(false) {} |
| 24 | |
| 25 | bool MfccDct::Initialize(int input_length, int coefficient_count) { |
| 26 | coefficient_count_ = coefficient_count; |
| 27 | input_length_ = input_length; |
| 28 | |
| 29 | if (coefficient_count_ < 1) { |
| 30 | LOG(ERROR) << "Coefficient count must be positive."; |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | if (input_length < 1) { |
| 35 | LOG(ERROR) << "Input length must be positive."; |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | if (coefficient_count_ > input_length_) { |
| 40 | LOG(ERROR) << "Coefficient count must be less than or equal to " |
| 41 | << "input length."; |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | cosines_.resize(coefficient_count_); |
| 46 | double fnorm = sqrt(2.0 / input_length_); |
| 47 | // Some platforms don't have M_PI, so define a local constant here. |
| 48 | const double pi = std::atan(1) * 4; |
| 49 | double arg = pi / input_length_; |
| 50 | for (int i = 0; i < coefficient_count_; ++i) { |
| 51 | cosines_[i].resize(input_length_); |
| 52 | for (int j = 0; j < input_length_; ++j) { |
| 53 | cosines_[i][j] = fnorm * cos(i * arg * (j + 0.5)); |
| 54 | } |
| 55 | } |
| 56 | initialized_ = true; |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | void MfccDct::Compute(const std::vector<double> &input, |
| 61 | std::vector<double> *output) const { |