From: Takenori Y. <tak...@us...> - 2017-01-26 10:33:57
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv24100 Modified Files: Makefile sptk_utils.cc sptk_utils.h Added Files: linear_predictive_coefficients_to_line_spectral_pairs.cc linear_predictive_coefficients_to_line_spectral_pairs.h lpc2lsp.cc Log Message: add lpc2lsp command Index: sptk_utils.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/sptk_utils.cc,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** sptk_utils.cc 24 Jan 2017 12:29:58 -0000 1.12 --- sptk_utils.cc 26 Jan 2017 10:33:54 -0000 1.13 *************** *** 121,134 **** bool WriteStream(int write_size, const std::vector<double>& sequence_to_write, std::ostream* output_stream) { ! if (write_size <= 0 || NULL == output_stream) { return false; } ! if (sequence_to_write.size() < static_cast<std::size_t>(write_size)) { return false; } ! output_stream->write(reinterpret_cast<const char*>(&(sequence_to_write[0])), ! sizeof(sequence_to_write[0]) * write_size); return !output_stream->fail(); --- 121,141 ---- bool WriteStream(int write_size, const std::vector<double>& sequence_to_write, std::ostream* output_stream) { ! return WriteStream(0, write_size, sequence_to_write, output_stream); ! } ! ! bool WriteStream(int begin, int end, ! const std::vector<double>& sequence_to_write, ! std::ostream* output_stream) { ! if (begin < 0 || end <= begin || NULL == output_stream) { return false; } ! if (sequence_to_write.size() < static_cast<std::size_t>(end)) { return false; } ! output_stream->write( ! reinterpret_cast<const char*>(&(sequence_to_write[0]) + begin), ! sizeof(sequence_to_write[0]) * (end - begin)); return !output_stream->fail(); --- NEW FILE: linear_predictive_coefficients_to_line_spectral_pairs.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 "linear_predictive_coefficients_to_line_spectral_pairs.h" #include <cmath> // std::acos, std::ceil, std::fabs #include <cstddef> // std::size_t namespace sptk { LinearPredictiveCoefficientsToLineSpectralPairs:: LinearPredictiveCoefficientsToLineSpectralPairs(int num_order, int num_split, int num_iteration, double epsilon) : num_order_(num_order), num_symmetric_polynomial_order_(std::ceil((num_order + 1) / 2)), num_asymmetric_polynomial_order_(num_order / 2), num_split_(num_split), num_iteration_(num_iteration), epsilon_(epsilon), is_valid_(true) { if (num_order < 0 || num_split < 1 || num_iteration < 1 || epsilon < 0.0) { is_valid_ = false; } } bool LinearPredictiveCoefficientsToLineSpectralPairs::Run( const std::vector<double>& linear_predictive_coefficients, std::vector<double>* line_spectral_pairs, LinearPredictiveCoefficientsToLineSpectralPairs::Buffer* buffer) const { // check inputs if (!is_valid_ || linear_predictive_coefficients.size() != static_cast<std::size_t>(num_order_ + 1) || NULL == line_spectral_pairs || NULL == buffer) { return false; } // prepare memory if (line_spectral_pairs->size() < static_cast<std::size_t>(num_order_ + 1)) { line_spectral_pairs->resize(num_order_ + 1); } (*line_spectral_pairs)[0] = linear_predictive_coefficients[0]; if (0 == num_order_) return true; // prepare buffer if (buffer->c1_.size() < static_cast<std::size_t>(num_symmetric_polynomial_order_ + 1)) { buffer->c1_.resize(num_symmetric_polynomial_order_ + 1); } if (buffer->c2_.size() < static_cast<std::size_t>(num_asymmetric_polynomial_order_ + 1)) { buffer->c2_.resize(num_asymmetric_polynomial_order_ + 1); } // calculate symmetric and antisymmetric polynomials const double* p1(&(linear_predictive_coefficients[0]) + 1); const double* p2(&(linear_predictive_coefficients[0]) + num_order_); double* c1(&buffer->c1_[0]); double* c2(&buffer->c2_[0]); c1[num_symmetric_polynomial_order_] = 1.0; c2[num_asymmetric_polynomial_order_] = 1.0; if (num_order_ % 2 == 0) { for (int i(num_symmetric_polynomial_order_ - 1); 0 <= i; --i, ++p1, --p2) { c1[i] = *p1 + *p2 - c1[i + 1]; c2[i] = *p1 - *p2 + c2[i + 1]; } } else { for (int i(num_asymmetric_polynomial_order_ - 1); 0 <= i; --i, ++p1, --p2) { c1[i + 1] = *p1 + *p2; c2[i] = (i == num_asymmetric_polynomial_order_ - 1) ? *p1 - *p2 : *p1 - *p2 + c2[i + 2]; } c1[0] = *p1 + *p2; } c1[0] *= 0.5; c2[0] *= 0.5; // set initial condition int order(0); std::vector<double>* c(&buffer->c1_); double x_prev(1.0); double y_prev; if (!CalculateChebyshevPolynomial(*c, x_prev, &y_prev)) return false; // search roots of polynomials const double delta(1.0 / num_split_); const double x_max(1.0 - delta); const double x_min(-1.0 - delta); for (double x(x_max); x_min < x; x -= delta) { double y; if (!CalculateChebyshevPolynomial(*c, x, &y)) return false; if (y * y_prev <= 0.0) { double x_lower(x); double x_upper(x_prev); double y_lower(y); double y_upper(y_prev); for (int i(0); i < num_iteration_; ++i) { double x_mid((x_lower + x_upper) * 0.5); double y_mid; if (!CalculateChebyshevPolynomial(*c, x_mid, &y_mid)) return false; if (y_mid * y_upper <= 0.0) { x_lower = x_mid; y_lower = y_mid; } else { x_upper = x_mid; y_upper = y_mid; } if (std::fabs(y_mid) <= epsilon_) break; } const double x_interpolated((y_lower * x_upper - y_upper * x_lower) / (y_lower - y_upper)); (*line_spectral_pairs)[++order] = std::acos(x_interpolated) / sptk::kTwoPi; if (num_order_ == order) return true; // update variables c = (c == &buffer->c1_) ? &buffer->c2_ : &buffer->c1_; x = x_interpolated; if (!CalculateChebyshevPolynomial(*c, x, &y)) return false; } x_prev = x; y_prev = y; } return false; } bool LinearPredictiveCoefficientsToLineSpectralPairs:: CalculateChebyshevPolynomial(const std::vector<double>& coefficients, double x, double* y) const { if (coefficients.empty() || NULL == y) { return false; } const double* c(&coefficients[0]); double b2(0.0); double b1(0.0); for (int i(coefficients.size() - 1); 0 < i; --i) { const double b0(2.0 * x * b1 - b2 + c[i]); b2 = b1; b1 = b0; } *y = x * b1 - b2 + c[0]; return true; } } // namespace sptk Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Makefile 23 Jan 2017 05:19:36 -0000 1.25 --- Makefile 26 Jan 2017 10:33:53 -0000 1.26 *************** *** 9,13 **** # Science and Engineering # # # ! # 1996-2016 Nagoya Institute of Technology # # Department of Computer Science # # # --- 9,13 ---- # Science and Engineering # # # ! # 1996-2017 Nagoya Institute of Technology # # Department of Computer Science # # # *************** *** 67,70 **** --- 67,71 ---- levinson_durbin_recursion.cc \ linear_predictive_coefficients_to_cepstrum.cc \ + linear_predictive_coefficients_to_line_spectral_pairs.cc \ linear_predictive_coefficients_to_parcor_coefficients.cc \ m_sequence_generation.cc \ --- NEW FILE: linear_predictive_coefficients_to_line_spectral_pairs.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_LINEAR_PREDICTIVE_COEFFICIENTS_TO_LINE_SPECTRAL_PAIRS_H_ #define SPTK_SRC_LINEAR_PREDICTIVE_COEFFICIENTS_TO_LINE_SPECTRAL_PAIRS_H_ #include <vector> // std::vector #include "sptk_utils.h" namespace sptk { class LinearPredictiveCoefficientsToLineSpectralPairs { public: class Buffer { public: Buffer() { } virtual ~Buffer() { } private: std::vector<double> c1_; std::vector<double> c2_; friend class LinearPredictiveCoefficientsToLineSpectralPairs; DISALLOW_COPY_AND_ASSIGN(Buffer); }; // LinearPredictiveCoefficientsToLineSpectralPairs(int num_order, int num_split, int num_iteration, double epsilon); // virtual ~LinearPredictiveCoefficientsToLineSpectralPairs() { } // int GetNumOrder() const { return num_order_; } // int GetNumSplit() const { return num_split_; } // int GetNumIteration() const { return num_iteration_; } // double GetEpsilon() const { return epsilon_; } // bool IsValid() const { return is_valid_; } // bool Run( const std::vector<double>& linear_predictive_coefficients, std::vector<double>* line_spectral_pairs, LinearPredictiveCoefficientsToLineSpectralPairs::Buffer* buffer) const; private: // bool CalculateChebyshevPolynomial(const std::vector<double>& coefficients, double x, double* y) const; // const int num_order_; // const int num_symmetric_polynomial_order_; // const int num_asymmetric_polynomial_order_; // const int num_split_; // const int num_iteration_; // const double epsilon_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(LinearPredictiveCoefficientsToLineSpectralPairs); }; } // namespace sptk #endif // SPTK_SRC_LINEAR_PREDICTIVE_COEFFICIENTS_TO_LINE_SPECTRAL_PAIRS_H_ --- NEW FILE: lpc2lsp.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 <algorithm> #include <cmath> #include <fstream> #include <functional> #include <iostream> #include <sstream> #include <vector> #include "linear_predictive_coefficients_to_line_spectral_pairs.h" #include "sptk_utils.h" namespace { enum OutputGainTypes { kLinearGain = 0, kLogGain, kWithoutGain, kNumOutputGainTypes }; enum OutputFormats { kNormalizedFrequencyInRadians = 0, kNormalizedFrequencyInCycles, kFrequecnyInkHz, kFrequecnyInHz, kNumOutputFormats }; const int kDefaultNumOrder(25); const double kDefaultSamplingFrequency(10.0); const int kDefaultOutputGainType(kLinearGain); const int kDefaultOutputFormat(kNormalizedFrequencyInRadians); const int kDefaultNumSplit(128); const int kDefaultNumIteration(4); const double kDefaultEpsilon(1e-6); void PrintUsage(std::ostream* stream) { // clang-format off *stream << std::endl; *stream << " lpc2lsp - transform linear predictive coefficients to " << std::endl; // NOLINT *stream << " line spectral pairs" << std::endl; *stream << std::endl; *stream << " usage:" << std::endl; *stream << " lpc2lsp [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -m m : order of linear predictive coefficients [" << kDefaultNumOrder << "]" << std::endl; // NOLINT *stream << " -s s : sampling frequency [" << kDefaultSamplingFrequency << "]" << std::endl; // NOLINT *stream << " -k k : output gain type [" << kDefaultOutputGainType << "]" << std::endl; // NOLINT *stream << " 0 (linear gain)" << std::endl; *stream << " 1 (log gain)" << std::endl; *stream << " 2 (without gain)" << std::endl; *stream << " -o o : output format [" << kDefaultOutputFormat << "]" << 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 << " -h : print this message" << std::endl; *stream << " (level 2)" << std::endl; *stream << " -n n : split number of unit circle [" << kDefaultNumSplit << "]" << std::endl; // NOLINT *stream << " -i i : maximum number of interpolation [" << kDefaultNumIteration << "]" << std::endl; // NOLINT *stream << " -d d : end condition of interpolation [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " infile:" << std::endl; *stream << " linear predictive coefficients (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; *stream << " line spectral pairs (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 sampling_frequency(kDefaultSamplingFrequency); OutputGainTypes output_gain_type( static_cast<OutputGainTypes>(kDefaultOutputGainType)); OutputFormats output_format(static_cast<OutputFormats>(kDefaultOutputFormat)); int num_split(kDefaultNumSplit); int num_iteration(kDefaultNumIteration); double epsilon(kDefaultEpsilon); for (;;) { const char option_char(getopt(argc, argv, "m:s:k:o:n:i:d: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("lpc2lsp", 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("lpc2lsp", error_message); return 1; } break; } case 'k': { const int min(0); const int max(static_cast<int>(kNumOutputGainTypes) - 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("lpc2lsp", error_message); return 1; } output_gain_type = static_cast<OutputGainTypes>(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("lpc2lsp", error_message); return 1; } output_format = static_cast<OutputFormats>(tmp); break; } case 'n': { if (!sptk::ConvertStringToInteger(optarg, &num_split) || num_split <= 0) { std::ostringstream error_message; error_message << "The argument for the -n option must be a positive integer"; sptk::PrintErrorMessage("lpc2lsp", error_message); return 1; } break; } case 'i': { if (!sptk::ConvertStringToInteger(optarg, &num_iteration) || num_iteration <= 0) { std::ostringstream error_message; error_message << "The argument for the -i option must be a positive integer"; sptk::PrintErrorMessage("lpc2lsp", error_message); return 1; } break; } case 'd': { if (!sptk::ConvertStringToDouble(optarg, &epsilon) || epsilon < 0.0) { std::ostringstream error_message; error_message << "The argument for the -d option must be a non-negative number"; sptk::PrintErrorMessage("lpc2lsp", 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("lpc2lsp", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); // prepare to transform sptk::LinearPredictiveCoefficientsToLineSpectralPairs linear_predictive_coefficients_to_line_spectral_pairs( num_order, num_split, num_iteration, epsilon); sptk::LinearPredictiveCoefficientsToLineSpectralPairs::Buffer buffer; if (!linear_predictive_coefficients_to_line_spectral_pairs.IsValid()) { std::ostringstream error_message; error_message << "Failed to set condition for transformation"; sptk::PrintErrorMessage("lpc2lsp", error_message); return 1; } const int length(num_order + 1); std::vector<double> linear_predictive_coefficients(length); std::vector<double> line_spectral_pairs(length); while (sptk::ReadStream(false, length, &linear_predictive_coefficients, &input_stream)) { if (!linear_predictive_coefficients_to_line_spectral_pairs.Run( linear_predictive_coefficients, &line_spectral_pairs, &buffer)) { std::ostringstream error_message; error_message << "Failed to transform linear predictive coefficients to " "line spectral pairs"; sptk::PrintErrorMessage("lpc2lsp", error_message); return 1; } switch (output_format) { case kNormalizedFrequencyInRadians: { std::transform(line_spectral_pairs.begin() + 1, line_spectral_pairs.end(), line_spectral_pairs.begin() + 1, std::bind1st(std::multiplies<double>(), sptk::kTwoPi)); break; } case kNormalizedFrequencyInCycles: { // nothing to do break; } case kFrequecnyInkHz: { std::transform( line_spectral_pairs.begin() + 1, line_spectral_pairs.end(), line_spectral_pairs.begin() + 1, std::bind1st(std::multiplies<double>(), sampling_frequency)); break; } case kFrequecnyInHz: { std::transform(line_spectral_pairs.begin() + 1, line_spectral_pairs.end(), line_spectral_pairs.begin() + 1, std::bind1st(std::multiplies<double>(), 1000.0 * sampling_frequency)); break; } default: { break; } } if (kLogGain == output_gain_type) { line_spectral_pairs[0] = std::log(line_spectral_pairs[0]); } const int begin(kWithoutGain == output_gain_type ? 1 : 0); if (!sptk::WriteStream(begin, length, line_spectral_pairs, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write line spectral pairs"; sptk::PrintErrorMessage("lpc2lsp", error_message); return 1; } } return 0; } Index: sptk_utils.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/sptk_utils.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** sptk_utils.h 26 Dec 2016 07:41:20 -0000 1.8 --- sptk_utils.h 26 Jan 2017 10:33:54 -0000 1.9 *************** *** 61,64 **** --- 61,65 ---- static const char* const kVersion("4.0"); static const double kPi(3.141592653589793); + static const double kTwoPi(6.283185307179586); static const double kNp(8.685889638065035); // 1 Np = 20 / ln(10) dB *************** *** 70,73 **** --- 71,77 ---- bool WriteStream(int write_size, const std::vector<double>& sequence_to_write, std::ostream* output_stream); + bool WriteStream(int begin, int end, + const std::vector<double>& sequence_to_write, + std::ostream* output_stream); const char* ConvertBooleanToString(bool input); bool ConvertStringToInteger(const std::string& input, int* output); |