From: Keiichiro O. <ur...@us...> - 2016-10-14 06:17:47
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv29518 Modified Files: Makefile freqt.cc frequency_transform.cc frequency_transform.h input_source_from_stream.h input_source_interface.h input_source_preprocessing_for_filter_gain.cc input_source_preprocessing_for_filter_gain.h Added Files: generalized_cepstrum_transform.cc generalized_cepstrum_transform.h Log Message: add generalized cepstrum transform Index: frequency_transform.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/frequency_transform.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** frequency_transform.cc 12 Oct 2016 12:14:38 -0000 1.9 --- frequency_transform.cc 14 Oct 2016 06:17:44 -0000 1.10 *************** *** 50,59 **** namespace sptk { bool FrequencyTransform::Run(const std::vector<double>& minimum_phase_sequence, std::vector<double>* warped_sequence, FrequencyTransform::Buffer* buffer) const { // check inputs ! if (minimum_phase_sequence.empty() || NULL == warped_sequence || ! NULL == buffer) { return false; } --- 50,72 ---- namespace sptk { + FrequencyTransform::FrequencyTransform(int num_input_order, + int num_output_order, double alpha) + : num_input_order_(num_input_order), + num_output_order_(num_output_order), + alpha_(alpha), + is_valid_(true) { + if (num_input_order_ < 0 || num_output_order_ < 0) { + is_valid_ = false; + } + } + bool FrequencyTransform::Run(const std::vector<double>& minimum_phase_sequence, std::vector<double>* warped_sequence, FrequencyTransform::Buffer* buffer) const { // check inputs ! if (!is_valid_ || ! minimum_phase_sequence.size() != ! static_cast<std::size_t>(num_input_order_ + 1) || ! NULL == warped_sequence || NULL == buffer) { return false; } *************** *** 65,70 **** } ! const int num_input_order(minimum_phase_sequence.size() - 1); ! if (0.0 == alpha_ && num_input_order == num_output_order_) { std::copy(minimum_phase_sequence.begin(), minimum_phase_sequence.end(), warped_sequence->begin()); --- 78,82 ---- } ! if (0.0 == alpha_ && num_input_order_ == num_output_order_) { std::copy(minimum_phase_sequence.begin(), minimum_phase_sequence.end(), warped_sequence->begin()); *************** *** 93,99 **** // transform ! for (int i(0); i <= num_input_order; ++i) { d[0] = g[0]; ! g[0] = input[num_input_order - i] + alpha_ * d[0]; if (1 <= num_output_order_) { d[1] = g[1]; --- 105,111 ---- // transform ! for (int i(0); i <= num_input_order_; ++i) { d[0] = g[0]; ! g[0] = input[num_input_order_ - i] + alpha_ * d[0]; if (1 <= num_output_order_) { d[1] = g[1]; Index: freqt.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/freqt.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** freqt.cc 12 Oct 2016 12:14:38 -0000 1.6 --- freqt.cc 14 Oct 2016 06:17:44 -0000 1.7 *************** *** 171,183 **** // prepare for frequency transform ! sptk::FrequencyTransform frequency_transform; sptk::FrequencyTransform::Buffer buffer; ! if (!frequency_transform.SetNumOutputOrder(num_output_order)) { std::ostringstream error_message; ! error_message << "Failed to set the number of output orders"; sptk::PrintErrorMessage("freqt", error_message); return 1; } - frequency_transform.SetAlpha(alpha); const int input_length(num_input_order + 1); --- 171,183 ---- // prepare for frequency transform ! sptk::FrequencyTransform frequency_transform(num_input_order, ! num_output_order, alpha); sptk::FrequencyTransform::Buffer buffer; ! if (!frequency_transform.IsValid()) { std::ostringstream error_message; ! error_message << "Failed to set the condition of frequency transform"; sptk::PrintErrorMessage("freqt", error_message); return 1; } const int input_length(num_input_order + 1); --- NEW FILE: generalized_cepstrum_transform.h --- // ----------------------------------------------------------------- // // The Speech Signal Processing Toolkit (SPTK) // // developed by SPTK Working Group // // http://sp-tk.sourceforge.net/ // // ----------------------------------------------------------------- // // // // Copyright (c) 1984-2007 Tokyo Institute of Technology // // Interdisciplinary Graduate School of // // Science and Engineering // // // // 1996-2016 Nagoya Institute of Technology // // Department of Computer Science // // // // All rights reserved. // // // // Redistribution and use in source and binary forms, with or // // without modification, are permitted provided that the following // // conditions are met: // // // // - Redistributions of source code must retain the above copyright // // notice, this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above // // copyright notice, this list of conditions and the following // // disclaimer in the documentation and/or other materials provided // // with the distribution. // // - Neither the name of the SPTK working group nor the names of its // // contributors may be used to endorse or promote products derived // // from this software without specific prior written permission. // // // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND // // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS // // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON // // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY // // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // // POSSIBILITY OF SUCH DAMAGE. // // ----------------------------------------------------------------- // #ifndef SPTK_SRC_GENERALIZED_CEPSTRUM_TRANSFORM_H_ #define SPTK_SRC_GENERALIZED_CEPSTRUM_TRANSFORM_H_ #include <vector> // std::vector #include "frequency_transform.h" #include "sptk_utils.h" namespace sptk { class GeneralizedCepstrumTransform { public: class Buffer { public: Buffer() {} virtual ~Buffer() {} private: std::vector<double> inverse_gain_normalized_input_; std::vector<double> gamma_divided_input_; std::vector<double> frequency_transformed_input_; FrequencyTransform::Buffer frequency_transform_buffer_; std::vector<double> gain_normalized_input_; std::vector<double> generalized_cepstrum_transformed_output_; std::vector<double> inverse_gain_normalized_output_; friend class GeneralizedCepstrumTransform; DISALLOW_COPY_AND_ASSIGN(Buffer); }; // GeneralizedCepstrumTransform(int num_input_order_, double input_alpha_, double input_gamma_, bool is_normalized_input_, bool is_multiplied_input_, int num_output_order_, double output_alpha_, double output_gamma_, bool is_normalized_output_, bool is_multiplied_output_); // virtual ~GeneralizedCepstrumTransform() {} // int GetNumInputOrder() const { return num_input_order_; } // double GetInputAlpha() const { return input_alpha_; } // double GetInputGamma() const { return input_gamma_; } // bool IsNormalizedInput() const { return is_normalized_input_; } // bool IsMultipliedInput() const { return is_multiplied_input_; } // int GetNumOutputOrder() const { return num_output_order_; } // double GetOutputAlpha() const { return output_alpha_; } // double GetOutputGamma() const { return output_gamma_; } // bool IsNormalizedOutut() const { return is_normalized_output_; } // bool IsMultipliedOutput() const { return is_multiplied_output_; } // bool IsValid() const { return is_valid_; } // bool Run(const std::vector<double>& input, std::vector<double>* output, GeneralizedCepstrumTransform::Buffer* buffer) const; private: // const int num_input_order_; // const double input_alpha_; // const double input_gamma_; // const bool is_normalized_input_; // const bool is_multiplied_input_; // const int num_output_order_; // const double output_alpha_; // const double output_gamma_; // const bool is_normalized_output_; // const bool is_multiplied_output_; // double alpha_transform_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(GeneralizedCepstrumTransform); }; } // namespace sptk #endif // SPTK_SRC_GENERALIZED_CEPSTRUM_TRANSFORM_H_ Index: input_source_from_stream.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/input_source_from_stream.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** input_source_from_stream.h 12 Oct 2016 12:14:38 -0000 1.3 --- input_source_from_stream.h 14 Oct 2016 06:17:44 -0000 1.4 *************** *** 72,75 **** --- 72,78 ---- // + virtual int GetSize() const { return read_size_; } + + // virtual bool IsValid() const { return is_valid_; } --- NEW FILE: generalized_cepstrum_transform.cc --- // ----------------------------------------------------------------- // // The Speech Signal Processing Toolkit (SPTK) // // developed by SPTK Working Group // // http://sp-tk.sourceforge.net/ // // ----------------------------------------------------------------- // // // // Copyright (c) 1984-2007 Tokyo Institute of Technology // // Interdisciplinary Graduate School of // // Science and Engineering // // // // 1996-2016 Nagoya Institute of Technology // // Department of Computer Science // // // // All rights reserved. // // // // Redistribution and use in source and binary forms, with or // // without modification, are permitted provided that the following // // conditions are met: // // // // - Redistributions of source code must retain the above copyright // // notice, this list of conditions and the following disclaimer. // // - Redistributions in binary form must reproduce the above // // copyright notice, this list of conditions and the following // // disclaimer in the documentation and/or other materials provided // // with the distribution. // // - Neither the name of the SPTK working group nor the names of its // // contributors may be used to endorse or promote products derived // // from this software without specific prior written permission. // // // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND // // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS // // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON // // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY // // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // // POSSIBILITY OF SUCH DAMAGE. // // ----------------------------------------------------------------- // #include "generalized_cepstrum_transform.h" #include <algorithm> // std::transform #include <vector> // std::vector #include "frequency_transform.h" #include "generalized_cepstrum_gain_normalization.h" #include "generalized_cepstrum_inverse_gain_normalization.h" namespace sptk { GeneralizedCepstrumTransform::GeneralizedCepstrumTransform( int num_input_order, double input_alpha, double input_gamma, bool is_normalized_input, bool is_multiplied_input, int num_output_order, double output_alpha, double output_gamma, bool is_normalized_output, bool is_multiplied_output) : num_input_order_(num_input_order), input_alpha_(input_alpha), input_gamma_(input_gamma), is_normalized_input_(is_normalized_input), is_multiplied_input_(is_multiplied_input), num_output_order_(num_output_order), output_alpha_(output_alpha), output_gamma_(output_gamma), is_normalized_output_(is_normalized_output), is_multiplied_output_(is_multiplied_output), alpha_transform_(0.0), is_valid_(true) { if (num_input_order_ < 0 || num_output_order_ < 0 || (input_alpha_ != output_alpha_ && 1.0 == input_alpha_ * output_alpha_) || (is_multiplied_input && 0.0 == input_gamma_) || (is_multiplied_output && 0.0 == output_gamma_)) { is_valid_ = false; return; } if (input_alpha_ != output_alpha_) { alpha_transform_ = (output_alpha_ - input_alpha_) / (1.0 - input_alpha_ * output_alpha_); } } bool GeneralizedCepstrumTransform::Run( const std::vector<double>& input, std::vector<double>* output, GeneralizedCepstrumTransform::Buffer* buffer) const { if (!is_valid_ || static_cast<std::size_t>(num_input_order_ + 1) != input.size() || NULL == output || NULL == buffer) { return false; } if (output->size() < static_cast<std::size_t>(num_output_order_ + 1)) { output->resize(num_output_order_ + 1); } // mgc2mgc input // norm=false multi=false freqt=false // -> -> -> gnorm -> gc2gc // norm=false multi=true freqt=false // -> c[1-m]/g -> -> gnorm -> gc2gc // norm=true multi=false freqt=false // -> gc2gc // norm=true multi=true freqt=false // ignorm -> c[1-m]/g -> -> gnorm -> gc2gc // norm=false multi=false freqt=true // -> -> freqt -> gnorm -> gc2gc // norm=false multi=true freqt=true // -> c[1-m]/g -> freqt -> gnorm -> gc2gc // norm=true multi=false freqt=true // ignorm -> -> freqt -> gnorm -> gc2gc // norm=true multi=true freqt=true // ignorm -> c[1-m]/g -> freqt -> gnorm -> gc2gc // do nothing if (num_input_order_ == num_output_order_ && input_alpha_ == output_alpha_ && input_gamma_ == output_gamma_ && is_normalized_input_ == is_normalized_output_ && is_multiplied_input_ == is_multiplied_output_) { std::copy(input.begin(), input.end(), output->begin()); return true; } // inverse gain normalization // input: input // output: inverse_gain_normalized_input const std::vector<double>* inverse_gain_normalized_input; if (is_normalized_input_ && (is_multiplied_input_ || 0.0 != alpha_transform_)) { GeneralizedCepstrumInverseGainNormalization generalized_cepstrum_inverse_gain_normalization(num_input_order_, input_gamma_); if (!generalized_cepstrum_inverse_gain_normalization.IsValid()) { return false; } if (!generalized_cepstrum_inverse_gain_normalization.Run( input, &buffer->inverse_gain_normalized_input_)) { return false; } inverse_gain_normalized_input = &buffer->inverse_gain_normalized_input_; } else { inverse_gain_normalized_input = &input; } // gamma division // input: inverse_gain_normalized_input // output: gamma_divided_input const std::vector<double>* gamma_divided_input; if (is_multiplied_input_) { if (buffer->gamma_divided_input_.size() < static_cast<std::size_t>(num_input_order_ + 1)) { buffer->gamma_divided_input_.resize(num_input_order_ + 1); } std::transform(inverse_gain_normalized_input->begin(), inverse_gain_normalized_input->end(), buffer->gamma_divided_input_.begin(), std::bind1st(std::multiplies<double>(), 1.0 / input_gamma_)); gamma_divided_input = &buffer->gamma_divided_input_; } else { gamma_divided_input = inverse_gain_normalized_input; } // frequency transform // input: gamma_divided_input // output: frequency_transformed_input const std::vector<double>* frequency_transformed_input; if (0.0 != alpha_transform_) { FrequencyTransform frequency_transform(num_input_order_, num_input_order_, alpha_transform_); if (!frequency_transform.IsValid()) { return false; } if (!frequency_transform.Run(*gamma_divided_input, &buffer->frequency_transformed_input_, &buffer->frequency_transform_buffer_)) { return false; } frequency_transformed_input = &buffer->frequency_transformed_input_; } else { frequency_transformed_input = gamma_divided_input; } // gain normalization // input: frequency_transformed_input // output: gain_normalized_input const std::vector<double>* gain_normalized_input; if (!is_normalized_input_ || is_multiplied_input_ || 0.0 != alpha_transform_) { GeneralizedCepstrumGainNormalization generalized_cepstrum_gain_normalization(num_input_order_, input_gamma_); if (!generalized_cepstrum_gain_normalization.IsValid()) { return false; } if (!generalized_cepstrum_gain_normalization.Run( *frequency_transformed_input, &buffer->gain_normalized_input_)) { return false; } gain_normalized_input = &buffer->gain_normalized_input_; } else { gain_normalized_input = frequency_transformed_input; } // generalized cepstrum transform // input: gain_normalized_input // output: generalized_cepstrum_transformed_output const std::vector<double>* generalized_cepstrum_transformed_output; if (input_gamma_ != output_gamma_ || num_input_order_ != num_output_order_) { if (buffer->generalized_cepstrum_transformed_output_.size() < static_cast<std::size_t>(num_output_order_ + 1)) { buffer->generalized_cepstrum_transformed_output_.resize( num_output_order_ + 1); } const double* c1(&(*gain_normalized_input)[0]); double* c2(&(buffer->generalized_cepstrum_transformed_output_[0])); c2[0] = c1[0]; for (int i(1); i <= num_output_order_; ++i) { double ss1(0.0), ss2(0.0); const int min(num_output_order_ < i ? num_output_order_ : i - 1); for (int k(1); k <= min; ++k) { int mk(i - k); double cc(c1[k] * c2[mk]); ss2 += k * cc; ss1 += mk * cc; } if (i <= num_input_order_) c2[i] = c1[i] + (output_gamma_ * ss2 - input_gamma_ * ss1) / i; else c2[i] = (output_gamma_ * ss2 - input_gamma_ * ss1) / i; } generalized_cepstrum_transformed_output = &buffer->generalized_cepstrum_transformed_output_; } else { generalized_cepstrum_transformed_output = gain_normalized_input; } // mgc2mgc output // norm=false multi=false // ignorm -> -> // norm=false multi=true // ignorm -> -> c[1-m]*g // norm=true multi=false // -> -> // norm=true multi=true // -> -> c[1-m]*g // inverse gain normalization // input: generalized_cepstrum_transformed_output // output: inverse_gain_normalized_output const std::vector<double>* inverse_gain_normalized_output; if (!is_normalized_output_) { GeneralizedCepstrumInverseGainNormalization generalized_cepstrum_inverse_gain_normalization(num_output_order_, output_gamma_); if (!generalized_cepstrum_inverse_gain_normalization.IsValid()) { return false; } if (!generalized_cepstrum_inverse_gain_normalization.Run( *generalized_cepstrum_transformed_output, &buffer->inverse_gain_normalized_output_)) { return false; } inverse_gain_normalized_output = &buffer->inverse_gain_normalized_output_; } else { inverse_gain_normalized_output = generalized_cepstrum_transformed_output; } // gamma multiplication // input: inverse_gain_normalized_output // output: output if (is_multiplied_output_) { std::transform( inverse_gain_normalized_output->begin(), inverse_gain_normalized_output->end(), output->begin(), std::bind1st(std::multiplies<double>(), 1.0 / output_gamma_)); } else { std::copy(inverse_gain_normalized_output->begin(), inverse_gain_normalized_output->end(), output->begin()); } return true; } } // namespace sptk Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Makefile 12 Oct 2016 13:39:46 -0000 1.16 --- Makefile 14 Oct 2016 06:17:44 -0000 1.17 *************** *** 54,57 **** --- 54,58 ---- generalized_cepstrum_gain_normalization.cc \ generalized_cepstrum_inverse_gain_normalization.cc \ + generalized_cepstrum_transform.cc \ input_source_from_stream.cc \ input_source_interpolation.cc \ Index: input_source_preprocessing_for_filter_gain.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/input_source_preprocessing_for_filter_gain.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** input_source_preprocessing_for_filter_gain.cc 12 Oct 2016 12:14:38 -0000 1.3 --- input_source_preprocessing_for_filter_gain.cc 14 Oct 2016 06:17:44 -0000 1.4 *************** *** 61,64 **** --- 61,71 ---- switch (gain_type_) { + case InputSourcePreprocessingForFilterGain::FilterGainType::kLinear: { + break; + } + case InputSourcePreprocessingForFilterGain::FilterGainType::kLog: { + buffer->at(0) = std::exp(buffer->at(0)); + break; + } case InputSourcePreprocessingForFilterGain::FilterGainType::kUnity: { buffer->at(0) = 1.0; *************** *** 73,83 **** break; } - case InputSourcePreprocessingForFilterGain::FilterGainType::kLinear: { - break; - } - case InputSourcePreprocessingForFilterGain::FilterGainType::kLog: { - buffer->at(0) = std::exp(buffer->at(0)); - break; - } default: { return false; } } --- 80,83 ---- Index: frequency_transform.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/frequency_transform.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** frequency_transform.h 12 Oct 2016 12:14:38 -0000 1.8 --- frequency_transform.h 14 Oct 2016 06:17:44 -0000 1.9 *************** *** 67,84 **** // ! FrequencyTransform() : num_output_order_(0), alpha_(0.0) {} // virtual ~FrequencyTransform() {} - // num_output_order must be non-negative. - bool SetNumOutputOrder(int num_output_order) { - if (num_output_order < 0) return false; - num_output_order_ = num_output_order; - return true; - } - // ! void SetAlpha(double alpha) { alpha_ = alpha; } // --- 67,77 ---- // ! FrequencyTransform(int num_input_order, int num_output_order, double alpha); // virtual ~FrequencyTransform() {} // ! int GetNumInputOrder() const { return num_input_order_; } // *************** *** 89,92 **** --- 82,88 ---- // + bool IsValid() const { return is_valid_; } + + // bool Run(const std::vector<double>& minimum_phase_sequence, std::vector<double>* warped_sequence, *************** *** 95,102 **** private: // ! int num_output_order_; // ! double alpha_; // --- 91,104 ---- private: // ! const int num_input_order_; // ! const int num_output_order_; ! ! // ! const double alpha_; ! ! // ! bool is_valid_; // Index: input_source_interface.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/input_source_interface.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** input_source_interface.h 12 Oct 2016 11:13:51 -0000 1.2 --- input_source_interface.h 14 Oct 2016 06:17:44 -0000 1.3 *************** *** 56,59 **** --- 56,62 ---- // + virtual int GetSize() const = 0; + + // virtual bool IsValid() const = 0; Index: input_source_preprocessing_for_filter_gain.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/input_source_preprocessing_for_filter_gain.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** input_source_preprocessing_for_filter_gain.h 12 Oct 2016 12:14:38 -0000 1.4 --- input_source_preprocessing_for_filter_gain.h 14 Oct 2016 06:17:44 -0000 1.5 *************** *** 80,83 **** --- 80,86 ---- // + virtual int GetSize() const { return source_ ? source_->GetSize() : 0; } + + // virtual bool IsValid() const { return is_valid_; } |