Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv15963 Modified Files: Makefile all_pole_digital_filter.cc all_pole_digital_filter.h levdur.cc levinson_durbin_recursion.cc levinson_durbin_recursion.h lpc.cc poledf.cc Added Files: input_source_from_stream.cc input_source_from_stream.h input_source_interface.h input_source_interpolation.cc input_source_interpolation.h input_source_preprocessing_for_filter_gain.cc input_source_preprocessing_for_filter_gain.h input_source_preprocessing_interface.h Log Message: reimplement filter interpolation --- NEW FILE: input_source_preprocessing_for_filter_gain.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 "input_source_preprocessing_for_filter_gain.h" #include <cmath> // std::exp namespace sptk { bool InputSourcePreprocessingForFilterGain::Get( std::vector<double>* buffer) { if (NULL == buffer || !is_valid_) { return false; } if (!source_->Get(buffer)) { return false; } switch (gain_type_) { case InputSourcePreprocessingForFilterGain::FilterGainType::kUnity: buffer->at(0) = 1.0; break; case InputSourcePreprocessingForFilterGain::FilterGainType::kLinear: break; case InputSourcePreprocessingForFilterGain::FilterGainType::kLog: buffer->at(0) = std::exp(buffer->at(0)); break; default: return false; } return true; } } // namespace sptk --- NEW FILE: input_source_from_stream.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_INPUT_SOURCE_FROM_STREAM_H_ #define SPTK_SRC_INPUT_SOURCE_FROM_STREAM_H_ #include <istream> // std::istream #include <vector> // std::vector #include "input_source_interface.h" #include "sptk_utils.h" namespace sptk { class InputSourceFromStream : public InputSourceInterface { public: // InputSourceFromStream(bool zero_padding, int read_size, std::istream* input_stream) : zero_padding_(zero_padding), read_size_(read_size), input_stream_(input_stream), is_valid_(false) { if (read_size <= 0 || NULL == input_stream) { return; } is_valid_ = true; } // virtual ~InputSourceFromStream() {} // virtual bool GetZeroPaddingFlag() const { return zero_padding_; } // virtual int GetReadSize() const { return read_size_; } // virtual bool IsValid() const { return is_valid_; } // virtual bool Get(std::vector<double>* buffer); private: // const bool zero_padding_; // const int read_size_; // std::istream* input_stream_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(InputSourceFromStream); }; } // namespace sptk #endif // SPTK_SRC_INPUT_SOURCE_FROM_STREAM_H_ Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Makefile 7 Oct 2016 00:47:51 -0000 1.10 --- Makefile 8 Oct 2016 15:14:58 -0000 1.11 *************** *** 46,58 **** 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 \ ! m_sequence_generation.cc \ ! normal_distributed_random_value_generation.cc \ ! sptk_utils.cc OBJECTS = $(SOURCES:.cc=.o) --- 46,60 ---- SOURCES = all_pole_digital_filter.cc \ ! autocorrelation.cc \ ! cepstrum_to_minimum_phase_impulse_response.cc \ ! fast_fourier_transform.cc \ frequency_transform.cc \ ! input_source_from_stream.cc \ ! input_source_interpolation.cc \ ! input_source_preprocessing_for_filter_gain.cc \ ! levinson_durbin_recursion.cc \ ! m_sequence_generation.cc \ ! normal_distributed_random_value_generation.cc \ ! sptk_utils.cc OBJECTS = $(SOURCES:.cc=.o) Index: lpc.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/lpc.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** lpc.cc 19 Apr 2016 04:27:10 -0000 1.1 --- lpc.cc 8 Oct 2016 15:14:59 -0000 1.2 *************** *** 74,87 **** *stream << " options:" << std::endl; *stream << " -l l : frame length [" << kDefaultFrameLength << "]" << std::endl; // NOLINT ! *stream << " -m m : order of LPC coefficients [" << kDefaultNumOrder << "]" << std::endl; // NOLINT *stream << " -f f : minimum value of the determinant of [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " the normal matrix" << std::endl; ! *stream << " -c c : check whether the derived LPC [0]" << std::endl; // NOLINT *stream << " coefficients are stable or not" << std::endl; *stream << " 0 (the check is not performed)" << std::endl; *stream << " 1 (if the coefficients are unstable," << std::endl; // NOLINT ! *stream << " output its index to stderr)" << std::endl; *stream << " 2 (if the coefficients are unstable," << std::endl; // NOLINT ! *stream << " output its index to stderr and" << std::endl; *stream << " exit immediately)" << std::endl; *stream << " -h : print this message" << std::endl; --- 74,87 ---- *stream << " options:" << std::endl; *stream << " -l l : frame length [" << kDefaultFrameLength << "]" << std::endl; // NOLINT ! *stream << " -m m : order of LP coefficients [" << kDefaultNumOrder << "]" << std::endl; // NOLINT *stream << " -f f : minimum value of the determinant of [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " the normal matrix" << std::endl; ! *stream << " -c c : check whether the derived LP [0]" << std::endl; // NOLINT *stream << " coefficients are stable or not" << std::endl; *stream << " 0 (the check is not performed)" << std::endl; *stream << " 1 (if the coefficients are unstable," << std::endl; // NOLINT ! *stream << " output the index to stderr)" << std::endl; *stream << " 2 (if the coefficients are unstable," << std::endl; // NOLINT ! *stream << " output the index to stderr and" << std::endl; *stream << " exit immediately)" << std::endl; *stream << " -h : print this message" << std::endl; *************** *** 89,93 **** *stream << " windowed sequence (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; ! *stream << " LPC coefficients (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; --- 89,93 ---- *stream << " windowed sequence (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; ! *stream << " LP coefficients (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; *************** *** 191,195 **** if (!autocorrelation.SetNumOrder(num_order)) { std::ostringstream error_message; ! error_message << "Failed to set the order of LPC coefficients"; sptk::PrintErrorMessage("lpc", error_message); return 1; --- 191,195 ---- if (!autocorrelation.SetNumOrder(num_order)) { std::ostringstream error_message; ! error_message << "Failed to set the order of LP coefficients"; sptk::PrintErrorMessage("lpc", error_message); return 1; *************** *** 208,212 **** std::vector<double> windowed_sequence(frame_length); std::vector<double> autocorrelation_sequence(output_length); ! std::vector<double> lpc_coefficients(output_length); for (int frame_index(0); --- 208,212 ---- std::vector<double> windowed_sequence(frame_length); std::vector<double> autocorrelation_sequence(output_length); ! std::vector<double> linear_predictive_coefficients(output_length); for (int frame_index(0); *************** *** 221,226 **** bool is_stable(false); ! if (!recursion.Run(autocorrelation_sequence, &lpc_coefficients, &buffer, ! &is_stable)) { std::ostringstream error_message; error_message << "Failed to solve an autocorrelation normal equation"; --- 221,226 ---- bool is_stable(false); ! if (!recursion.Run(autocorrelation_sequence, ! &linear_predictive_coefficients, &buffer, &is_stable)) { std::ostringstream error_message; error_message << "Failed to solve an autocorrelation normal equation"; *************** *** 236,242 **** } ! if (!sptk::WriteStream(output_length, lpc_coefficients, &std::cout)) { std::ostringstream error_message; ! error_message << "Failed to write LPC coefficients"; sptk::PrintErrorMessage("lpc", error_message); return 1; --- 236,243 ---- } ! if (!sptk::WriteStream(output_length, linear_predictive_coefficients, ! &std::cout)) { std::ostringstream error_message; ! error_message << "Failed to write LP coefficients"; sptk::PrintErrorMessage("lpc", error_message); return 1; --- NEW FILE: input_source_interpolation.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 "input_source_interpolation.h" #include <algorithm> // std::copy, std::transform #include <cstring> // std::size_t #include <functional> // std::plus namespace sptk { InputSourceInterpolation::InputSourceInterpolation( int frame_period, int interpolation_period, InputSourcePreprocessingInterface* source) : frame_period_(frame_period), interpolation_period_(interpolation_period), first_interpolation_period_(interpolation_period / 2), point_index_in_frame_(0), source_(source), is_valid_(false) { if (frame_period <= 0 || interpolation_period < 0 || frame_period / 2 < interpolation_period || NULL == source) { return; } if (!source_->Get(&curr_data_)) { return; } is_valid_ = true; data_length_ = curr_data_.size(); if (!source_->Get(&next_data_)) { next_data_.resize(data_length_); std::copy(curr_data_.begin(), curr_data_.end(), next_data_.begin()); } if (0 < interpolation_period_) { increment_.resize(data_length_); CalculateIncrement(); } } void InputSourceInterpolation::CalculateIncrement() { const double rate(static_cast<double>(interpolation_period_) / frame_period_); for (int i(0); i < data_length_; ++i) { increment_[i] = rate * (next_data_[i] - curr_data_[i]); } } bool InputSourceInterpolation::Get(std::vector<double>* buffer) { if (NULL == buffer || !is_valid_) { return false; } if (buffer->size() < static_cast<std::size_t>(data_length_)) { buffer->resize(data_length_); } std::copy(curr_data_.begin(), curr_data_.end(), buffer->begin()); // Update internal states for the next call. ++point_index_in_frame_; if (0 == point_index_in_frame_ % frame_period_) { // Update current and next data. std::copy(next_data_.begin(), next_data_.end(), curr_data_.begin()); if (!source_->Get(&next_data_)) { // Use the final data until the end of input sequence. std::copy(curr_data_.begin(), curr_data_.end(), next_data_.begin()); } if (0 < interpolation_period_) { CalculateIncrement(); } // Rewind point index. point_index_in_frame_ = 0; } else if (0 < interpolation_period_ && 0 == ((point_index_in_frame_ + first_interpolation_period_) % interpolation_period_)) { // Interpolate adjacent data. std::transform(curr_data_.begin(), curr_data_.end(), increment_.begin(), curr_data_.begin(), std::plus<double>()); } else if (0 == interpolation_period_ && frame_period_ / 2 == point_index_in_frame_) { std::copy(next_data_.begin(), next_data_.end(), curr_data_.begin()); } return true; } } // namespace sptk --- NEW FILE: input_source_interface.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_INPUT_SOURCE_INTERFACE_H_ #define SPTK_SRC_INPUT_SOURCE_INTERFACE_H_ #include <vector> // std::vector namespace sptk { class InputSourceInterface { public: // virtual ~InputSourceInterface() {} // virtual bool GetZeroPaddingFlag() const = 0; // virtual int GetReadSize() const = 0; // virtual bool IsValid() const = 0; // virtual bool Get(std::vector<double>* buffer) = 0; }; } // namespace sptk #endif // SPTK_SRC_INPUT_SOURCE_INTERFACE_H_ Index: all_pole_digital_filter.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/all_pole_digital_filter.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** all_pole_digital_filter.h 29 Jul 2016 07:26:20 -0000 1.2 --- all_pole_digital_filter.h 8 Oct 2016 15:14:59 -0000 1.3 *************** *** 80,85 **** // ! explicit AllPoleDigitalFilter(bool is_transposed) : ! is_transposed_(is_transposed) {} // --- 80,86 ---- // ! AllPoleDigitalFilter(int num_filter_order, bool transposition) ! : num_filter_order_(num_filter_order), ! transposition_(transposition) {} // *************** *** 87,92 **** // bool GetTranspositionFlag() const { ! return is_transposed_; } --- 88,98 ---- // + int GetNumFilterOrder() const { + return num_filter_order_; + } + + // bool GetTranspositionFlag() const { ! return transposition_; } *************** *** 98,102 **** private: // ! const bool is_transposed_; // --- 104,111 ---- private: // ! const int num_filter_order_; ! ! // ! const bool transposition_; // --- NEW FILE: input_source_preprocessing_for_filter_gain.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_INPUT_SOURCE_PREPROCESSING_FOR_FILTER_GAIN_H_ #define SPTK_SRC_INPUT_SOURCE_PREPROCESSING_FOR_FILTER_GAIN_H_ #include <vector> // std::vector #include "input_source_interface.h" #include "input_source_preprocessing_interface.h" #include "sptk_utils.h" namespace sptk { class InputSourcePreprocessingForFilterGain : public InputSourcePreprocessingInterface { public: // enum class FilterGainType { kUnity = 0, kLinear, kLog, }; // InputSourcePreprocessingForFilterGain( FilterGainType gain_type, InputSourceInterface* source) : gain_type_(gain_type), source_(source), is_valid_(false) { if (NULL == source) { return; } is_valid_ = source_->IsValid(); } // virtual ~InputSourcePreprocessingForFilterGain() {} // FilterGainType GetFilterGainType() const { return gain_type_; } // virtual bool IsValid() const { return is_valid_; } // virtual bool Get(std::vector<double>* buffer); private: // const FilterGainType gain_type_; // InputSourceInterface* source_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(InputSourcePreprocessingForFilterGain); }; } // namespace sptk #endif // SPTK_SRC_INPUT_SOURCE_PREPROCESSING_FOR_FILTER_GAIN_H_ --- NEW FILE: input_source_interpolation.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_INPUT_SOURCE_INTERPOLATION_H_ #define SPTK_SRC_INPUT_SOURCE_INTERPOLATION_H_ #include <vector> // std::vector #include "input_source_preprocessing_interface.h" #include "sptk_utils.h" namespace sptk { class InputSourceInterpolation { public: // InputSourceInterpolation(int frame_period, int interpolation_period, InputSourcePreprocessingInterface* source); // virtual ~InputSourceInterpolation() {} // virtual int GetFramePeriod() const { return frame_period_; } // virtual int GetInterpolationPeriod() const { return interpolation_period_; } // virtual bool IsValid() const { return is_valid_; } // virtual bool Get(std::vector<double>* buffer); private: // void CalculateIncrement(); // const int frame_period_; // const int interpolation_period_; // const int first_interpolation_period_; // int data_length_; // int point_index_in_frame_; // InputSourcePreprocessingInterface* source_; // bool is_valid_; // std::vector<double> curr_data_; // std::vector<double> next_data_; // std::vector<double> increment_; // DISALLOW_COPY_AND_ASSIGN(InputSourceInterpolation); }; } // namespace sptk #endif // SPTK_SRC_INPUT_SOURCE_INTERPOLATION_H_ Index: levinson_durbin_recursion.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/levinson_durbin_recursion.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** levinson_durbin_recursion.h 1 Apr 2016 09:05:46 -0000 1.2 --- levinson_durbin_recursion.h 8 Oct 2016 15:14:59 -0000 1.3 *************** *** 84,88 **** // bool Run(const std::vector<double>& autocorrelation_sequence, ! std::vector<double>* lpc_coefficients, LevinsonDurbinRecursion::Buffer* buffer, bool* is_stable) const; --- 84,88 ---- // bool Run(const std::vector<double>& autocorrelation_sequence, ! std::vector<double>* linear_predictive_coefficients, LevinsonDurbinRecursion::Buffer* buffer, bool* is_stable) const; --- NEW FILE: input_source_preprocessing_interface.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_INPUT_SOURCE_PREPROCESSING_INTERFACE_H_ #define SPTK_SRC_INPUT_SOURCE_PREPROCESSING_INTERFACE_H_ #include <vector> // std::vector namespace sptk { class InputSourcePreprocessingInterface { public: // virtual ~InputSourcePreprocessingInterface() {} // virtual bool IsValid() const = 0; // virtual bool Get(std::vector<double>* buffer) = 0; }; } // namespace sptk #endif // SPTK_SRC_INPUT_SOURCE_PREPROCESSING_INTERFACE_H_ Index: poledf.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/poledf.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** poledf.cc 29 Jul 2016 07:26:20 -0000 1.1 --- poledf.cc 8 Oct 2016 15:14:59 -0000 1.2 *************** *** 44,48 **** #include <unistd.h> - #include <algorithm> #include <fstream> #include <iostream> --- 44,47 ---- *************** *** 51,55 **** #include "all_pole_digital_filter.h" ! #include "coefficients_stream_reader.h" #include "sptk_utils.h" --- 50,56 ---- #include "all_pole_digital_filter.h" ! #include "input_source_from_stream.h" ! #include "input_source_interpolation.h" ! #include "input_source_preprocessing_for_filter_gain.h" #include "sptk_utils.h" *************** *** 199,216 **** std::istream& stream_for_filter_input(ifs2.fail() ? std::cin : ifs2); const int filter_length(num_filter_order + 1); std::vector<double> filter_coefficients(filter_length); ! double filter_input; ! double filter_output; ! ! sptk::AllPoleDigitalFilter filter(transposition_flag); sptk::AllPoleDigitalFilter::StoredSignals stored_signals; ! sptk::CoefficientsStreamReader reader(filter_length, ! frame_period, ! interpolation_period, ! &stream_for_filter_coefficients); ! if (!reader.IsValid()) { std::ostringstream error_message; ! error_message << "Failed to set the condition for filtering"; sptk::PrintErrorMessage("poledf", error_message); return 1; --- 200,224 ---- std::istream& stream_for_filter_input(ifs2.fail() ? std::cin : ifs2); + // Prepare variables for filtering. const int filter_length(num_filter_order + 1); std::vector<double> filter_coefficients(filter_length); ! sptk::InputSourceFromStream input_source(false, filter_length, ! &stream_for_filter_coefficients); ! const sptk::InputSourcePreprocessingForFilterGain::FilterGainType gain_type( ! gain_flag ? ! sptk::InputSourcePreprocessingForFilterGain::FilterGainType::kLinear : ! sptk::InputSourcePreprocessingForFilterGain::FilterGainType::kUnity); ! sptk::InputSourcePreprocessingForFilterGain preprocessing(gain_type, ! &input_source); ! sptk::InputSourceInterpolation interpolation(frame_period, ! interpolation_period, ! &preprocessing); ! double filter_input, filter_output; ! sptk::AllPoleDigitalFilter filter(num_filter_order, transposition_flag); sptk::AllPoleDigitalFilter::StoredSignals stored_signals; ! ! if (!interpolation.IsValid()) { std::ostringstream error_message; ! error_message << "Failed to set the conditions for filtering"; sptk::PrintErrorMessage("poledf", error_message); return 1; *************** *** 218,222 **** while (sptk::ReadStream(&filter_input, &stream_for_filter_input)) { ! if (!reader.GetCoefficients(&filter_coefficients)) { std::ostringstream error_message; error_message << "Cannot get filter coefficients"; --- 226,230 ---- while (sptk::ReadStream(&filter_input, &stream_for_filter_input)) { ! if (!interpolation.Get(&filter_coefficients)) { std::ostringstream error_message; error_message << "Cannot get filter coefficients"; *************** *** 225,232 **** } ! if (!gain_flag) filter_coefficients[0] = 1.0; ! ! if (!filter.Run(filter_coefficients, filter_input, ! &filter_output, &stored_signals)) { std::ostringstream error_message; error_message << "Failed to apply all-pole digital filter"; --- 233,238 ---- } ! if (!filter.Run(filter_coefficients, ! filter_input, &filter_output, &stored_signals)) { std::ostringstream error_message; error_message << "Failed to apply all-pole digital filter"; Index: levinson_durbin_recursion.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/levinson_durbin_recursion.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** levinson_durbin_recursion.cc 29 Jul 2016 07:26:20 -0000 1.3 --- levinson_durbin_recursion.cc 8 Oct 2016 15:14:59 -0000 1.4 *************** *** 52,61 **** bool LevinsonDurbinRecursion::Run( const std::vector<double>& autocorrelation_sequence, ! std::vector<double>* lpc_coefficients, LevinsonDurbinRecursion::Buffer* buffer, bool* is_stable) const { // check inputs if (autocorrelation_sequence.empty() || ! NULL == lpc_coefficients || NULL == buffer) { return false; --- 52,61 ---- bool LevinsonDurbinRecursion::Run( const std::vector<double>& autocorrelation_sequence, ! std::vector<double>* linear_predictive_coefficients, LevinsonDurbinRecursion::Buffer* buffer, bool* is_stable) const { // check inputs if (autocorrelation_sequence.empty() || ! NULL == linear_predictive_coefficients || NULL == buffer) { return false; *************** *** 64,69 **** // prepare memories const int output_length(autocorrelation_sequence.size()); ! if (lpc_coefficients->size() < static_cast<std::size_t>(output_length)) { ! lpc_coefficients->resize(output_length); } if (buffer->c_.size() < static_cast<std::size_t>(output_length)) { --- 64,70 ---- // prepare memories const int output_length(autocorrelation_sequence.size()); ! if (linear_predictive_coefficients->size() < ! static_cast<std::size_t>(output_length)) { ! linear_predictive_coefficients->resize(output_length); } if (buffer->c_.size() < static_cast<std::size_t>(output_length)) { *************** *** 73,77 **** // get values const double* input(&(autocorrelation_sequence[0])); ! double* output(&((*lpc_coefficients)[0])); double* c(&buffer->c_[0]); --- 74,78 ---- // get values const double* input(&(autocorrelation_sequence[0])); ! double* output(&((*linear_predictive_coefficients)[0])); double* c(&buffer->c_[0]); Index: levdur.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/levdur.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** levdur.cc 19 Apr 2016 04:27:10 -0000 1.2 --- levdur.cc 8 Oct 2016 15:14:59 -0000 1.3 *************** *** 75,85 **** *stream << " -f f : minimum value of the determinant of [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " the normal matrix" << std::endl; ! *stream << " -c c : check whether the derived LPC [0]" << std::endl; // NOLINT *stream << " coefficients are stable or not" << std::endl; *stream << " 0 (the check is not performed)" << std::endl; *stream << " 1 (if the coefficients are unstable," << std::endl; // NOLINT ! *stream << " output its index to stderr)" << std::endl; *stream << " 2 (if the coefficients are unstable," << std::endl; // NOLINT ! *stream << " output its index to stderr and" << std::endl; *stream << " exit immediately)" << std::endl; *stream << " -h : print this message" << std::endl; --- 75,85 ---- *stream << " -f f : minimum value of the determinant of [" << kDefaultEpsilon << "]" << std::endl; // NOLINT *stream << " the normal matrix" << std::endl; ! *stream << " -c c : check whether the derived LP [0]" << std::endl; // NOLINT *stream << " coefficients are stable or not" << std::endl; *stream << " 0 (the check is not performed)" << std::endl; *stream << " 1 (if the coefficients are unstable," << std::endl; // NOLINT ! *stream << " output the index to stderr)" << std::endl; *stream << " 2 (if the coefficients are unstable," << std::endl; // NOLINT ! *stream << " output the index to stderr and" << std::endl; *stream << " exit immediately)" << std::endl; *stream << " -h : print this message" << std::endl; *************** *** 87,91 **** *stream << " autocorrelation sequence (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; ! *stream << " LPC coefficients (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; --- 87,91 ---- *stream << " autocorrelation sequence (double) [stdin]" << std::endl; // NOLINT *stream << " stdout:" << std::endl; ! *stream << " LP coefficients (double)" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; *************** *** 185,189 **** const int length(num_order + 1); std::vector<double> autocorrelation_sequence(length); ! std::vector<double> lpc_coefficients(length); for (int frame_index(0); --- 185,189 ---- const int length(num_order + 1); std::vector<double> autocorrelation_sequence(length); ! std::vector<double> linear_predictive_coefficients(length); for (int frame_index(0); *************** *** 192,197 **** ++frame_index) { bool is_stable(false); ! if (!recursion.Run(autocorrelation_sequence, &lpc_coefficients, &buffer, ! &is_stable)) { std::ostringstream error_message; error_message << "Failed to solve an autocorrelation normal equation"; --- 192,197 ---- ++frame_index) { bool is_stable(false); ! if (!recursion.Run(autocorrelation_sequence, ! &linear_predictive_coefficients, &buffer, &is_stable)) { std::ostringstream error_message; error_message << "Failed to solve an autocorrelation normal equation"; *************** *** 207,213 **** } ! if (!sptk::WriteStream(length, lpc_coefficients, &std::cout)) { std::ostringstream error_message; ! error_message << "Failed to write LPC coefficients"; sptk::PrintErrorMessage("levdur", error_message); return 1; --- 207,214 ---- } ! if (!sptk::WriteStream(length, linear_predictive_coefficients, ! &std::cout)) { std::ostringstream error_message; ! error_message << "Failed to write LP coefficients"; sptk::PrintErrorMessage("levdur", error_message); return 1; Index: all_pole_digital_filter.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/all_pole_digital_filter.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** all_pole_digital_filter.cc 29 Jul 2016 07:26:20 -0000 1.2 --- all_pole_digital_filter.cc 8 Oct 2016 15:14:58 -0000 1.3 *************** *** 55,59 **** AllPoleDigitalFilter::StoredSignals* stored_signals) const { // check inputs ! if (filter_coefficients.empty() || NULL == filter_output || NULL == stored_signals) { --- 55,60 ---- AllPoleDigitalFilter::StoredSignals* stored_signals) const { // check inputs ! if (filter_coefficients.size() != ! static_cast<std::size_t>(num_filter_order_ + 1) || NULL == filter_output || NULL == stored_signals) { *************** *** 62,69 **** // prepare memory - const int num_filter_order(filter_coefficients.size() - 1); if (stored_signals->signals_.size() != ! static_cast<std::size_t>(num_filter_order)) { ! stored_signals->signals_.resize(num_filter_order); std::fill(stored_signals->signals_.begin(), stored_signals->signals_.end(), 0.0); --- 63,69 ---- // prepare memory if (stored_signals->signals_.size() != ! static_cast<std::size_t>(num_filter_order_)) { ! stored_signals->signals_.resize(num_filter_order_); std::fill(stored_signals->signals_.begin(), stored_signals->signals_.end(), 0.0); *************** *** 72,76 **** // set value const double gained_input(filter_input * filter_coefficients[0]); ! if (0 == num_filter_order) { *filter_output = gained_input; return true; --- 72,76 ---- // set value const double gained_input(filter_input * filter_coefficients[0]); ! if (0 == num_filter_order_) { *filter_output = gained_input; return true; *************** *** 83,94 **** // apply filter double sum(gained_input); ! if (is_transposed_) { sum -= signals[0]; ! for (int i(1); i < num_filter_order; ++i) { signals[i - 1] = signals[i] + coefficients[i] * sum; } ! signals[num_filter_order - 1] = coefficients[num_filter_order] * sum; } else { ! for (int i(num_filter_order - 1); 0 < i; --i) { sum -= coefficients[i + 1] * signals[i]; signals[i] = signals[i - 1]; --- 83,94 ---- // apply filter double sum(gained_input); ! if (transposition_) { sum -= signals[0]; ! for (int i(1); i < num_filter_order_; ++i) { signals[i - 1] = signals[i] + coefficients[i] * sum; } ! signals[num_filter_order_ - 1] = coefficients[num_filter_order_] * sum; } else { ! for (int i(num_filter_order_ - 1); 0 < i; --i) { sum -= coefficients[i + 1] * signals[i]; signals[i] = signals[i - 1]; --- NEW FILE: input_source_from_stream.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 "input_source_from_stream.h" namespace sptk { bool InputSourceFromStream::Get(std::vector<double>* buffer) { if (NULL == buffer || !is_valid_) { return false; } return sptk::ReadStream(zero_padding_, read_size_, buffer, input_stream_); } } // namespace sptk |