Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv7879 Added Files: mel_generalized_cepstrum_to_spectrum.cc mel_generalized_cepstrum_to_spectrum.h mel_generalized_cepstrum_transform.cc mel_generalized_cepstrum_transform.h mel_generalized_line_spectral_pairs_to_spectrum.cc mel_generalized_line_spectral_pairs_to_spectrum.h mglsp2sp.cc Removed Files: generalized_cepstrum_to_spectrum.cc generalized_cepstrum_to_spectrum.h generalized_cepstrum_transform.cc generalized_cepstrum_transform.h line_spectral_pairs_to_spectrum.cc line_spectral_pairs_to_spectrum.h lsp2sp.cc Log Message: rename files --- generalized_cepstrum_transform.h DELETED --- --- NEW FILE: mel_generalized_cepstrum_to_spectrum.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 "mel_generalized_cepstrum_to_spectrum.h" namespace sptk { MelGeneralizedCepstrumToSpectrum::MelGeneralizedCepstrumToSpectrum( int num_order, double alpha, double gamma, bool is_normalized, bool is_multiplied, int fft_size) : mel_generalized_cepstrum_transform_(num_order, alpha, gamma, is_normalized, is_multiplied, fft_size / 2, 0.0, 0.0, false, false), fast_fourier_transform_(fft_size / 2, fft_size, false), is_valid_(true) { if (!mel_generalized_cepstrum_transform_.IsValid() || !fast_fourier_transform_.IsValid()) { is_valid_ = false; } } bool MelGeneralizedCepstrumToSpectrum::Run( const std::vector<double>& mel_generalized_cepstrum, std::vector<double>* amplitude_spectrum, std::vector<double>* phase_spectrum, MelGeneralizedCepstrumToSpectrum::Buffer* buffer) const { if (!is_valid_ || mel_generalized_cepstrum.size() != static_cast<std::size_t>(GetNumOrder() + 1) || NULL == amplitude_spectrum || NULL == phase_spectrum || NULL == buffer) { return false; } if (!mel_generalized_cepstrum_transform_.Run( mel_generalized_cepstrum, &buffer->cepstrum_, &buffer->mel_generalized_cepstrum_transform_buffer_) || !fast_fourier_transform_.Run(buffer->cepstrum_, amplitude_spectrum, phase_spectrum, &buffer->fast_fourier_transform_buffer_)) { return false; } return true; } } // namespace sptk --- NEW FILE: mel_generalized_cepstrum_to_spectrum.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_MEL_GENERALIZED_CEPSTRUM_TO_SPECTRUM_H_ #define SPTK_SRC_MEL_GENERALIZED_CEPSTRUM_TO_SPECTRUM_H_ #include <vector> // std::vector #include "fast_fourier_transform_for_real_sequence.h" #include "mel_generalized_cepstrum_transform.h" #include "sptk_utils.h" namespace sptk { class MelGeneralizedCepstrumToSpectrum { public: class Buffer { public: Buffer() { } virtual ~Buffer() { } private: MelGeneralizedCepstrumTransform::Buffer mel_generalized_cepstrum_transform_buffer_; FastFourierTransformForRealSequence::Buffer fast_fourier_transform_buffer_; std::vector<double> cepstrum_; friend class MelGeneralizedCepstrumToSpectrum; DISALLOW_COPY_AND_ASSIGN(Buffer); }; // MelGeneralizedCepstrumToSpectrum(int num_order, double alpha, double gamma, bool is_normalized, bool is_multiplied, int fft_size); // virtual ~MelGeneralizedCepstrumToSpectrum() { } // int GetNumOrder() const { return mel_generalized_cepstrum_transform_.GetNumInputOrder(); } // double GetAlpha() const { return mel_generalized_cepstrum_transform_.GetInputAlpha(); } // double GetGamma() const { return mel_generalized_cepstrum_transform_.GetInputGamma(); } // bool IsNormalized() const { return mel_generalized_cepstrum_transform_.IsNormalizedInput(); } // bool IsMultiplied() const { return mel_generalized_cepstrum_transform_.IsMultipliedInput(); } // int GetFftSize() const { return fast_fourier_transform_.GetFftSize(); } // bool IsValid() const { return is_valid_; } // bool Run(const std::vector<double>& mel_generalized_cepstrum, std::vector<double>* amplitude_spectrum, std::vector<double>* phase_spectrum, MelGeneralizedCepstrumToSpectrum::Buffer* buffer) const; private: // const MelGeneralizedCepstrumTransform mel_generalized_cepstrum_transform_; // const FastFourierTransformForRealSequence fast_fourier_transform_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(MelGeneralizedCepstrumToSpectrum); }; } // namespace sptk #endif // SPTK_SRC_MEL_GENERALIZED_CEPSTRUM_TO_SPECTRUM_H_ --- NEW FILE: mel_generalized_line_spectral_pairs_to_spectrum.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_generalized_line_spectral_pairs_to_spectrum.h" #include <cmath> // std::atan, std::cos, std::fabs, std::sin #include <cstddef> // std::size_t namespace sptk { MelGeneralizedLineSpectralPairsToSpectrum:: MelGeneralizedLineSpectralPairsToSpectrum(int num_input_order, double alpha, double gamma, int num_output_order) : num_input_order_(num_input_order), alpha_(alpha), gamma_(gamma), num_output_order_(num_output_order), is_valid_(true) { if (num_input_order < 0 || num_output_order < 0 || gamma < -1.0 || 0.0 <= gamma) { is_valid_ = false; } } bool MelGeneralizedLineSpectralPairsToSpectrum::Run( const std::vector<double>& mel_generalized_line_spectral_pairs, std::vector<double>* spectrum) const { if (!is_valid_ || mel_generalized_line_spectral_pairs.size() != static_cast<std::size_t>(num_input_order_ + 1) || NULL == spectrum) { return false; } // prepare memory const int output_length(num_output_order_ + 1); if (spectrum->size() < static_cast<std::size_t>(output_length)) { spectrum->resize(output_length); } // get values const double* input(&(mel_generalized_line_spectral_pairs[0])); double* output(&((*spectrum)[0])); // set value const bool is_odd(num_input_order_ % 2 == 1); const double c1(is_odd ? (num_input_order_ - 1) * sptk::kLogTwo : num_input_order_ * sptk::kLogTwo); const double c2(0.5 / gamma_); const double delta(0 == num_output_order_ ? 0.0 : sptk::kPi / num_output_order_); double omega(0.0); for (int j(0); j < output_length; ++j, omega += delta) { const double warped_omega( 0.0 == alpha_ ? omega : omega + 2.0 * std::atan(alpha_ * std::sin(omega) / (1.0 - alpha_ * std::cos(omega)))); const double cos_omega(std::cos(warped_omega)); double p(0.0); for (int i(2); i <= num_input_order_; i += 2) { p += 2.0 * sptk::FloorLog(std::fabs(cos_omega - std::cos(input[i]))); } double q(0.0); for (int i(1); i <= num_input_order_; i += 2) { q += 2.0 * sptk::FloorLog(std::fabs(cos_omega - std::cos(input[i]))); } if (is_odd) { p += 2.0 * sptk::FloorLog(std::sin(warped_omega)); } else { p += 2.0 * sptk::FloorLog(std::sin(warped_omega * 0.5)); q += 2.0 * sptk::FloorLog(std::cos(warped_omega * 0.5)); } output[j] = sptk::FloorLog(input[0]) + c2 * (c1 + sptk::AddInLogSpace(p, q)); } return true; } } // namespace sptk --- NEW FILE: mel_generalized_line_spectral_pairs_to_spectrum.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_GENERALIZED_LINE_SPECTRAL_PAIRS_TO_SPECTRUM_H_ #define SPTK_SRC_MEL_GENERALIZED_LINE_SPECTRAL_PAIRS_TO_SPECTRUM_H_ #include <vector> // std::vector #include "sptk_utils.h" namespace sptk { class MelGeneralizedLineSpectralPairsToSpectrum { public: // MelGeneralizedLineSpectralPairsToSpectrum(int num_input_order, double alpha, double gamma, int num_output_order); // virtual ~MelGeneralizedLineSpectralPairsToSpectrum() { } // int GetNumInputOrder() const { return num_input_order_; } // double GetAlpha() const { return alpha_; } // double GetGamma() const { return gamma_; } // int GetNumOutputOrder() const { return num_output_order_; } // bool IsValid() const { return is_valid_; } // Assume that the first element of line_spectral_pairs is linear gain and // the other elements are in normalized frequency (0...pi). bool Run(const std::vector<double>& line_spectral_pairs, std::vector<double>* spectrum) const; private: // const int num_input_order_; // const double alpha_; // const double gamma_; // const int num_output_order_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(MelGeneralizedLineSpectralPairsToSpectrum); }; } // namespace sptk #endif // SPTK_SRC_MEL_GENERALIZED_LINE_SPECTRAL_PAIRS_TO_SPECTRUM_H_ --- line_spectral_pairs_to_spectrum.cc DELETED --- --- generalized_cepstrum_transform.cc DELETED --- --- generalized_cepstrum_to_spectrum.cc DELETED --- --- NEW FILE: mel_generalized_cepstrum_transform.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_GENERALIZED_CEPSTRUM_TRANSFORM_H_ #define SPTK_SRC_MEL_GENERALIZED_CEPSTRUM_TRANSFORM_H_ #include <vector> // std::vector #include "frequency_transform.h" #include "sptk_utils.h" namespace sptk { class MelGeneralizedCepstrumTransform { public: class Buffer { public: Buffer() { } virtual ~Buffer() { } private: FrequencyTransform::Buffer frequency_transform_buffer_; std::vector<double> temporary_mel_generalized_cepstrum_; friend class MelGeneralizedCepstrumTransform; DISALLOW_COPY_AND_ASSIGN(Buffer); }; class ModuleInterface { public: virtual ~ModuleInterface() { } virtual bool IsValid() const = 0; virtual bool Run( const std::vector<double>& input, std::vector<double>* output, FrequencyTransform::Buffer* frequency_transform_buffer) const = 0; }; // MelGeneralizedCepstrumTransform( int num_input_order_, double input_alpha_, double input_gamma_, bool is_normalized_input_, bool is_multiplied_input_, int num_output_order_, double output_alpha_, double output_gamma_, bool is_normalized_output_, bool is_multiplied_output_); // virtual ~MelGeneralizedCepstrumTransform() { for (std::vector<MelGeneralizedCepstrumTransform::ModuleInterface*>:: iterator itr(modules_.begin()); itr != modules_.end(); ++itr) { delete (*itr); } } // int GetNumInputOrder() const { return num_input_order_; } // double GetInputAlpha() const { return input_alpha_; } // double GetInputGamma() const { return input_gamma_; } // bool IsNormalizedInput() const { return is_normalized_input_; } // bool IsMultipliedInput() const { return is_multiplied_input_; } // int GetNumOutputOrder() const { return num_output_order_; } // double GetOutputAlpha() const { return output_alpha_; } // double GetOutputGamma() const { return output_gamma_; } // bool IsNormalizedOutut() const { return is_normalized_output_; } // bool IsMultipliedOutput() const { return is_multiplied_output_; } // bool IsValid() const { return is_valid_; } // bool Run(const std::vector<double>& input, std::vector<double>* output, MelGeneralizedCepstrumTransform::Buffer* buffer) const; private: // const int num_input_order_; // const double input_alpha_; // const double input_gamma_; // const bool is_normalized_input_; // const bool is_multiplied_input_; // const int num_output_order_; // const double output_alpha_; // const double output_gamma_; // const bool is_normalized_output_; // const bool is_multiplied_output_; // double alpha_transform_; // std::vector<MelGeneralizedCepstrumTransform::ModuleInterface*> modules_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(MelGeneralizedCepstrumTransform); }; } // namespace sptk #endif // SPTK_SRC_MEL_GENERALIZED_CEPSTRUM_TRANSFORM_H_ --- NEW FILE: mel_generalized_cepstrum_transform.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 "mel_generalized_cepstrum_transform.h" #include <algorithm> // std::copy, std::transform #include <functional> // std::multiplies #include <vector> // std::vector #include "frequency_transform.h" #include "generalized_cepstrum_gain_normalization.h" #include "generalized_cepstrum_inverse_gain_normalization.h" namespace { class GainNormalizationModule : public sptk::MelGeneralizedCepstrumTransform::ModuleInterface { public: GainNormalizationModule(int num_order, double gamma) : generalized_cepstrum_gain_normalization_(num_order, gamma) { } virtual bool IsValid() const { return generalized_cepstrum_gain_normalization_.IsValid(); } virtual bool Run( const std::vector<double>& input, std::vector<double>* output, sptk::FrequencyTransform::Buffer* frequency_transform_buffer) const { if (!generalized_cepstrum_gain_normalization_.Run(input, output)) { return false; } output->resize(generalized_cepstrum_gain_normalization_.GetNumOrder() + 1); return true; } private: const sptk::GeneralizedCepstrumGainNormalization generalized_cepstrum_gain_normalization_; DISALLOW_COPY_AND_ASSIGN(GainNormalizationModule); }; class InverseGainNormalizationModule : public sptk::MelGeneralizedCepstrumTransform::ModuleInterface { public: InverseGainNormalizationModule(int num_order, double gamma) : generalized_cepstrum_inverse_gain_normalization_(num_order, gamma) { } virtual bool IsValid() const { return generalized_cepstrum_inverse_gain_normalization_.IsValid(); } virtual bool Run( const std::vector<double>& input, std::vector<double>* output, sptk::FrequencyTransform::Buffer* frequency_transform_buffer) const { if (!generalized_cepstrum_inverse_gain_normalization_.Run(input, output)) { return false; } output->resize( generalized_cepstrum_inverse_gain_normalization_.GetNumOrder() + 1); return true; } private: const sptk::GeneralizedCepstrumInverseGainNormalization generalized_cepstrum_inverse_gain_normalization_; DISALLOW_COPY_AND_ASSIGN(InverseGainNormalizationModule); }; class FrequencyTransformModule : public sptk::MelGeneralizedCepstrumTransform::ModuleInterface { public: FrequencyTransformModule(int num_input_order, int num_output_order, double alpha_transform) : frequency_transform_(num_input_order, num_output_order, alpha_transform) { } virtual bool IsValid() const { return frequency_transform_.IsValid(); } virtual bool Run( const std::vector<double>& input, std::vector<double>* output, sptk::FrequencyTransform::Buffer* frequency_transform_buffer) const { if (!frequency_transform_.Run(input, output, frequency_transform_buffer)) { return false; } output->resize(frequency_transform_.GetNumOutputOrder() + 1); return true; } private: const sptk::FrequencyTransform frequency_transform_; DISALLOW_COPY_AND_ASSIGN(FrequencyTransformModule); }; class MelGeneralizedCepstrumTransformModule : public sptk::MelGeneralizedCepstrumTransform::ModuleInterface { public: MelGeneralizedCepstrumTransformModule(int num_input_order, int num_output_order, double input_gamma, double output_gamma) : num_input_order_(num_input_order), num_output_order_(num_output_order), input_gamma_(input_gamma), output_gamma_(output_gamma) { } virtual bool IsValid() const { return true; } virtual bool Run( const std::vector<double>& input, std::vector<double>* output, sptk::FrequencyTransform::Buffer* frequency_transform_buffer) const { if (output->size() != static_cast<std::size_t>(num_output_order_ + 1)) { output->resize(num_output_order_ + 1); } const double* c1(&(input)[0]); double* c2(&((*output)[0])); c2[0] = c1[0]; for (int i(1); i <= num_output_order_; ++i) { double ss1(0.0), ss2(0.0); const int min(num_input_order_ < i ? num_input_order_ : i - 1); for (int k(1); k <= min; ++k) { const int mk(i - k); const double cc(c1[k] * c2[mk]); ss2 += k * cc; ss1 += mk * cc; } if (i <= num_input_order_) c2[i] = c1[i] + (output_gamma_ * ss2 - input_gamma_ * ss1) / i; else c2[i] = (output_gamma_ * ss2 - input_gamma_ * ss1) / i; } return true; } private: const int num_input_order_; const int num_output_order_; const double input_gamma_; const double output_gamma_; DISALLOW_COPY_AND_ASSIGN(MelGeneralizedCepstrumTransformModule); }; class GammaDivisionModule : public sptk::MelGeneralizedCepstrumTransform::ModuleInterface { public: GammaDivisionModule(int num_order, double gamma) : num_order_(num_order), gamma_(gamma) { } virtual bool IsValid() const { return true; } virtual bool Run( const std::vector<double>& input, std::vector<double>* output, sptk::FrequencyTransform::Buffer* frequency_transform_buffer) const { if (output->size() != static_cast<std::size_t>(num_order_ + 1)) { output->resize(num_order_ + 1); } // c[0] is not changed *(output->begin()) = *(input.begin()); // c[1-m] /= g std::transform(++(input.begin()), input.end(), ++(output->begin()), std::bind1st(std::multiplies<double>(), 1.0 / gamma_)); return true; } private: const int num_order_; const double gamma_; DISALLOW_COPY_AND_ASSIGN(GammaDivisionModule); }; class GammaMultiplicationModule : public sptk::MelGeneralizedCepstrumTransform::ModuleInterface { public: GammaMultiplicationModule(int num_order, double gamma) : num_order_(num_order), gamma_(gamma) { } virtual bool IsValid() const { return true; } virtual bool Run( const std::vector<double>& input, std::vector<double>* output, sptk::FrequencyTransform::Buffer* frequency_transform_buffer) const { if (output->size() != static_cast<std::size_t>(num_order_ + 1)) { output->resize(num_order_ + 1); } // copy c[0] *(output->begin()) = *(input.begin()); // c[1-m] *= g std::transform(++(input.begin()), input.end(), ++(output->begin()), std::bind1st(std::multiplies<double>(), gamma_)); return true; } private: const int num_order_; const double gamma_; DISALLOW_COPY_AND_ASSIGN(GammaMultiplicationModule); }; } // namespace namespace sptk { MelGeneralizedCepstrumTransform::MelGeneralizedCepstrumTransform( int num_input_order, double input_alpha, double input_gamma, bool is_normalized_input, bool is_multiplied_input, int num_output_order, double output_alpha, double output_gamma, bool is_normalized_output, bool is_multiplied_output) : num_input_order_(num_input_order), input_alpha_(input_alpha), input_gamma_(input_gamma), is_normalized_input_(is_normalized_input), is_multiplied_input_(is_multiplied_input), num_output_order_(num_output_order), output_alpha_(output_alpha), output_gamma_(output_gamma), is_normalized_output_(is_normalized_output), is_multiplied_output_(is_multiplied_output), alpha_transform_(0.0), is_valid_(true) { if (num_input_order_ < 0 || num_output_order_ < 0 || (input_alpha_ != output_alpha_ && 1.0 == input_alpha_ * output_alpha_) || (is_multiplied_input && 0.0 == input_gamma_)) { is_valid_ = false; return; } if (input_alpha_ != output_alpha_) { alpha_transform_ = (output_alpha_ - input_alpha_) / (1.0 - input_alpha_ * output_alpha_); } // ch_a: change alpha // norm_i: normalized input // norm_o: normalized output // ch_g: change gamma // ch_m: change order // ch_a=F norm_i=F norm_o=F ch_g=F ch_m=F // -> -> -> -> // ch_a=F norm_i=F norm_o=F ch_g=F ch_m=T // -> -> gnorm -> gc2gc -> ignorm // ch_a=F norm_i=F norm_o=F ch_g=T ch_m=F // -> -> gnorm -> gc2gc -> ignorm // ch_a=F norm_i=F norm_o=F ch_g=T ch_m=T // -> -> gnorm -> gc2gc -> ignorm // ch_a=F norm_i=F norm_o=T ch_g=F ch_m=F // -> -> gnorm -> -> // ch_a=F norm_i=F norm_o=T ch_g=F ch_m=T // -> -> gnorm -> gc2gc -> // ch_a=F norm_i=F norm_o=T ch_g=T ch_m=F // -> -> gnorm -> gc2gc -> // ch_a=F norm_i=F norm_o=T ch_g=T ch_m=T // -> -> gnorm -> gc2gc -> // ch_a=F norm_i=T norm_o=F ch_g=F ch_m=F // -> -> -> -> ignorm // ch_a=F norm_i=T norm_o=F ch_g=F ch_m=T // -> -> -> gc2gc -> ignorm // ch_a=F norm_i=T norm_o=F ch_g=T ch_m=F // -> -> -> gc2gc -> ignorm // ch_a=F norm_i=T norm_o=F ch_g=T ch_m=T // -> -> -> gc2gc -> ignorm // ch_a=F norm_i=T norm_o=T ch_g=F ch_m=F // -> -> -> -> // ch_a=F norm_i=T norm_o=T ch_g=F ch_m=T // -> -> -> gc2gc -> // ch_a=F norm_i=T norm_o=T ch_g=T ch_m=F // -> -> -> gc2gc -> // ch_a=F norm_i=T norm_o=T ch_g=T ch_m=T // -> -> -> gc2gc -> // ch_a=T norm_i=F norm_o=F ch_g=F ch_m=F // -> freqt -> -> -> // ch_a=T norm_i=F norm_o=F ch_g=F ch_m=T // -> freqt -> -> -> // ch_a=T norm_i=F norm_o=F ch_g=T ch_m=F // -> freqt -> gnorm -> gc2gc -> ignorm // ch_a=T norm_i=F norm_o=F ch_g=T ch_m=T // -> freqt -> gnorm -> gc2gc -> ignorm // ch_a=T norm_i=F norm_o=T ch_g=F ch_m=F // -> freqt -> gnorm -> -> // ch_a=T norm_i=F norm_o=T ch_g=F ch_m=T // -> freqt -> gnorm -> -> // ch_a=T norm_i=F norm_o=T ch_g=T ch_m=F // -> freqt -> gnorm -> gc2gc -> // ch_a=T norm_i=F norm_o=T ch_g=T ch_m=T // -> freqt -> gnorm -> gc2gc -> // ch_a=T norm_i=T norm_o=F ch_g=F ch_m=F // ignorm -> freqt -> -> -> // ch_a=T norm_i=T norm_o=F ch_g=F ch_m=T // ignorm -> freqt -> -> -> // ch_a=T norm_i=T norm_o=F ch_g=T ch_m=F // ignorm -> freqt -> gnorm -> gc2gc -> ignorm // ch_a=T norm_i=T norm_o=F ch_g=T ch_m=T // ignorm -> freqt -> gnorm -> gc2gc -> ignorm // ch_a=T norm_i=T norm_o=T ch_g=F ch_m=F // ignorm -> freqt -> gnorm -> -> // ch_a=T norm_i=T norm_o=T ch_g=F ch_m=T // ignorm -> freqt -> gnorm -> -> // ch_a=T norm_i=T norm_o=T ch_g=T ch_m=F // ignorm -> freqt -> gnorm -> gc2gc -> // ch_a=T norm_i=T norm_o=T ch_g=T ch_m=T // ignorm -> freqt -> gnorm -> gc2gc -> if (0.0 == alpha_transform_) { if (num_input_order_ == num_output_order_ && input_gamma_ == output_gamma_) { if (!is_multiplied_input_ && is_multiplied_output_) modules_.push_back( new GammaMultiplicationModule(num_input_order_, input_gamma_)); if (!is_normalized_input_ && is_normalized_output_) modules_.push_back( new GainNormalizationModule(num_input_order_, input_gamma_)); if (is_normalized_input_ && !is_normalized_output_) modules_.push_back(new InverseGainNormalizationModule(num_output_order_, output_gamma_)); if (is_multiplied_input_ && !is_multiplied_output_) modules_.push_back( new GammaDivisionModule(num_output_order_, output_gamma_)); } else { if (is_multiplied_input_) modules_.push_back( new GammaDivisionModule(num_input_order_, input_gamma_)); if (!is_normalized_input_) modules_.push_back( new GainNormalizationModule(num_input_order_, input_gamma_)); modules_.push_back(new MelGeneralizedCepstrumTransformModule( num_input_order_, num_output_order_, input_gamma_, output_gamma_)); if (!is_normalized_output_) modules_.push_back(new InverseGainNormalizationModule(num_output_order_, output_gamma_)); if (is_multiplied_output_) modules_.push_back( new GammaMultiplicationModule(num_output_order_, output_gamma_)); } } else { if (is_multiplied_input_) modules_.push_back( new GammaDivisionModule(num_input_order_, input_gamma_)); if (is_normalized_input_) modules_.push_back( new InverseGainNormalizationModule(num_input_order_, input_gamma_)); modules_.push_back(new FrequencyTransformModule( num_input_order_, num_output_order_, alpha_transform_)); if (is_normalized_output_ || input_gamma_ != output_gamma_) modules_.push_back( new GainNormalizationModule(num_output_order_, input_gamma_)); if (input_gamma_ != output_gamma_) modules_.push_back(new MelGeneralizedCepstrumTransformModule( num_output_order_, num_output_order_, input_gamma_, output_gamma_)); if (!is_normalized_output_ && input_gamma_ != output_gamma_) modules_.push_back( new InverseGainNormalizationModule(num_output_order_, output_gamma_)); if (is_multiplied_output_) modules_.push_back( new GammaMultiplicationModule(num_output_order_, output_gamma_)); } for (std::vector<MelGeneralizedCepstrumTransform::ModuleInterface*>::iterator itr(modules_.begin()); itr != modules_.end(); ++itr) { if (!(*itr)->IsValid()) { is_valid_ = false; break; } } } bool MelGeneralizedCepstrumTransform::Run( const std::vector<double>& input, std::vector<double>* output, MelGeneralizedCepstrumTransform::Buffer* buffer) const { if (!is_valid_ || static_cast<std::size_t>(num_input_order_ + 1) != input.size() || NULL == output || NULL == buffer) { return false; } if (modules_.empty()) { if (output->size() < static_cast<std::size_t>(num_output_order_ + 1)) { output->resize(num_output_order_ + 1); } std::copy(input.begin(), input.end(), output->begin()); return true; } for (std::vector<MelGeneralizedCepstrumTransform::ModuleInterface*>:: const_iterator itr(modules_.begin()); itr != modules_.end(); ++itr) { if (itr != modules_.begin()) { output->swap(buffer->temporary_mel_generalized_cepstrum_); } if (!(*itr)->Run((itr == modules_.begin()) ? input : buffer->temporary_mel_generalized_cepstrum_, output, &(buffer->frequency_transform_buffer_))) { return false; } } return true; } } // namespace sptk --- generalized_cepstrum_to_spectrum.h DELETED --- --- lsp2sp.cc DELETED --- --- line_spectral_pairs_to_spectrum.h DELETED --- --- NEW FILE: mglsp2sp.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 <algorithm> #include <cmath> #include <fstream> #include <functional> #include <iostream> #include <sstream> #include <vector> #include "mel_generalized_line_spectral_pairs_to_spectrum.h" #include "sptk_utils.h" namespace { enum InputGainTypes { kLinearGain = 0, kLogGain, kWithoutGain, kNumInputGainTypes }; enum InputFormats { kNormalizedFrequencyInRadians = 0, kNormalizedFrequencyInCycles, kFrequencyInkHz, kFrequencyInHz, kNumInputFormats }; enum OutputFormats { kLogAmplitudeSpectrumInDecibels = 0, kLogAmplitudeSpectrum, kAmplitudeSpectrum, kPowerSpectrum, kNumOutputFormats }; const int kDefaultNumOrder(25); const double kDefaultAlpha(0.0); const double kDefaultGamma(-1.0); const int kDefaultSpectrumLength(128); const double kDefaultSamplingFrequency(10.0); const InputGainTypes kDefaultInputGainType(kLinearGain); const InputFormats kDefaultInputFormat(kNormalizedFrequencyInRadians); const OutputFormats kDefaultOutputFormat(kLogAmplitudeSpectrumInDecibels); void PrintUsage(std::ostream* stream) { // clang-format off *stream << std::endl; *stream << " mglsp2sp - transform mel-generalized line spectral pairs to spectrum" << std::endl; *stream << std::endl; *stream << " usage:" << std::endl; *stream << " mglsp2sp [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -m m : order of mel-generalized line spectral pairs [" << kDefaultNumOrder << "]" << std::endl; // NOLINT *stream << " -a a : alpha of mel-generalized line spectral pairs [" << kDefaultAlpha << "]" << std::endl; // NOLINT *stream << " -g g : gamma of mel-generalized line spectral pairs [" << kDefaultGamma << "]" << std::endl; // NOLINT *stream << " -c c : gamma of mel-generalized line spectral pairs = -1 / (int) c" << std::endl; // NOLINT *stream << " -l l : spectrum legnth [" << kDefaultSpectrumLength << "]" << std::endl; // NOLINT *stream << " -s s : sampling frequency [" << kDefaultSamplingFrequency << "]" << std::endl; // NOLINT *stream << " -k k : input gain type [" << kDefaultInputGainType << "]" << std::endl; // NOLINT *stream << " 0 (linear gain)" << std::endl; *stream << " 1 (log gain)" << std::endl; *stream << " 2 (without gain)" << std::endl; *stream << " -q q : input format [" << kDefaultInputFormat << "]" << std::endl; // NOLINT *stream << " 0 (normalized frequency [0...pi])" << std::endl; *stream << " 1 (normalized frequency [0...1/2])" << std::endl; *stream << " 2 (frequency [kHz])" << std::endl; *stream << " 3 (frequency [Hz])" << std::endl; *stream << " -o o : output format [" << kDefaultOutputFormat << "]" << std::endl; // NOLINT *stream << " 0 (20*log|H(z)|)" << std::endl; *stream << " 1 (ln|H(z)|)" << std::endl; *stream << " 2 (|H(z)|)" << std::endl; *stream << " 3 (|H(z)|^2)" << std::endl; *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; *stream << " mel-generalized line spectral pairs (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; *stream << " spectrum (double)" << std::endl; *stream << " notice:" << std::endl; *stream << " if k is 2, input length in a frame is assumed to be m instead of m+1" << std::endl; // NOLINT *stream << " value of c must be c >= 1" << std::endl; *stream << " value of g must be 0 > g >= -1" << 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); double gamma(kDefaultGamma); int spectrum_length(kDefaultSpectrumLength); double sampling_frequency(kDefaultSamplingFrequency); InputGainTypes input_gain_type(kDefaultInputGainType); InputFormats input_format(kDefaultInputFormat); OutputFormats output_format(kDefaultOutputFormat); for (;;) { const int option_char( getopt_long(argc, argv, "m:a:g:c:l:s:k:q:o: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("mglsp2sp", 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("mglsp2sp", error_message); return 1; } break; } case 'g': { const int min(-1.0); const int max(0.0); if (!sptk::ConvertStringToDouble(optarg, &gamma) || gamma < min || max <= gamma) { std::ostringstream error_message; error_message << "The argument for the -g option must be numeric " << "in the range of " << min << " to " << max; sptk::PrintErrorMessage("mglsp2sp", error_message); return 1; } break; } case 'c': { int tmp; if (!sptk::ConvertStringToInteger(optarg, &tmp) || tmp < 1) { std::ostringstream error_message; error_message << "The argument for the -c option must be a " << "positive integer"; sptk::PrintErrorMessage("mglsp2sp", error_message); return 1; } gamma = -1.0 / tmp; break; } case 'l': { if (!sptk::ConvertStringToInteger(optarg, &spectrum_length) || spectrum_length <= 0) { std::ostringstream error_message; error_message << "The argument for the -l option must be a positive integer"; sptk::PrintErrorMessage("mglsp2sp", error_message); return 1; } break; } case 's': { if (!sptk::ConvertStringToDouble(optarg, &sampling_frequency) || sampling_frequency <= 0.0) { std::ostringstream error_message; error_message << "The argument for the -s option must be a positive number"; sptk::PrintErrorMessage("mglsp2sp", error_message); return 1; } break; } case 'k': { const int min(0); const int max(static_cast<int>(kNumInputGainTypes) - 1); int tmp; if (!sptk::ConvertStringToInteger(optarg, &tmp) || !sptk::IsInRange(tmp, min, max)) { std::ostringstream error_message; error_message << "The argument for the -k option must be an integer " << "in the range of " << min << " to " << max; sptk::PrintErrorMessage("mglsp2sp", error_message); return 1; } input_gain_type = static_cast<InputGainTypes>(tmp); break; } case 'q': { const int min(0); const int max(static_cast<int>(kNumInputFormats) - 1); int tmp; if (!sptk::ConvertStringToInteger(optarg, &tmp) || !sptk::IsInRange(tmp, min, max)) { std::ostringstream error_message; error_message << "The argument for the -q option must be an integer " << "in the range of " << min << " to " << max; sptk::PrintErrorMessage("mglsp2sp", error_message); return 1; } input_format = static_cast<InputFormats>(tmp); break; } case 'o': { const int min(0); const int max(static_cast<int>(kNumOutputFormats) - 1); int tmp; if (!sptk::ConvertStringToInteger(optarg, &tmp) || !sptk::IsInRange(tmp, min, max)) { std::ostringstream error_message; error_message << "The argument for the -o option must be an integer " << "in the range of " << min << " to " << max; sptk::PrintErrorMessage("mglsp2sp", error_message); return 1; } output_format = static_cast<OutputFormats>(tmp); 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("mglsp2sp", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); // prepare to transform sptk::MelGeneralizedLineSpectralPairsToSpectrum mel_generalized_line_spectral_pairs_to_spectrum(num_order, alpha, gamma, spectrum_length); if (!mel_generalized_line_spectral_pairs_to_spectrum.IsValid()) { std::ostringstream error_message; error_message << "Failed to set condition for transformation"; sptk::PrintErrorMessage("mglsp2sp", error_message); return 1; } const int input_length(num_order + 1); const int output_length(spectrum_length + 1); const int read_size(kWithoutGain == input_gain_type ? num_order : input_length); const int read_point(kWithoutGain == input_gain_type ? 1 : 0); std::vector<double> mel_generalized_line_spectral_pairs(input_length); std::vector<double> spectrum(output_length); while (sptk::ReadStream(false, 0, read_point, read_size, &mel_generalized_line_spectral_pairs, &input_stream)) { switch (input_gain_type) { case kLinearGain: { // nothing to do break; } case kLogGain: { mel_generalized_line_spectral_pairs[0] = std::exp(mel_generalized_line_spectral_pairs[0]); break; } case kWithoutGain: { mel_generalized_line_spectral_pairs[0] = 1.0; break; } default: { break; } } switch (input_format) { case kNormalizedFrequencyInRadians: { // nothing to do break; } case kNormalizedFrequencyInCycles: { std::transform(mel_generalized_line_spectral_pairs.begin() + 1, mel_generalized_line_spectral_pairs.end(), mel_generalized_line_spectral_pairs.begin() + 1, std::bind1st(std::multiplies<double>(), sptk::kTwoPi)); break; } case kFrequencyInkHz: { std::transform(mel_generalized_line_spectral_pairs.begin() + 1, mel_generalized_line_spectral_pairs.end(), mel_generalized_line_spectral_pairs.begin() + 1, std::bind1st(std::multiplies<double>(), sptk::kTwoPi / sampling_frequency)); break; } case kFrequencyInHz: { std::transform(mel_generalized_line_spectral_pairs.begin() + 1, mel_generalized_... [truncated message content] |