-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from sp-nitech/iltcdf
Add iltcdf
- Loading branch information
Showing
15 changed files
with
577 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.. _iltcdf: | ||
|
||
iltcdf | ||
====== | ||
|
||
.. doxygenfile:: iltcdf.cc | ||
|
||
.. seealso:: :ref:`lpc2par` :ref:`ltcdf` | ||
|
||
.. doxygenclass:: sptk::AllZeroLatticeDigitalFilter | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// ------------------------------------------------------------------------ // | ||
// Copyright 2021 SPTK Working Group // | ||
// // | ||
// Licensed under the Apache License, Version 2.0 (the "License"); // | ||
// you may not use this file except in compliance with the License. // | ||
// You may obtain a copy of the License at // | ||
// // | ||
// http://www.apache.org/licenses/LICENSE-2.0 // | ||
// // | ||
// Unless required by applicable law or agreed to in writing, software // | ||
// distributed under the License is distributed on an "AS IS" BASIS, // | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // | ||
// See the License for the specific language governing permissions and // | ||
// limitations under the License. // | ||
// ------------------------------------------------------------------------ // | ||
|
||
#ifndef SPTK_FILTER_ALL_ZERO_LATTICE_DIGITAL_FILTER_H_ | ||
#define SPTK_FILTER_ALL_ZERO_LATTICE_DIGITAL_FILTER_H_ | ||
|
||
#include <vector> // std::vector | ||
|
||
#include "SPTK/utils/sptk_utils.h" | ||
|
||
namespace sptk { | ||
|
||
/** | ||
* Apply all-zero lattice filter for speech synthesis. | ||
* | ||
* Given the @f$M@f$-th order PARCOR coefficients, | ||
* @f[ | ||
* \begin{array}{cccc} | ||
* K, & k(1), & \ldots, & k(M), | ||
* \end{array} | ||
* @f] | ||
* an output signal is obtained by applying the all-zero lattice filter to an | ||
* input signal in time domain. | ||
*/ | ||
class AllZeroLatticeDigitalFilter { | ||
public: | ||
/** | ||
* Buffer for AllZeroLatticeDigitalFilter class. | ||
*/ | ||
class Buffer { | ||
public: | ||
Buffer() { | ||
} | ||
|
||
virtual ~Buffer() { | ||
} | ||
|
||
private: | ||
std::vector<double> d_; | ||
|
||
friend class AllZeroLatticeDigitalFilter; | ||
DISALLOW_COPY_AND_ASSIGN(Buffer); | ||
}; | ||
|
||
/** | ||
* @param[in] num_filter_order Order of filter coefficients, @f$M@f$. | ||
*/ | ||
explicit AllZeroLatticeDigitalFilter(int num_filter_order); | ||
|
||
virtual ~AllZeroLatticeDigitalFilter() { | ||
} | ||
|
||
/** | ||
* @return Order of coefficients. | ||
*/ | ||
int GetNumFilterOrder() const { | ||
return num_filter_order_; | ||
} | ||
|
||
/** | ||
* @return True if this object is valid. | ||
*/ | ||
bool IsValid() const { | ||
return is_valid_; | ||
} | ||
|
||
/** | ||
* @param[in] filter_coefficients @f$M@f$-th order PARCOR coefficients. | ||
* @param[in] filter_input Input signal. | ||
* @param[out] filter_output Output signal. | ||
* @param[in,out] buffer Buffer. | ||
* @return True on success, false on failure. | ||
*/ | ||
bool Run(const std::vector<double>& filter_coefficients, double filter_input, | ||
double* filter_output, | ||
AllZeroLatticeDigitalFilter::Buffer* buffer) const; | ||
|
||
/** | ||
* @param[in] filter_coefficients @f$M@f$-th order PARCOR coefficients. | ||
* @param[in,out] input_and_output Input/output signal. | ||
* @param[in,out] buffer Buffer. | ||
* @return True on success, false on failure. | ||
*/ | ||
bool Run(const std::vector<double>& filter_coefficients, | ||
double* input_and_output, | ||
AllZeroLatticeDigitalFilter::Buffer* buffer) const; | ||
|
||
private: | ||
const int num_filter_order_; | ||
|
||
bool is_valid_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(AllZeroLatticeDigitalFilter); | ||
}; | ||
|
||
} // namespace sptk | ||
|
||
#endif // SPTK_FILTER_ALL_ZERO_LATTICE_DIGITAL_FILTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// ------------------------------------------------------------------------ // | ||
// Copyright 2021 SPTK Working Group // | ||
// // | ||
// Licensed under the Apache License, Version 2.0 (the "License"); // | ||
// you may not use this file except in compliance with the License. // | ||
// You may obtain a copy of the License at // | ||
// // | ||
// http://www.apache.org/licenses/LICENSE-2.0 // | ||
// // | ||
// Unless required by applicable law or agreed to in writing, software // | ||
// distributed under the License is distributed on an "AS IS" BASIS, // | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // | ||
// See the License for the specific language governing permissions and // | ||
// limitations under the License. // | ||
// ------------------------------------------------------------------------ // | ||
|
||
#include "SPTK/filter/all_zero_lattice_digital_filter.h" | ||
|
||
#include <algorithm> // std::fill | ||
#include <cstddef> // std::size_t | ||
|
||
namespace sptk { | ||
|
||
AllZeroLatticeDigitalFilter::AllZeroLatticeDigitalFilter(int num_filter_order) | ||
: num_filter_order_(num_filter_order), is_valid_(true) { | ||
if (num_filter_order_ < 0) { | ||
is_valid_ = false; | ||
return; | ||
} | ||
} | ||
|
||
bool AllZeroLatticeDigitalFilter::Run( | ||
const std::vector<double>& filter_coefficients, double filter_input, | ||
double* filter_output, AllZeroLatticeDigitalFilter::Buffer* buffer) const { | ||
// Check inputs | ||
if (!is_valid_ || | ||
filter_coefficients.size() != | ||
static_cast<std::size_t>(num_filter_order_ + 1) || | ||
NULL == filter_output || NULL == buffer) { | ||
return false; | ||
} | ||
|
||
// Prepare memories. | ||
if (buffer->d_.size() != static_cast<std::size_t>(num_filter_order_)) { | ||
buffer->d_.resize(num_filter_order_); | ||
std::fill(buffer->d_.begin(), buffer->d_.end(), 0.0); | ||
} | ||
|
||
if (0 == num_filter_order_) { | ||
*filter_output = filter_input * filter_coefficients[0]; | ||
return true; | ||
} | ||
|
||
const double* k(&(filter_coefficients[1])); | ||
double* d(&buffer->d_[0]); | ||
double sum(filter_input); | ||
double next_d(filter_input); | ||
|
||
// Apply all-zero lattice filter. | ||
for (int m(0); m < num_filter_order_; ++m) { | ||
const double tmp(d[m] + k[m] * sum); | ||
sum += k[m] * d[m]; | ||
d[m] = next_d; | ||
next_d = tmp; | ||
} | ||
|
||
// Save result. | ||
*filter_output = sum * filter_coefficients[0]; | ||
|
||
return true; | ||
} | ||
|
||
bool AllZeroLatticeDigitalFilter::Run( | ||
const std::vector<double>& filter_coefficients, double* input_and_output, | ||
AllZeroLatticeDigitalFilter::Buffer* buffer) const { | ||
if (NULL == input_and_output) return false; | ||
return Run(filter_coefficients, *input_and_output, input_and_output, buffer); | ||
} | ||
|
||
} // namespace sptk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.