From: Keiichiro O. <ur...@us...> - 2016-10-06 10:24:56
|
Update of /cvsroot/sp-tk/SPTK4/src In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv25304 Modified Files: Makefile Added Files: m_sequence_generation.cc m_sequence_generation.h mseq.cc Log Message: add mseq command --- NEW FILE: m_sequence_generation.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 "./m_sequence_generation.h" namespace { const int kInitialValue(0x55555555); const int kB0(0x00000001); const int kB28(0x10000000); const int kB31(0x80000000); const int kB31F(0x7fffffff); const int kZ(0x00000000); }; namespace sptk { MSequenceGeneration::Buffer::Buffer() : x_(kInitialValue) { } void MSequenceGeneration::Buffer::Clear() { x_ = kInitialValue; } bool MSequenceGeneration::Run(double *output, MSequenceGeneration::Buffer *buffer) const { // check input if (NULL == output || NULL == buffer) { return false; } // generate M-Sequence using X**31 + X**28 + 1 int x0, x28; buffer->x_ >>= 1; if (buffer->x_ & kB0) x0 = 1; else x0 = -1; if (buffer->x_ & kB28) x28 = 1; else x28 = -1; if (x0 + x28) buffer->x_ &= kB31F; else buffer->x_ |= kB31; *output = static_cast<double>(x0); return true; } } // namespace sptk Index: Makefile =================================================================== RCS file: /cvsroot/sp-tk/SPTK4/src/Makefile,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile 6 Oct 2016 10:04:46 -0000 1.8 --- Makefile 6 Oct 2016 10:24:54 -0000 1.9 *************** *** 52,55 **** --- 52,56 ---- frequency_transform.cc \ levinson_durbin_recursion.cc \ + m_sequence_generation.cc \ sptk_utils.cc --- NEW FILE: mseq.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 <unistd.h> #include <fstream> #include <iostream> #include <sstream> #include <vector> #include "./m_sequence_generation.h" #include "./sptk_utils.h" namespace { const int kDefaultNumOutputLength(256); void PrintUsage(std::ostream* stream) { *stream << std::endl; *stream << " mseq - M-Sequence generation" << std::endl; *stream << std::endl; *stream << " usage:" << std::endl; *stream << " mseq [ options ] > stdout" << std::endl; *stream << " options:" << std::endl; *stream << " -l l : output length [" << kDefaultNumOutputLength << "]" << std::endl; // NOLINT *stream << " -h : print this message" << std::endl; *stream << " stdout:" << std::endl; *stream << " M-Sequence (double)" << std::endl; *stream << " notice:" << std::endl; *stream << " if l<0, generate infinite sequence" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; *stream << std::endl; } } // namespace int main(int argc, char* argv[]) { int num_output_length(kDefaultNumOutputLength); for (;;) { const char option_char(getopt(argc, argv, "l:h")); if (-1 == option_char) break; switch (option_char) { case 'l': { if (!sptk::ConvertStringToInteger(optarg, &num_output_length)) { std::ostringstream error_message; error_message << "The argument for the -l option must be integer"; sptk::PrintErrorMessage("mseq", error_message); return 1; } break; } case 'h': { PrintUsage(&std::cout); return 0; } default: { PrintUsage(&std::cerr); return 1; } } } sptk::MSequenceGeneration generator; sptk::MSequenceGeneration::Buffer buffer; for (int i(0); num_output_length < 0 || i < num_output_length; ++i) { double output; if (!generator.Run(&output, &buffer)) { std::ostringstream error_message; error_message << "Failed to generate M sequence"; sptk::PrintErrorMessage("mseq", error_message); return 1; } if (!sptk::WriteStream(output, &std::cout)) { std::ostringstream error_message; error_message << "Failed to write an output sequence"; sptk::PrintErrorMessage("mseq", error_message); return 1; } } return 0; } --- NEW FILE: m_sequence_generation.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_M_SEQUENCE_GENERATION_H_ #define SPTK_SRC_M_SEQUENCE_GENERATION_H_ #include "./sptk_utils.h" namespace sptk { class MSequenceGeneration { public: class Buffer { public: // Buffer(); // ~Buffer() {} // void Clear(); private: // int x_; // friend class MSequenceGeneration; // DISALLOW_COPY_AND_ASSIGN(Buffer); }; public: // MSequenceGeneration() {} // virtual ~MSequenceGeneration() {} // bool Run(double *output, MSequenceGeneration::Buffer *buffer) const; private: // DISALLOW_COPY_AND_ASSIGN(MSequenceGeneration); }; } // namespace sptk #endif // SPTK_SRC_M_SEQUENCE_GENERATION_H_ |