From: Takenori Y. <tak...@us...> - 2016-11-24 04:16:58
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv15203 Modified Files: Makefile levdur.cc lpc.cc Added Files: linear_predictive_coefficients_to_cepstrum.cc linear_predictive_coefficients_to_cepstrum.h lpc2c.cc Log Message: add lpc2c command --- NEW FILE: lpc2c.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 <unistd.h> #include <fstream> #include <iostream> #include <sstream> #include <vector> #include "linear_predictive_coefficients_to_cepstrum.h" #include "sptk_utils.h" namespace { const int kDefaultNumInputOrder(25); const int kDefaultNumOutputOrder(25); void PrintUsage(std::ostream* stream) { // clang-format off *stream << std::endl; *stream << " lpc2c - transform linear predictive coefficients to cepstrum" << std::endl; // NOLINT *stream << std::endl; *stream << " usage:" << std::endl; *stream << " lpc2c [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -m m : order of linear predictive [" << kDefaultNumInputOrder << "]" << std::endl; // NOLINT *stream << " coefficients" << std::endl; *stream << " -M M : order of cepstrum [" << kDefaultNumOutputOrder << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; *stream << " linear predictive coefficients (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; *stream << " cepstrum (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; *stream << std::endl; // clang-format on } } // namespace int main(int argc, char* argv[]) { int num_input_order(kDefaultNumInputOrder); int num_output_order(kDefaultNumOutputOrder); for (;;) { const char option_char(getopt(argc, argv, "m:M:h")); if (-1 == option_char) break; switch (option_char) { case 'm': { if (!sptk::ConvertStringToInteger(optarg, &num_input_order) || num_input_order < 0) { std::ostringstream error_message; error_message << "The argument for the -m option must be a " << "non-negative integer"; sptk::PrintErrorMessage("lpc2c", error_message); return 1; } break; } case 'M': { if (!sptk::ConvertStringToInteger(optarg, &num_output_order) || num_output_order < 0) { std::ostringstream error_message; error_message << "The argument for the -M option must be a " << "non-negative integer"; sptk::PrintErrorMessage("lpc2c", error_message); return 1; } break; } case 'h': { PrintUsage(&std::cout); return 0; } default: { PrintUsage(&std::cerr); return 1; } } } // get input file const char* input_file((optind < argc) ? argv[argc - 1] : NULL); // open stream std::ifstream ifs; ifs.open(input_file, std::ios::in | std::ios::binary); if (ifs.fail() && NULL != input_file) { std::ostringstream error_message; error_message << "Cannot open file " << input_file; sptk::PrintErrorMessage("lpc2c", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); // prepare for frequency transform sptk::LinearPredictiveCoefficientsToCepstrum linear_predictive_coefficients_to_cepstrum(num_input_order, num_output_order); if (!linear_predictive_coefficients_to_cepstrum.IsValid()) { std::ostringstream error_message; error_message << "Failed to set the condition of input/output orders"; sptk::PrintErrorMessage("lpc2c", error_message); return 1; } const int input_length(num_input_order + 1); const int output_length(num_output_order + 1); std::vector<double> linear_predictive_coefficients(input_length); std::vector<double> cepstrum(output_length); while (sptk::ReadStream(false, input_length, &linear_predictive_coefficients, &input_stream)) { if (!linear_predictive_coefficients_to_cepstrum.Run( linear_predictive_coefficients, &cepstrum)) { std::ostringstream error_message; error_message << "Failed to convert linear predictive coefficients to cepstrum"; sptk::PrintErrorMessage("lpc2c", error_message); return 1; } if (!sptk::WriteStream(output_length, cepstrum, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write an output sequence"; sptk::PrintErrorMessage("lpc2c", error_message); return 1; } } return 0; } Index: lpc.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/lpc.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** lpc.cc 12 Oct 2016 12:14:38 -0000 1.3 --- lpc.cc 24 Nov 2016 04:16:56 -0000 1.4 *************** *** 69,83 **** // clang-format off *stream << std::endl; ! *stream << " lpc - LPC analysis using Levinson-Durbin recursion" << std::endl; *stream << std::endl; *stream << " usage:" << std::endl; *stream << " lpc [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; ! *stream << " -l l : frame length [" << kDefaultFrameLength << "]" << std::endl; // NOLINT ! *stream << " -m m : order of LP coefficients [" << kDefaultNumOrder << "]" << std::endl; // NOLINT ! *stream << " -f f : minimum value of the determinant of [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " the normal matrix" << std::endl; ! *stream << " -c c : check whether the derived LP [0]" << std::endl; // NOLINT ! *stream << " coefficients are stable or not" << std::endl; *stream << " 0 (the check is not performed)" << std::endl; *stream << " 1 (if the coefficients are unstable," << std::endl; // NOLINT --- 69,83 ---- // clang-format off *stream << std::endl; ! *stream << " lpc - linear predictive coding using Levinson-Durbin recursion" << std::endl; // NOLINT *stream << std::endl; *stream << " usage:" << std::endl; *stream << " lpc [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; ! *stream << " -l l : frame length [" << kDefaultFrameLength << "]" << std::endl; // NOLINT ! *stream << " -m m : order of linear predictive coefficients [" << kDefaultNumOrder << "]" << std::endl; // NOLINT ! *stream << " -f f : minimum value of the determinant of [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " the normal matrix" << std::endl; ! *stream << " -c c : check whether the derived linear [0]" << std::endl; // NOLINT ! *stream << " predictive coefficients are stable" << std::endl; *stream << " 0 (the check is not performed)" << std::endl; *stream << " 1 (if the coefficients are unstable," << std::endl; // NOLINT *************** *** 88,94 **** *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; ! *stream << " windowed sequence (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; ! *stream << " LP coefficients (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; --- 88,94 ---- *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; ! *stream << " windowed sequence (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; ! *stream << " linear predictive coefficients (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; *************** *** 192,196 **** if (!autocorrelation.SetNumOrder(num_order)) { std::ostringstream error_message; ! error_message << "Failed to set the order of LP coefficients"; sptk::PrintErrorMessage("lpc", error_message); return 1; --- 192,196 ---- if (!autocorrelation.SetNumOrder(num_order)) { std::ostringstream error_message; ! error_message << "Failed to set the number of orders"; sptk::PrintErrorMessage("lpc", error_message); return 1; *************** *** 240,244 **** &std::cout)) { std::ostringstream error_message; ! error_message << "Failed to write LP coefficients"; sptk::PrintErrorMessage("lpc", error_message); return 1; --- 240,244 ---- &std::cout)) { std::ostringstream error_message; ! error_message << "Failed to write linear predictive coefficients"; sptk::PrintErrorMessage("lpc", error_message); return 1; Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Makefile 26 Oct 2016 08:18:58 -0000 1.18 --- Makefile 24 Nov 2016 04:16:55 -0000 1.19 *************** *** 61,64 **** --- 61,65 ---- input_source_preprocessing_for_filter_gain.cc \ levinson_durbin_recursion.cc \ + linear_predictive_coefficients_to_cepstrum.cc \ m_sequence_generation.cc \ normal_distributed_random_value_generation.cc \ Index: levdur.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/levdur.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** levdur.cc 12 Oct 2016 12:14:38 -0000 1.4 --- levdur.cc 24 Nov 2016 04:16:55 -0000 1.5 *************** *** 76,81 **** *stream << " -f f : minimum value of the determinant of [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " the normal matrix" << std::endl; ! *stream << " -c c : check whether the derived LP [0]" << std::endl; // NOLINT ! *stream << " coefficients are stable or not" << std::endl; *stream << " 0 (the check is not performed)" << std::endl; *stream << " 1 (if the coefficients are unstable," << std::endl; // NOLINT --- 76,81 ---- *stream << " -f f : minimum value of the determinant of [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " the normal matrix" << std::endl; ! *stream << " -c c : check whether the derived linear [0]" << std::endl; // NOLINT ! *stream << " predictive coefficients are stable" << std::endl; *stream << " 0 (the check is not performed)" << std::endl; *stream << " 1 (if the coefficients are unstable," << std::endl; // NOLINT *************** *** 88,92 **** *stream << " autocorrelation sequence (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; ! *stream << " LP coefficients (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; --- 88,92 ---- *stream << " autocorrelation sequence (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; ! *stream << " linear predictive coefficients (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; *************** *** 210,214 **** &std::cout)) { std::ostringstream error_message; ! error_message << "Failed to write LP coefficients"; sptk::PrintErrorMessage("levdur", error_message); return 1; --- 210,214 ---- &std::cout)) { std::ostringstream error_message; ! error_message << "Failed to write linear predictive coefficients"; sptk::PrintErrorMessage("levdur", error_message); return 1; --- NEW FILE: linear_predictive_coefficients_to_cepstrum.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_LINEAR_PREDICTIVE_COEFFICIENTS_TO_CEPSTRUM_H_ #define SPTK_SRC_LINEAR_PREDICTIVE_COEFFICIENTS_TO_CEPSTRUM_H_ #include <vector> // std::vector #include "sptk_utils.h" namespace sptk { class LinearPredictiveCoefficientsToCepstrum { public: // LinearPredictiveCoefficientsToCepstrum(int num_input_order, int num_output_order); // virtual ~LinearPredictiveCoefficientsToCepstrum() { } // int GetNumInputOrder() const { return num_input_order_; } // int GetNumOutputOrder() const { return num_output_order_; } // bool IsValid() const { return is_valid_; } // bool Run(const std::vector<double>& linear_predictive_coefficients, std::vector<double>* cepstrum) const; private: // const int num_input_order_; // const int num_output_order_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(LinearPredictiveCoefficientsToCepstrum); }; } // namespace sptk #endif // SPTK_SRC_LINEAR_PREDICTIVE_COEFFICIENTS_TO_CEPSTRUM_H_ --- NEW FILE: linear_predictive_coefficients_to_cepstrum.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 "linear_predictive_coefficients_to_cepstrum.h" #include <cmath> // std::isfinite, std::log #include <cstring> // std::size_t namespace sptk { LinearPredictiveCoefficientsToCepstrum::LinearPredictiveCoefficientsToCepstrum( int num_input_order, int num_output_order) : num_input_order_(num_input_order), num_output_order_(num_output_order), is_valid_(true) { if (num_input_order_ < 0 || num_output_order_ < 0) { is_valid_ = false; } } bool LinearPredictiveCoefficientsToCepstrum::Run( const std::vector<double>& linear_predictive_coefficients, std::vector<double>* cepstrum) const { // check inputs if (!is_valid_ || linear_predictive_coefficients.size() != static_cast<std::size_t>(num_input_order_ + 1) || NULL == cepstrum) { return false; } // prepare memory const int output_length(num_output_order_ + 1); if (cepstrum->size() < static_cast<std::size_t>(output_length)) { cepstrum->resize(output_length); } // get values const double* input(&(linear_predictive_coefficients[0])); double* output(&((*cepstrum)[0])); output[0] = std::log(input[0]); if (0 == num_output_order_) return true; output[1] = -input[1]; for (int n(2); n <= num_output_order_; ++n) { double sum(0.0); const int k_first((num_input_order_ < n) ? (n - num_input_order_) : 1); for (int k(k_first); k < n; ++k) { sum -= k * output[k] * input[n - k]; } output[n] = sum / n; if (n <= num_input_order_) { output[n] -= input[n]; } } return true; } } // namespace sptk |