From: Keiichiro O. <ur...@us...> - 2016-10-06 10:04:48
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv24212 Modified Files: Makefile Added Files: c2mpir.cc cepstrum_to_minimum_phase_impulse_response.h cepstrum_to_minimum_phase_impulse_response.cc Log Message: add c2mpir command --- NEW FILE: cepstrum_to_minimum_phase_impulse_response.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_CEPSTRUM_TO_MINIMUM_PHASE_IMPULSE_RESPONSE_H_ #define SPTK_SRC_CEPSTRUM_TO_MINIMUM_PHASE_IMPULSE_RESPONSE_H_ #include <vector> // std::vector #include "./sptk_utils.h" namespace sptk { class CepstrumToMinimumPhaseImpulseResponse { public: // CepstrumToMinimumPhaseImpulseResponse(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; } // virtual ~CepstrumToMinimumPhaseImpulseResponse() {} // 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>& cepstrum_coefficient, std::vector<double>* minimum_phase_sequense) const; private: // int num_input_order_; // int num_output_order_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(CepstrumToMinimumPhaseImpulseResponse); }; } // namespace sptk #endif // SPTK_SRC_CEPSTRUM_TO_MINIMUM_PHASE_IMPULSE_RESPONSE_H_ --- NEW FILE: c2mpir.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 "./cepstrum_to_minimum_phase_impulse_response.h" #include "./sptk_utils.h" namespace { const int kDefaultNumInputOrder(25); const int kDefaultNumOutputOrder(255); void PrintUsage(std::ostream* stream) { *stream << std::endl; *stream << " c2mpir - cepstrum to minimum phase impulse response" << std::endl; // NOLINT *stream << std::endl; *stream << " usage:" << std::endl; *stream << " c2mpir [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -m m : order of cepstrum [" << kDefaultNumInputOrder << "]" << std::endl; // NOLINT *stream << " -M M : order of minimum phase impulse response [" << kDefaultNumOutputOrder << "]" << std::endl; // NOLINT *stream << " -l l : length of minimum phase impulse response [" << kDefaultNumOutputOrder + 1 << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; *stream << " cepstrum (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; *stream << " minimum phase impulse response (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; *stream << std::endl; } } // 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:l: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("c2mpir", 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("c2mpir", error_message); return 1; } break; } case 'l': { if (!sptk::ConvertStringToInteger(optarg, &num_output_order) || num_output_order < 1) { std::ostringstream error_message; error_message << "The argument for the -M option must be bigger than 0"; sptk::PrintErrorMessage("c2mpir", error_message); return 1; } num_output_order++; 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("freqt", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); // prepare converter sptk::CepstrumToMinimumPhaseImpulseResponse cepstrum_to_minimum_phase_impulse_response(num_input_order, num_output_order); if (!cepstrum_to_minimum_phase_impulse_response.IsValid()) { std::ostringstream error_message; error_message << "Failed to set the number of input/output orders"; sptk::PrintErrorMessage("c2mpir", error_message); return 1; } const int input_length(num_input_order + 1); const int output_length(num_output_order + 1); std::vector<double> cepstrum(input_length); std::vector<double> minimum_phase_impulse_response(output_length); while (sptk::ReadStream(false, input_length, &cepstrum, &input_stream)) { if (!cepstrum_to_minimum_phase_impulse_response.Run(cepstrum, &minimum_phase_impulse_response)) { std::ostringstream error_message; error_message << "Failed to convert cepstrum to minimum phase impulse response"; // NOLINT sptk::PrintErrorMessage("c2mpir", error_message); return 1; } if (!sptk::WriteStream(output_length, minimum_phase_impulse_response, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write an output sequence"; sptk::PrintErrorMessage("c2mpir", error_message); return 1; } } return 0; } --- NEW FILE: cepstrum_to_minimum_phase_impulse_response.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 "./cepstrum_to_minimum_phase_impulse_response.h" #include <cmath> // std::exp #include <cstring> // std::size_t namespace sptk { bool CepstrumToMinimumPhaseImpulseResponse::Run( const std::vector<double>& cepstrum_coefficient, std::vector<double>* minimum_phase_impulse_response) const { // check inputs if (cepstrum_coefficient.size() != static_cast<std::size_t>(num_input_order_+1) || NULL == minimum_phase_impulse_response || is_valid_ == false) { return false; } // prepare memory if (minimum_phase_impulse_response->size() < static_cast<std::size_t>(num_output_order_ + 1)) { minimum_phase_impulse_response->resize(num_output_order_ + 1); } const double *c = &cepstrum_coefficient[0]; double *h = &((*minimum_phase_impulse_response)[0]); int upl; double d; h[0] = std::exp(c[0]); for (int n(1); n <= num_output_order_; ++n) { d = 0; upl = (n > num_input_order_) ? num_input_order_ : n; for (int k(1); k <= upl; ++k) d += k * c[k] * h[n - k]; h[n] = d / n; } return true; } } // namespace sptk Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile 29 Jul 2016 07:26:20 -0000 1.7 --- Makefile 6 Oct 2016 10:04:46 -0000 1.8 *************** *** 46,54 **** SOURCES = all_pole_digital_filter.cc \ ! autocorrelation.cc \ ! fast_fourier_transform.cc \ ! coefficients_stream_reader.cc \ frequency_transform.cc \ ! levinson_durbin_recursion.cc \ sptk_utils.cc --- 46,55 ---- SOURCES = all_pole_digital_filter.cc \ ! autocorrelation.cc \ ! fast_fourier_transform.cc \ ! cepstrum_to_minimum_phase_impulse_response.cc \ ! coefficients_stream_reader.cc \ frequency_transform.cc \ ! levinson_durbin_recursion.cc \ sptk_utils.cc |