From: Takenori Y. <tak...@us...> - 2017-05-17 07:13:01
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv11549 Modified Files: sptk_utils.cc sptk_utils.h Added Files: mu_law_compression.cc mu_law_compression.h Log Message: add MuLawCompression class --- NEW FILE: mu_law_compression.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 "mu_law_compression.h" #include <cmath> // std::fabs, std::log, std::pow namespace sptk { MuLawCompression::MuLawCompression(double maximum_value, int compression_factor, bool inverse) : maximum_value_(maximum_value), compression_factor_(compression_factor), inverse_(inverse), is_valid_(true) { if (maximum_value <= 0.0 || compression_factor <= 0) { is_valid_ = false; } } bool MuLawCompression::Run(double input, double* output) const { if (!is_valid_ || NULL == output) { return false; } const double ratio(std::fabs(input) / maximum_value_); if (inverse_) { *output = sptk::ExtractSign(input) * maximum_value_ * (std::pow(1.0 + compression_factor_, ratio) - 1.0) / compression_factor_; } else { *output = sptk::ExtractSign(input) * maximum_value_ * std::log(1.0 + compression_factor_ * ratio) / std::log(1.0 + compression_factor_); } return true; } } // namespace sptk --- NEW FILE: mu_law_compression.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_MU_LAW_COMPRESSION_H_ #define SPTK_SRC_MU_LAW_COMPRESSION_H_ #include "sptk_utils.h" namespace sptk { class MuLawCompression { public: // MuLawCompression(double maximum_value, int compression_factor, bool inverse); // virtual ~MuLawCompression() { } // double GetMaximumValue() const { return maximum_value_; } // int GetCompressionFactor() const { return compression_factor_; } // bool GetInverseFlag() const { return inverse_; } // bool IsValid() const { return is_valid_; } // bool Run(double input, double* output) const; private: // const double maximum_value_; // const int compression_factor_; // const bool inverse_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(MuLawCompression); }; } // namespace sptk #endif // SPTK_SRC_MU_LAW_COMPRESSION_H_ Index: sptk_utils.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/sptk_utils.cc,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** sptk_utils.cc 3 Apr 2017 02:03:06 -0000 1.15 --- sptk_utils.cc 17 May 2017 07:12:59 -0000 1.16 *************** *** 199,202 **** --- 199,208 ---- } + int ExtractSign(double x) { + if (0.0 < x) return 1; + if (x < 0.0) return -1; + return 0; + } + double FloorLog(double x) { return (x <= 0.0) ? sptk::kLogZero : std::log(x); Index: sptk_utils.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/sptk_utils.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** sptk_utils.h 3 Apr 2017 02:03:06 -0000 1.11 --- sptk_utils.h 17 May 2017 07:12:59 -0000 1.12 *************** *** 83,86 **** --- 83,87 ---- bool IsInRange(int num, int min, int max); bool IsPowerOfTwo(int num); + int ExtractSign(double x); double FloorLog(double x); double AddInLogSpace(double log_x, double log_y); |