From: Natsumi K. <koi...@us...> - 2017-05-26 06:37:49
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv11545 Added Files: mlsa_digital_filter_coefficients_to_mel_cepstrum.h mlsa_digital_filter_coefficients_to_mel_cepstrum.cc b2mc.cc Log Message: add b2mc command --- NEW FILE: mlsa_digital_filter_coefficients_to_mel_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-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 "mlsa_digital_filter_coefficients_to_mel_cepstrum.h" namespace sptk { MlsaDigitalFilterCoefficientsToMelCepstrum:: MlsaDigitalFilterCoefficientsToMelCepstrum(int num_order, double alpha) : num_order_(num_order), alpha_(alpha), is_valid_(true) { if (num_order_ < 0) { is_valid_ = false; } } bool MlsaDigitalFilterCoefficientsToMelCepstrum::Run( const std::vector<double>& mlsa_digital_filter_coefficients, std::vector<double>* mel_cepstrum) const { // check inputs if (!is_valid_ || mlsa_digital_filter_coefficients.size() != static_cast<std::size_t>(num_order_ + 1) || NULL == mel_cepstrum) { return false; } // prepare memory if (mel_cepstrum->size() < static_cast<std::size_t>(num_order_ + 1)) { mel_cepstrum->resize(num_order_ + 1); } // get values const double* input(&(mlsa_digital_filter_coefficients[0])); double* output(&((*mel_cepstrum)[0])); output[num_order_] = input[num_order_]; for (int i(num_order_ - 1); 0 <= i; --i) { output[i] = input[i] + alpha_ * input[i + 1]; } return true; } } // namespace sptk --- NEW FILE: mlsa_digital_filter_coefficients_to_mel_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-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_MLSA_DIGITAL_FILTER_COEFFICIENTS_TO_MEL_CEPSTRUM_H_ #define SPTK_SRC_MLSA_DIGITAL_FILTER_COEFFICIENTS_TO_MEL_CEPSTRUM_H_ #include <vector> // std::vector #include "sptk_utils.h" namespace sptk { class MlsaDigitalFilterCoefficientsToMelCepstrum { public: // MlsaDigitalFilterCoefficientsToMelCepstrum(int num_order, double alpha); // virtual ~MlsaDigitalFilterCoefficientsToMelCepstrum() { } // int GetNumOrder() const { return num_order_; } // double GetAlpha() const { return alpha_; } // bool IsValid() const { return is_valid_; } // bool Run(const std::vector<double>& mlsa_digital_filter_coefficients, std::vector<double>* mel_cepstrum) const; private: // const int num_order_; // const double alpha_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(MlsaDigitalFilterCoefficientsToMelCepstrum); }; } // namespace sptk #endif // SPTK_SRC_MLSA_DIGITAL_FILTER_COEFFICIENTS_TO_MEL_CEPSTRUM_H_ --- NEW FILE: b2mc.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 "mlsa_digital_filter_coefficients_to_mel_cepstrum.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 << " b2mc - transform MLSA digital filter coefficients to mel-cepstrum" << std::endl; // NOLINT *stream << std::endl; *stream << " usage:" << std::endl; *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; *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("b2mc", 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("b2mc", 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("b2mc", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); // prepare for transformation sptk::MlsaDigitalFilterCoefficientsToMelCepstrum mlsa_digital_filter_coefficients_to_mel_cepstrum(num_order, alpha); if (!mlsa_digital_filter_coefficients_to_mel_cepstrum.IsValid()) { std::ostringstream error_message; error_message << "Failed to set the condition"; sptk::PrintErrorMessage("b2mc", error_message); return 1; } const int length(num_order + 1); std::vector<double> mlsa_digital_filter_coefficients(length); std::vector<double> mel_cepstrum(length); while (sptk::ReadStream(false, 0, 0, length, &mlsa_digital_filter_coefficients, &input_stream)) { if (!mlsa_digital_filter_coefficients_to_mel_cepstrum.Run( mlsa_digital_filter_coefficients, &mel_cepstrum)) { std::ostringstream error_message; error_message << "Failed to transform MLSA digital filter coefficients " "to mel-cepstrum"; sptk::PrintErrorMessage("b2mc", error_message); return 1; } if (!sptk::WriteStream(0, length, mel_cepstrum, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write mel-cepstrum"; sptk::PrintErrorMessage("b2mc", error_message); return 1; } } return 0; } |