Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv19214 Modified Files: Makefile fast_fourier_transform.cc fast_fourier_transform.h fast_fourier_transform_for_real_sequence.cc fast_fourier_transform_for_real_sequence.h fft.cc fftr.cc ifft.cc mel_generalized_cepstrum_to_spectrum.cc mu_law_compression.cc mu_law_compression.h Added Files: inverse_fast_fourier_transform.cc inverse_fast_fourier_transform.h inverse_fast_fourier_transform_for_real_sequence.cc inverse_fast_fourier_transform_for_real_sequence.h iulaw.cc mu_law_decompression.cc mu_law_decompression.h ulaw.cc Log Message: add ulaw command Index: fast_fourier_transform.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/fast_fourier_transform.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** fast_fourier_transform.h 10 May 2017 10:10:13 -0000 1.9 --- fast_fourier_transform.h 22 May 2017 03:44:10 -0000 1.10 *************** *** 55,59 **** public: // ! FastFourierTransform(int num_order, int fft_size, bool inverse); // --- 55,59 ---- public: // ! FastFourierTransform(int num_order, int fft_size); // *************** *** 72,80 **** // - bool GetInverseFlag() const { - return inverse_; - } - - // bool IsValid() const { return is_valid_; --- 72,75 ---- *************** *** 98,104 **** // - const bool inverse_; - - // bool is_valid_; --- 93,96 ---- Index: mu_law_compression.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/mu_law_compression.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mu_law_compression.cc 17 May 2017 07:12:59 -0000 1.1 --- mu_law_compression.cc 22 May 2017 03:44:11 -0000 1.2 *************** *** 45,59 **** #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; } --- 45,58 ---- #include "mu_law_compression.h" ! #include <cmath> // std::fabs, std::log namespace sptk { ! MuLawCompression::MuLawCompression(double absolute_max_value, ! int compression_factor) ! : absolute_max_value_(absolute_max_value), compression_factor_(compression_factor), is_valid_(true) { ! if (absolute_max_value <= 0.0 || compression_factor <= 0) { is_valid_ = false; } *************** *** 65,78 **** } ! 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; --- 64,71 ---- } ! const double ratio(std::fabs(input) / absolute_max_value_); ! *output = sptk::ExtractSign(input) * absolute_max_value_ * ! std::log(1.0 + compression_factor_ * ratio) / ! std::log(1.0 + compression_factor_); return true; Index: mu_law_compression.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/mu_law_compression.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mu_law_compression.h 17 May 2017 07:12:59 -0000 1.1 --- mu_law_compression.h 22 May 2017 03:44:11 -0000 1.2 *************** *** 53,57 **** public: // ! MuLawCompression(double maximum_value, int compression_factor, bool inverse); // --- 53,57 ---- public: // ! MuLawCompression(double absolute_max_value, int compression_factor); // *************** *** 60,65 **** // ! double GetMaximumValue() const { ! return maximum_value_; } --- 60,65 ---- // ! double GetAbsoluteMaxValue() const { ! return absolute_max_value_; } *************** *** 70,78 **** // - bool GetInverseFlag() const { - return inverse_; - } - - // bool IsValid() const { return is_valid_; --- 70,73 ---- *************** *** 84,88 **** private: // ! const double maximum_value_; // --- 79,83 ---- private: // ! const double absolute_max_value_; // *************** *** 90,96 **** // - const bool inverse_; - - // bool is_valid_; --- 85,88 ---- Index: fast_fourier_transform.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/fast_fourier_transform.cc,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** fast_fourier_transform.cc 10 May 2017 10:10:13 -0000 1.12 --- fast_fourier_transform.cc 22 May 2017 03:44:10 -0000 1.13 *************** *** 51,60 **** namespace sptk { ! FastFourierTransform::FastFourierTransform(int num_order, int fft_size, ! bool inverse) : num_order_(num_order), fft_size_(fft_size), half_fft_size_(fft_size / 2), - inverse_(inverse), is_valid_(true) { if (fft_size < 4 || !IsPowerOfTwo(fft_size) || fft_size <= num_order || --- 51,58 ---- namespace sptk { ! FastFourierTransform::FastFourierTransform(int num_order, int fft_size) : num_order_(num_order), fft_size_(fft_size), half_fft_size_(fft_size / 2), is_valid_(true) { if (fft_size < 4 || !IsPowerOfTwo(fft_size) || fft_size <= num_order || *************** *** 104,111 **** imaginary_part_output->end(), 0.0); ! double* x(inverse_ ? &((*imaginary_part_output)[0]) ! : &((*real_part_output)[0])); ! double* y(inverse_ ? &((*real_part_output)[0]) ! : &((*imaginary_part_output)[0])); int lix(fft_size_); --- 102,107 ---- imaginary_part_output->end(), 0.0); ! double* x(&((*real_part_output)[0])); ! double* y(&((*imaginary_part_output)[0])); int lix(fft_size_); *************** *** 172,186 **** } - // normalize - if (inverse_) { - xp = x; - yp = y; - const double inverse_fft_size(1.0 / fft_size_); - for (int i(0); i < fft_size_; ++i) { - *xp++ *= inverse_fft_size; - *yp++ *= inverse_fft_size; - } - } - return true; } --- 168,171 ---- Index: fft.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/fft.cc,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** fft.cc 11 May 2017 01:30:43 -0000 1.14 --- fft.cc 22 May 2017 03:44:10 -0000 1.15 *************** *** 180,184 **** // prepare for fast Fourier transform ! sptk::FastFourierTransform fft(num_order, fft_size, false); if (!fft.IsValid()) { std::ostringstream error_message; --- 180,184 ---- // prepare for fast Fourier transform ! sptk::FastFourierTransform fft(num_order, fft_size); if (!fft.IsValid()) { std::ostringstream error_message; --- NEW FILE: iulaw.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 <fstream> #include <iostream> #include <sstream> #include <vector> #include "mu_law_decompression.h" #include "sptk_utils.h" namespace { const double kDefaultAbsoluteMaxValue(32768); const int kDefaultCompressionFactor(255); void PrintUsage(std::ostream* stream) { // clang-format off *stream << std::endl; *stream << " iulaw - inverse u-Law pulse code modulation" << std::endl; *stream << std::endl; *stream << " usage:" << std::endl; *stream << " iulaw [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -v v : absolute maximum of input [" << kDefaultAbsoluteMaxValue << "]" << std::endl; // NOLINT *stream << " -u u : compression factor [" << kDefaultCompressionFactor << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; *stream << " input sequence (double) [stdin]" << std::endl; *stream << " stdout:" << std::endl; *stream << " decompressed sequence (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[]) { double absolute_max_value(kDefaultAbsoluteMaxValue); int compression_factor(kDefaultCompressionFactor); for (;;) { const int option_char(getopt_long(argc, argv, "v:u:h", NULL, NULL)); if (-1 == option_char) break; switch (option_char) { case 'v': { if (!sptk::ConvertStringToDouble(optarg, &absolute_max_value) || absolute_max_value <= 0.0) { std::ostringstream error_message; error_message << "The argument for the -v option must be a positive number"; sptk::PrintErrorMessage("iulaw", error_message); return 1; } break; } case 'u': { if (!sptk::ConvertStringToInteger(optarg, &compression_factor) || compression_factor <= 0) { std::ostringstream error_message; error_message << "The argument for the -u option must be a positive integer"; sptk::PrintErrorMessage("iulaw", 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("iulaw", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); // prepare for u-law decompression sptk::MuLawDecompression mu_law_decompression(absolute_max_value, compression_factor); if (!mu_law_decompression.IsValid()) { std::ostringstream error_message; error_message << "Failed to set condition for u-Law decompression"; sptk::PrintErrorMessage("iulaw", error_message); return 1; } double input; double output; while (sptk::ReadStream(&input, &input_stream)) { if (!mu_law_decompression.Run(input, &output)) { std::ostringstream error_message; error_message << "Failed to decompress"; sptk::PrintErrorMessage("iulaw", error_message); return 1; } if (!sptk::WriteStream(output, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write a decompressed sequence"; sptk::PrintErrorMessage("iulaw", error_message); return 1; } } return 0; } Index: mel_generalized_cepstrum_to_spectrum.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/mel_generalized_cepstrum_to_spectrum.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mel_generalized_cepstrum_to_spectrum.cc 10 May 2017 10:10:13 -0000 1.2 --- mel_generalized_cepstrum_to_spectrum.cc 22 May 2017 03:44:11 -0000 1.3 *************** *** 53,57 **** 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() || --- 53,57 ---- is_normalized, is_multiplied, fft_size / 2, 0.0, 0.0, false, false), ! fast_fourier_transform_(fft_size / 2, fft_size), is_valid_(true) { if (!mel_generalized_cepstrum_transform_.IsValid() || --- NEW FILE: ulaw.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 <fstream> #include <iostream> #include <sstream> #include <vector> #include "mu_law_compression.h" #include "sptk_utils.h" namespace { const double kDefaultAbsoluteMaxValue(32768); const int kDefaultCompressionFactor(255); void PrintUsage(std::ostream* stream) { // clang-format off *stream << std::endl; *stream << " ulaw - u-Law pulse code modulation" << std::endl; *stream << std::endl; *stream << " usage:" << std::endl; *stream << " ulaw [ options ] [ infile ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -v v : absolute maximum of input [" << kDefaultAbsoluteMaxValue << "]" << std::endl; // NOLINT *stream << " -u u : compression factor [" << kDefaultCompressionFactor << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; *stream << " infile:" << std::endl; *stream << " input sequence (double) [stdin]" << std::endl; *stream << " stdout:" << std::endl; *stream << " compressed sequence (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[]) { double absolute_max_value(kDefaultAbsoluteMaxValue); int compression_factor(kDefaultCompressionFactor); for (;;) { const int option_char(getopt_long(argc, argv, "v:u:h", NULL, NULL)); if (-1 == option_char) break; switch (option_char) { case 'v': { if (!sptk::ConvertStringToDouble(optarg, &absolute_max_value) || absolute_max_value <= 0.0) { std::ostringstream error_message; error_message << "The argument for the -v option must be a positive number"; sptk::PrintErrorMessage("ulaw", error_message); return 1; } break; } case 'u': { if (!sptk::ConvertStringToInteger(optarg, &compression_factor) || compression_factor <= 0) { std::ostringstream error_message; error_message << "The argument for the -u option must be a positive integer"; sptk::PrintErrorMessage("ulaw", 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("ulaw", error_message); return 1; } std::istream& input_stream(ifs.fail() ? std::cin : ifs); // prepare for u-law compression sptk::MuLawCompression mu_law_compression(absolute_max_value, compression_factor); if (!mu_law_compression.IsValid()) { std::ostringstream error_message; error_message << "Failed to set condition for u-Law compression"; sptk::PrintErrorMessage("ulaw", error_message); return 1; } double input; double output; while (sptk::ReadStream(&input, &input_stream)) { if (!mu_law_compression.Run(input, &output)) { std::ostringstream error_message; error_message << "Failed to compress"; sptk::PrintErrorMessage("ulaw", error_message); return 1; } if (!sptk::WriteStream(output, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write a compressed sequence"; sptk::PrintErrorMessage("ulaw", error_message); return 1; } } return 0; } Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Makefile 17 May 2017 10:07:14 -0000 1.31 --- Makefile 22 May 2017 03:44:10 -0000 1.32 *************** *** 64,67 **** --- 64,69 ---- input_source_interpolation_with_magic_number.cc \ input_source_preprocessing_for_filter_gain.cc \ + inverse_fast_fourier_transform.cc \ + inverse_fast_fourier_transform_for_real_sequence.cc \ levinson_durbin_recursion.cc \ line_spectral_pairs_to_linear_predictive_coefficients.cc \ *************** *** 74,77 **** --- 76,80 ---- mel_generalized_line_spectral_pairs_to_spectrum.cc \ mu_law_compression.cc \ + mu_law_decompression.cc \ normal_distributed_random_value_generation.cc \ parcor_coefficients_to_linear_predictive_coefficients.cc \ Index: fftr.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/fftr.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** fftr.cc 11 May 2017 01:30:43 -0000 1.5 --- fftr.cc 22 May 2017 03:44:10 -0000 1.6 *************** *** 187,191 **** // prepare for fast Fourier transform ! sptk::FastFourierTransformForRealSequence fft(num_order, fft_size, false); sptk::FastFourierTransformForRealSequence::Buffer buffer; if (!fft.IsValid()) { --- 187,191 ---- // prepare for fast Fourier transform ! sptk::FastFourierTransformForRealSequence fft(num_order, fft_size); sptk::FastFourierTransformForRealSequence::Buffer buffer; if (!fft.IsValid()) { Index: ifft.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/ifft.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ifft.cc 15 Mar 2017 13:38:04 -0000 1.8 --- ifft.cc 22 May 2017 03:44:10 -0000 1.9 *************** *** 49,53 **** #include <vector> ! #include "fast_fourier_transform.h" #include "sptk_utils.h" --- 49,53 ---- #include <vector> ! #include "inverse_fast_fourier_transform.h" #include "sptk_utils.h" *************** *** 148,154 **** std::istream& input_stream(ifs.fail() ? std::cin : ifs); ! // prepare for fast Fourier transform ! sptk::FastFourierTransform fft(fft_size - 1, fft_size, true); ! if (!fft.IsValid()) { std::ostringstream error_message; error_message << "FFT size must be a power of 2 and greater than 2"; --- 148,154 ---- std::istream& input_stream(ifs.fail() ? std::cin : ifs); ! // prepare for inverse fast Fourier transform ! sptk::InverseFastFourierTransform inverse_fft(fft_size - 1, fft_size); ! if (!inverse_fft.IsValid()) { std::ostringstream error_message; error_message << "FFT size must be a power of 2 and greater than 2"; *************** *** 164,168 **** while (sptk::ReadStream(false, 0, 0, fft_size, &input_x, &input_stream) && sptk::ReadStream(false, 0, 0, fft_size, &input_y, &input_stream)) { ! if (!fft.Run(input_x, input_y, &output_x, &output_y)) { std::ostringstream error_message; error_message << "Failed to run inverse fast Fourier transform"; --- 164,168 ---- while (sptk::ReadStream(false, 0, 0, fft_size, &input_x, &input_stream) && sptk::ReadStream(false, 0, 0, fft_size, &input_y, &input_stream)) { ! if (!inverse_fft.Run(input_x, input_y, &output_x, &output_y)) { std::ostringstream error_message; error_message << "Failed to run inverse fast Fourier transform"; --- NEW FILE: inverse_fast_fourier_transform_for_real_sequence.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 "inverse_fast_fourier_transform_for_real_sequence.h" #include <algorithm> // std::transform #include <cstddef> // std::size_t #include <functional> // std::bind1st, std::multiplies namespace sptk { InverseFastFourierTransformForRealSequence:: InverseFastFourierTransformForRealSequence(int num_order, int fft_size) : fast_fourier_transform_(num_order, fft_size) { } bool InverseFastFourierTransformForRealSequence::Run( const std::vector<double>& real_part_input, std::vector<double>* real_part_output, std::vector<double>* imaginary_part_output, InverseFastFourierTransformForRealSequence::Buffer* buffer) const { // check inputs if (!fast_fourier_transform_.IsValid() || real_part_input.size() != static_cast<std::size_t>(fast_fourier_transform_.GetNumOrder() + 1) || NULL == real_part_output || NULL == imaginary_part_output || NULL == buffer) { return false; } if (fast_fourier_transform_.Run(real_part_input, real_part_output, imaginary_part_output, &buffer->fast_fourier_transform_buffer_)) { return false; } const int fft_size(fast_fourier_transform_.GetFftSize()); const double inverse_fft_size(1.0 / fft_size); std::transform(real_part_output->begin(), real_part_output->begin() + fft_size, real_part_output->begin(), std::bind1st(std::multiplies<double>(), inverse_fft_size)); std::transform(imaginary_part_output->begin(), imaginary_part_output->begin() + fft_size, imaginary_part_output->begin(), std::bind1st(std::multiplies<double>(), inverse_fft_size)); return true; } } // namespace sptk Index: fast_fourier_transform_for_real_sequence.cc =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/fast_fourier_transform_for_real_sequence.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** fast_fourier_transform_for_real_sequence.cc 10 May 2017 10:10:13 -0000 1.3 --- fast_fourier_transform_for_real_sequence.cc 22 May 2017 03:44:10 -0000 1.4 *************** *** 52,61 **** FastFourierTransformForRealSequence::FastFourierTransformForRealSequence( ! int num_order, int fft_size, bool inverse) : num_order_(num_order), fft_size_(fft_size), half_fft_size_(fft_size / 2), ! inverse_(inverse), ! fast_fourier_transform_(half_fft_size_ - 1, half_fft_size_, false), is_valid_(true) { if (!fast_fourier_transform_.IsValid() || !IsPowerOfTwo(fft_size) || --- 52,60 ---- FastFourierTransformForRealSequence::FastFourierTransformForRealSequence( ! int num_order, int fft_size) : num_order_(num_order), fft_size_(fft_size), half_fft_size_(fft_size / 2), ! fast_fourier_transform_(half_fft_size_ - 1, half_fft_size_), is_valid_(true) { if (!fast_fourier_transform_.IsValid() || !IsPowerOfTwo(fft_size) || *************** *** 155,168 **** } - if (inverse_) { - xp = x; - yp = y; - const double inverse_fft_size(1.0 / fft_size_); - for (int i(0); i < fft_size_; ++i) { - *xp++ *= inverse_fft_size; - *yp++ *= inverse_fft_size; - } - } - return true; } --- 154,157 ---- --- NEW FILE: mu_law_decompression.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_DECOMPRESSION_H_ #define SPTK_SRC_MU_LAW_DECOMPRESSION_H_ #include "sptk_utils.h" namespace sptk { class MuLawDecompression { public: // MuLawDecompression(double absolute_max_value, int compression_factor); // virtual ~MuLawDecompression() { } // double GetAbsoluteMaxValue() const { return absolute_max_value_; } // int GetCompressionFactor() const { return compression_factor_; } // bool IsValid() const { return is_valid_; } // bool Run(double input, double* output) const; private: // const double absolute_max_value_; // const int compression_factor_; // bool is_valid_; // DISALLOW_COPY_AND_ASSIGN(MuLawDecompression); }; } // namespace sptk #endif // SPTK_SRC_MU_LAW_DECOMPRESSION_H_ --- NEW FILE: inverse_fast_fourier_transform_for_real_sequence.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_INVERSE_FAST_FOURIER_TRANSFORM_FOR_REAL_SEQUENCE_H_ #define SPTK_SRC_INVERSE_FAST_FOURIER_TRANSFORM_FOR_REAL_SEQUENCE_H_ #include <vector> // std::vector #include "fast_fourier_transform_for_real_sequence.h" #include "sptk_utils.h" namespace sptk { class InverseFastFourierTransformForRealSequence { public: class Buffer { public: Buffer() { } virtual ~Buffer() { } private: FastFourierTransformForRealSequence::Buffer fast_fourier_transform_buffer_; friend class InverseFastFourierTransformForRealSequence; DISALLOW_COPY_AND_ASSIGN(Buffer); }; // InverseFastFourierTransformForRealSequence(int num_order, int fft_size); // virtual ~InverseFastFourierTransformForRealSequence() { } // int GetNumOrder() const { return fast_fourier_transform_.GetNumOrder(); } // int GetFftSize() const { return fast_fourier_transform_.GetFftSize(); } // bool IsValid() const { return fast_fourier_transform_.IsValid(); } // bool Run(const std::vector<double>& real_part_input, std::vector<double>* real_part_output, std::vector<double>* imaginary_part_output, InverseFastFourierTransformForRealSequence::Buffer* buffer) const; private: // const FastFourierTransformForRealSequence fast_fourier_transform_; // DISALLOW_COPY_AND_ASSIGN(InverseFastFourierTransformForRealSequence); }; } // namespace sptk #endif // SPTK_SRC_INVERSE_FAST_FOURIER_TRANSFORM_FOR_REAL_SEQUENCE_H_ Index: fast_fourier_transform_for_real_sequence.h =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/fast_fourier_transform_for_real_sequence.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** fast_fourier_transform_for_real_sequence.h 10 May 2017 10:10:13 -0000 1.3 --- fast_fourier_transform_for_real_sequence.h 22 May 2017 03:44:10 -0000 1.4 *************** *** 70,75 **** // ! FastFourierTransformForRealSequence(int num_order, int fft_size, ! bool inverse); // --- 70,74 ---- // ! FastFourierTransformForRealSequence(int num_order, int fft_size); // *************** *** 88,96 **** // - bool GetInverseFlag() const { - return inverse_; - } - - // bool IsValid() const { return is_valid_; --- 87,90 ---- *************** *** 114,120 **** // - const bool inverse_; - - // const FastFourierTransform fast_fourier_transform_; --- 108,111 ---- --- NEW FILE: mu_law_decompression.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_decompression.h" #include <cmath> // std::fabs, std::pow namespace sptk { MuLawDecompression::MuLawDecompression(double absolute_max_value, int compression_factor) : absolute_max_value_(absolute_max_value), compression_factor_(compression_factor), is_valid_(true) { if (absolute_max_value <= 0.0 || compression_factor <= 0) { is_valid_ = false; } } bool MuLawDecompression::Run(double input, double* output) const { if (!is_valid_ || NULL == output) { return false; } const double ratio(std::fabs(input) / absolute_max_value_); *output = sptk::ExtractSign(input) * absolute_max_value_ * (std::pow(1.0 + compression_factor_, ratio) - 1.0) / compression_factor_; return true; } } // namespace sptk --- NEW FILE: inverse_fast_fourier_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-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 "inverse_fast_fourier_transform.h" #include <algorithm> // std::transform #include <cstddef> // std::size_t #include <functional> // std::bind1st, std::multiplies namespace sptk { InverseFastFourierTransform::InverseFastFourierTransform(int num_order, int fft_size) : fast_fourier_transform_(num_order, fft_size) { } bool InverseFastFourierTransform::Run( const std::vector<double>& real_part_input, const std::vector<double>& imaginary_part_input, std::vector<double>* real_part_output, std::vector<double>* imaginary_part_output) const { // check inputs if (!fast_fourier_transform_.IsValid() || real_part_input.size() != static_cast<std::size_t>(fast_fourier_transform_.GetNumOrder() + 1) || imaginary_part_input.size() != static_cast<std::size_t>(fast_fourier_transform_.GetNumOrder() + 1) || NULL == real_part_output || NULL == imaginary_part_output) { return false; } if (!fast_fourier_transform_.Run(imaginary_part_input, real_part_input, imaginary_part_output, real_part_output)) { return false; } const int fft_size(fast_fourier_transform_.GetFftSize()); const double inverse_fft_size(1.0 / fft_size); std::transform(real_part_output->begin(), real_part_output->begin() + fft_size, real_part_output->begin(), std::bind1st(std::multiplies<double>(), inverse_fft_size)); std::transform(imaginary_part_output->begin(), imaginary_part_output->begin() + fft_size, imaginary_part_output->begin(), std::bind1st(std::multiplies<double>(), inverse_fft_size)); return true; } } // namespace sptk --- NEW FILE: inverse_fast_fourier_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_INVERSE_FAST_FOURIER_TRANSFORM_H_ #define SPTK_SRC_INVERSE_FAST_FOURIER_TRANSFORM_H_ #include <vector> // std::vector #include "fast_fourier_transform.h" #include "sptk_utils.h" namespace sptk { class InverseFastFourierTransform { public: // InverseFastFourierTransform(int num_order, int fft_size); // virtual ~InverseFastFourierTransform() { } int GetNumOrder() const { return fast_fourier_transform_.GetNumOrder(); } // int GetFftSize() const { return fast_fourier_transform_.GetFftSize(); } // bool IsValid() const { return fast_fourier_transform_.IsValid(); } // bool Run(const std::vector<double>& real_part_input, const std::vector<double>& imaginary_part_input, std::vector<double>* real_part_output, std::vector<double>* imaginary_part_output) const; private: // const FastFourierTransform fast_fourier_transform_; // DISALLOW_COPY_AND_ASSIGN(InverseFastFourierTransform); }; } // namespace sptk #endif // SPTK_SRC_INVERSE_FAST_FOURIER_TRANSFORM_H_ |