From: Natsumi K. <koi...@us...> - 2017-06-02 10:41:25
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv7029 Modified Files: Makefile b2mc.cc Added Files: mel_cepstrum_to_mlsa_digital_filter_coefficients.h mel_cepstrum_to_mlsa_digital_filter_coefficients.cc mc2b.cc Log Message: add mc2b command --- NEW FILE: mel_cepstrum_to_mlsa_digital_filter_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 "mel_cepstrum_to_mlsa_digital_filter_coefficients.h" namespace sptk { MelCepstrumToMlsaDigitalFilterCoefficients:: MelCepstrumToMlsaDigitalFilterCoefficients(int num_order, double alpha) : num_order_(num_order), alpha_(alpha), is_valid_(true) { if (num_order_ < 0) { is_valid_ = false; } } bool MelCepstrumToMlsaDigitalFilterCoefficients::Run( const std::vector<double>& mel_cepstrum, std::vector<double>* mlsa_digital_filter_coefficients) const { // check inputs if (!is_valid_ || mel_cepstrum.size() != static_cast<std::size_t>(num_order_ + 1) || NULL == mlsa_digital_filter_coefficients) { return false; } // prepare memory if (mlsa_digital_filter_coefficients->size() < static_cast<std::size_t>(num_order_ + 1)) { mlsa_digital_filter_coefficients->resize(num_order_ + 1); } // get values const double* input(&(mel_cepstrum[0])); double* output(&((*mlsa_digital_filter_coefficients)[0])); output[num_order_] = input[num_order_]; for (int i(num_order_ - 1); 0 <= i; --i) { output[i] = input[i] - alpha_ * output[i + 1]; } return true; } } // namespace sptk --- NEW FILE: mel_cepstrum_to_mlsa_digital_filter_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_MEL_CEPSTRUM_TO_MLSA_DIGITAL_FILTER_COEFFICIENTS_H_ #define SPTK_SRC_MEL_CEPSTRUM_TO_MLSA_DIGITAL_FILTER_COEFFICIENTS_H_ #include <vector> // std::vector #include "sptk_utils.h" namespace sptk { class MelCepstrumToMlsaDigitalFilterCoefficients { public: // MelCepstrumToMlsaDigitalFilterCoefficients(int num_order, double alpha); // virtual ~MelCepstrumToMlsaDigitalFilterCoefficients() { } // int GetNumOrder() const { return num_order_; } // double GetAlpha() const { return alpha_; } // bool IsValid() const { return is_valid_; } // bool Run(const std::vector<double>& mel_cepstrum, std::vector<double>* mlsa_digital_filter_coefficients) const; private: // const int num_order_; // const double alpha_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(MelCepstrumToMlsaDigitalFilterCoefficients); }; } // namespace sptk #endif // SPTK_SRC_MEL_CEPSTRUM_TO_MLSA_DIGITAL_FILTER_COEFFICIENTS_H_ --- NEW FILE: mc2b.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 <getopt.h> #include <fstream> #include <iostream> #include <sstream> #include <vector> #include "mel_cepstrum_to_mlsa_digital_filter_coefficients.h" #include "sptk_utils.h" namespace { const int kDefaultNumOrder(25); const double kDefaultAlpha(0.35); void PrintUsage(std::ostream* stream) { // clang-format off *stream << std::endl; *stream << " mc2b - transform mel-cepstrum to MLSA digital filter coefficients" << std::endl; // NOLINT *stream << std::endl; *stream << " usage:" << std::endl; *stream << " mc2b [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -m m : order of mel-cepstrum [" << kDefaultNumOrder << "]" << std::endl; // NOLINT *stream << " -a a : all-pass constant [" << kDefaultAlpha << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; *stream << " MLSA filter coefficients (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; *stream << " mel-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_order(kDefaultNumOrder); double alpha(kDefaultAlpha); for (;;) { const int option_char(getopt_long(argc, argv, "m:a:h", NULL, NULL)); 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("mc2b", error_message); return 1; } break; } case 'a': { if (!sptk::ConvertStringToDouble(optarg, &alpha)) { std::ostringstream error_message; error_message << "The argument for the -a option must be numeric"; sptk::PrintErrorMessage("mc2b", 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("mc2b", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); // prepare for transformation sptk::MelCepstrumToMlsaDigitalFilterCoefficients mel_cepstrum_to_mlsa_digital_filter_coefficients(num_order, alpha); if (!mel_cepstrum_to_mlsa_digital_filter_coefficients.IsValid()) { std::ostringstream error_message; error_message << "Failed to set the condition"; sptk::PrintErrorMessage("mc2b", error_message); return 1; } const int length(num_order + 1); std::vector<double> mel_cepstrum(length); std::vector<double> mlsa_digital_filter_coefficients(length); while (sptk::ReadStream(false, 0, 0, length, &mel_cepstrum, &input_stream)) { if (!mel_cepstrum_to_mlsa_digital_filter_coefficients.Run( mel_cepstrum, &mlsa_digital_filter_coefficients)) { std::ostringstream error_message; error_message << "Failed to transform mel-cepstrum to MLSA digital " "filter coefficients"; sptk::PrintErrorMessage("mc2b", error_message); return 1; } if (!sptk::WriteStream(0, length, mlsa_digital_filter_coefficients, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write MLSA digital filter coefficients"; sptk::PrintErrorMessage("mc2b", error_message); return 1; } } return 0; } Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Makefile 26 May 2017 06:52:35 -0000 1.34 --- Makefile 2 Jun 2017 10:41:21 -0000 1.35 *************** *** 73,76 **** --- 73,77 ---- linear_predictive_coefficients_to_parcor_coefficients.cc \ m_sequence_generation.cc \ + mel_cepstrum_to_mlsa_digital_filter_coefficients.cc \ mel_generalized_cepstrum_to_spectrum.cc \ mel_generalized_cepstrum_transform.cc \ Index: b2mc.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/b2mc.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** b2mc.cc 26 May 2017 06:37:47 -0000 1.1 --- b2mc.cc 2 Jun 2017 10:41:23 -0000 1.2 *************** *** 65,69 **** *stream << " b2mc [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; ! *stream << " -m m : order of mel cepstrum [" << kDefaultNumOrder << "]" << std::endl; // NOLINT *stream << " -a a : all-pass constant [" << kDefaultAlpha << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; --- 65,69 ---- *stream << " b2mc [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; ! *stream << " -m m : order of mel-cepstrum [" << kDefaultNumOrder << "]" << std::endl; // NOLINT *stream << " -a a : all-pass constant [" << kDefaultAlpha << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; |