From: fujishita t. <fjs...@us...> - 2017-01-23 05:19:38
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv5181 Modified Files: Makefile Added Files: par2lpc.cc parcor_coefficients_to_linear_predictive_coefficients.cc parcor_coefficients_to_linear_predictive_coefficients.h Log Message: add par2lpc command --- NEW FILE: parcor_coefficients_to_linear_predictive_coefficients.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-2017 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_PARCOR_COEFFICIENTS_TO_LINEAR_PREDICTIVE_COEFFICIENTS_H_ #define SPTK_SRC_PARCOR_COEFFICIENTS_TO_LINEAR_PREDICTIVE_COEFFICIENTS_H_ #include <vector> // std::vector #include "sptk_utils.h" namespace sptk { class ParcorCoefficientsToLinearPredictiveCoefficients { public: class Buffer { public: Buffer() { } virtual ~Buffer() { } private: std::vector<double> k_; friend class ParcorCoefficientsToLinearPredictiveCoefficients; DISALLOW_COPY_AND_ASSIGN(Buffer); }; // explicit ParcorCoefficientsToLinearPredictiveCoefficients(int num_order) : num_order_(num_order), is_valid_(true) { if (num_order_ < 0) { is_valid_ = false; } } // virtual ~ParcorCoefficientsToLinearPredictiveCoefficients() { } // int GetNumOrder() const { return num_order_; } // bool IsValid() const { return is_valid_; } // bool Run( const std::vector<double>& parcor_coefficients, std::vector<double>* linear_predictive_coefficients, ParcorCoefficientsToLinearPredictiveCoefficients::Buffer* buffer) const; private: // const int num_order_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(ParcorCoefficientsToLinearPredictiveCoefficients); }; } // namespace sptk #endif // SPTK_SRC_PARCOR_COEFFICIENTS_TO_LINEAR_PREDICTIVE_COEFFICIENTS_H_ --- NEW FILE: parcor_coefficients_to_linear_predictive_coefficients.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-2017 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 "parcor_coefficients_to_linear_predictive_coefficients.h" #include <algorithm> // std::copy #include <cstddef> // std::size_t namespace sptk { bool ParcorCoefficientsToLinearPredictiveCoefficients::Run( const std::vector<double>& parcor_coefficients, std::vector<double>* linear_predictive_coefficients, ParcorCoefficientsToLinearPredictiveCoefficients::Buffer* buffer) const { // check inputs if (!is_valid_ || parcor_coefficients.size() != static_cast<std::size_t>(num_order_ + 1) || NULL == linear_predictive_coefficients || NULL == buffer) { return false; } // prepare memory const int output_length(num_order_ + 1); if (linear_predictive_coefficients->size() < static_cast<std::size_t>(output_length)) { linear_predictive_coefficients->resize(output_length); } (*linear_predictive_coefficients)[0] = parcor_coefficients[0]; if (0 == num_order_) { return true; } // prepare buffer if (buffer->k_.size() < static_cast<std::size_t>(output_length)) { buffer->k_.resize(output_length); } // get value double* output(&((*linear_predictive_coefficients)[0])); // transform parcor coefficients to linear predictive coefficients std::copy(parcor_coefficients.begin(), parcor_coefficients.end(), buffer->k_.begin()); double* k(&buffer->k_[0]); for (int i(1); i <= num_order_; ++i) { for (int j(1); j < i; ++j) { output[j] = k[j] + k[i] * k[i - j]; } for (int j(1); j < i; ++j) { k[j] = output[j]; } } output[num_order_] = k[num_order_]; return true; } } // namespace sptk Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Makefile 13 Jan 2017 03:19:11 -0000 1.24 --- Makefile 23 Jan 2017 05:19:36 -0000 1.25 *************** *** 70,73 **** --- 70,74 ---- m_sequence_generation.cc \ normal_distributed_random_value_generation.cc \ + parcor_coefficients_to_linear_predictive_coefficients.cc \ sptk_utils.cc --- NEW FILE: par2lpc.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-2017 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 "parcor_coefficients_to_linear_predictive_coefficients.h" #include "sptk_utils.h" namespace { const int kDefaultNumOrder(25); void PrintUsage(std::ostream* stream) { // clang-format off *stream << std::endl; *stream << " par2lpc - transform PARCOR coefficients to linear predictive coefficients" << std::endl; // NOLINT *stream << std::endl; *stream << " usage:" << std::endl; *stream << " par2lpc [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -m m : order of linear predictive coefficients [" << kDefaultNumOrder << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; *stream << " PARCOR coefficients (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; *stream << std::endl; // clang-format on } } // namespace int main(int argc, char* argv[]) { int num_order(kDefaultNumOrder); for (;;) { const char option_char(getopt(argc, argv, "m:h")); if (-1 == option_char) break; switch (option_char) { case 'm': { if (!sptk::ConvertStringToInteger(optarg, &num_order) || num_order < 0) { std::ostringstream error_message; error_message << "The argument for the -m option must be a " << "non-negative integer"; sptk::PrintErrorMessage("par2lpc", 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("par2lpc", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); sptk::ParcorCoefficientsToLinearPredictiveCoefficients parcor_coefficients_to_linear_predictive_coefficients(num_order); sptk::ParcorCoefficientsToLinearPredictiveCoefficients::Buffer buffer; if (!parcor_coefficients_to_linear_predictive_coefficients.IsValid()) { std::ostringstream error_message; error_message << "Failed to set the condition"; sptk::PrintErrorMessage("par2lpc", error_message); return 1; } const int length(num_order + 1); std::vector<double> parcor_coefficients(length); std::vector<double> linear_predictive_coefficients(length); for (int frame_index(0); sptk::ReadStream(false, length, &parcor_coefficients, &input_stream); ++frame_index) { if (!parcor_coefficients_to_linear_predictive_coefficients.Run( parcor_coefficients, &linear_predictive_coefficients, &buffer)) { std::ostringstream error_message; error_message << "Failed to transform PARCOR coefficients to " << "linear predictive coefficients"; sptk::PrintErrorMessage("par2lpc", error_message); return 1; } if (!sptk::WriteStream(length, linear_predictive_coefficients, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write linear predictive coefficients"; sptk::PrintErrorMessage("par2lpc", error_message); return 1; } } return 0; } |