Skip to content

Commit

Permalink
Merge pull request #30 from sp-nitech/aperiodicity
Browse files Browse the repository at this point in the history
Add ap command
  • Loading branch information
takenori-y committed Feb 9, 2023
2 parents 010ad66 + 0bf64b9 commit 518b496
Show file tree
Hide file tree
Showing 31 changed files with 2,335 additions and 49 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ set(CC_SOURCES
${THIRD_PARTY_DIR}/SWIPE/vector.cc
${THIRD_PARTY_DIR}/Snack/jkGetF0.cc
${THIRD_PARTY_DIR}/Snack/sigproc.cc
${THIRD_PARTY_DIR}/WORLD/aperiodicity.cc
${THIRD_PARTY_DIR}/WORLD/common.cc
${THIRD_PARTY_DIR}/WORLD/d4c.cc
${THIRD_PARTY_DIR}/WORLD/dio.cc
${THIRD_PARTY_DIR}/WORLD/fft_world.cc
${THIRD_PARTY_DIR}/WORLD/matlabfunctions.cc
${SOURCE_DIR}/analysis/adaptive_generalized_cepstral_analysis.cc
${SOURCE_DIR}/analysis/adaptive_mel_cepstral_analysis.cc
${SOURCE_DIR}/analysis/adaptive_mel_generalized_cepstral_analysis.cc
${SOURCE_DIR}/analysis/aperiodicity_extraction.cc
${SOURCE_DIR}/analysis/aperiodicity_extraction_by_tandem.cc
${SOURCE_DIR}/analysis/aperiodicity_extraction_by_world.cc
${SOURCE_DIR}/analysis/autocorrelation_analysis.cc
${SOURCE_DIR}/analysis/fast_fourier_transform_cepstral_analysis.cc
${SOURCE_DIR}/analysis/mel_cepstral_analysis.cc
Expand Down Expand Up @@ -213,6 +218,7 @@ set(MAIN_SOURCES
${SOURCE_DIR}/main/acr2csm.cc
${SOURCE_DIR}/main/aeq.cc
${SOURCE_DIR}/main/amgcep.cc
${SOURCE_DIR}/main/ap.cc
${SOURCE_DIR}/main/average.cc
${SOURCE_DIR}/main/b2mc.cc
${SOURCE_DIR}/main/bcp.cc
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Changes from SPTK3
- No memory leaks
- Thread-safe
- New features:
- Aperiodicity extraction (`ap`)
- Conversion from/to log area ratio (`lar2par` and `par2lar`)
- Dynamic range compression (`drc`)
- Entropy calculation (`entropy`)
Expand Down
9 changes: 9 additions & 0 deletions doc/main/ap.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _ap:

ap
==

.. doxygenfile:: ap.cc

.. doxygenclass:: sptk::AperiodicityExtraction
:members:
87 changes: 87 additions & 0 deletions include/SPTK/analysis/aperiodicity_extraction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// ------------------------------------------------------------------------ //
// Copyright 2021 SPTK Working Group //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ------------------------------------------------------------------------ //

#ifndef SPTK_ANALYSIS_APERIODICITY_EXTRACTION_H_
#define SPTK_ANALYSIS_APERIODICITY_EXTRACTION_H_

#include <vector> // std::vector

#include "SPTK/analysis/aperiodicity_extraction_interface.h"
#include "SPTK/utils/sptk_utils.h"

namespace sptk {

/**
* Extract aperiodicity from waveform.
*
* The input is whole audio waveform and the output is the sequence of the
* aperiodicity measure. The implemented algorithms of the extraction are
* TANDEM-STRAIGHT and D4C.
*
* [1] H. Kawahara et al., &quot;Simplification and extension of non-periodic
* excitation source representations for high-quality speech manipulation
* systems,&quot; Proc. of Interspeech, pp. 38-41, 2010.
*
* [2] M. Morise, &quot;D4C, a band-aperiodicity estimator for high-quality
* speech synthesis,&quot; Proc. of Speech Communication, vol. 84,
* pp. 57-65, 2016.
*/
class AperiodicityExtraction {
public:
/**
* Aperiodicity extraction algorithms.
*/
enum Algorithms { kTandem = 0, kWorld, kNumAlgorithms };

/**
* @param[in] fft_length FFT length.
* @param[in] frame_shift Frame shift in point.
* @param[in] sampling_rate Sampling rate in Hz.
* @param[in] algorithm Algorithm used for aperiodicity extraction.
*/
AperiodicityExtraction(int fft_length, int frame_shift, double sampling_rate,
Algorithms algorithm);

virtual ~AperiodicityExtraction() {
delete aperiodicity_extraction_;
}

/**
* @return True if this object is valid.
*/
bool IsValid() const {
return (NULL != aperiodicity_extraction_ &&
aperiodicity_extraction_->IsValid());
}

/**
* @param[in] waveform Waveform.
* @param[in] f0 Fundamental frequency in Hz.
* @param[out] aperiodicity Aperiodicity measure.
* @return True on success, false on failure.
*/
bool Run(const std::vector<double>& waveform, const std::vector<double>& f0,
std::vector<std::vector<double> >* aperiodicity) const;

private:
AperiodicityExtractionInterface* aperiodicity_extraction_;

DISALLOW_COPY_AND_ASSIGN(AperiodicityExtraction);
};

} // namespace sptk

#endif // SPTK_ANALYSIS_APERIODICITY_EXTRACTION_H_
93 changes: 93 additions & 0 deletions include/SPTK/analysis/aperiodicity_extraction_by_tandem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ------------------------------------------------------------------------ //
// Copyright 2021 SPTK Working Group //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ------------------------------------------------------------------------ //

#ifndef SPTK_ANALYSIS_APERIODICITY_EXTRACTION_BY_TANDEM_H_
#define SPTK_ANALYSIS_APERIODICITY_EXTRACTION_BY_TANDEM_H_

#include <vector> // std::vector

#include "SPTK/analysis/aperiodicity_extraction_interface.h"
#include "SPTK/utils/sptk_utils.h"

namespace sptk {

/**
* Extract aperiodicity based on TANDEM-STRAIGHT.
*/
class AperiodicityExtractionByTandem : public AperiodicityExtractionInterface {
public:
/**
* @param[in] fft_length FFT length.
* @param[in] frame_shift Frame shift in point.
* @param[in] sampling_rate Sampling rate in Hz.
*/
AperiodicityExtractionByTandem(int fft_length, int frame_shift,
double sampling_rate);

virtual ~AperiodicityExtractionByTandem() {
}

/**
* @return FFT length.
*/
int GetFftLength() const {
return fft_length_;
}

/**
* @return Frame shift.
*/
virtual int GetFrameShift() const {
return frame_shift_;
}

/**
* @return Sampling rate.
*/
double GetSamplingRate() const {
return sampling_rate_;
}

/**
* @return True if this object is valid.
*/
virtual bool IsValid() const {
return is_valid_;
}

/**
* @param[in] waveform Waveform.
* @param[in] f0 Fundamental frequency in Hz.
* @param[out] aperiodicity Aperiodicity measure.
* @return True on success, false on failure.
*/
virtual bool Run(const std::vector<double>& waveform,
const std::vector<double>& f0,
std::vector<std::vector<double> >* aperiodicity) const;

private:
const int fft_length_;
const int frame_shift_;
const double sampling_rate_;

bool is_valid_;

DISALLOW_COPY_AND_ASSIGN(AperiodicityExtractionByTandem);
};

} // namespace sptk

#endif // SPTK_ANALYSIS_APERIODICITY_EXTRACTION_BY_TANDEM_H_
93 changes: 93 additions & 0 deletions include/SPTK/analysis/aperiodicity_extraction_by_world.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ------------------------------------------------------------------------ //
// Copyright 2021 SPTK Working Group //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ------------------------------------------------------------------------ //

#ifndef SPTK_ANALYSIS_APERIODICITY_EXTRACTION_BY_WORLD_H_
#define SPTK_ANALYSIS_APERIODICITY_EXTRACTION_BY_WORLD_H_

#include <vector> // std::vector

#include "SPTK/analysis/aperiodicity_extraction_interface.h"
#include "SPTK/utils/sptk_utils.h"

namespace sptk {

/**
* Extract aperiodicity based on WORLD (D4C).
*/
class AperiodicityExtractionByWorld : public AperiodicityExtractionInterface {
public:
/**
* @param[in] fft_length FFT length.
* @param[in] frame_shift Frame shift in point.
* @param[in] sampling_rate Sampling rate in Hz.
*/
AperiodicityExtractionByWorld(int fft_length, int frame_shift,
double sampling_rate);

virtual ~AperiodicityExtractionByWorld() {
}

/**
* @return FFT length.
*/
int GetFftLength() const {
return fft_length_;
}

/**
* @return Frame shift.
*/
virtual int GetFrameShift() const {
return frame_shift_;
}

/**
* @return Sampling rate.
*/
double GetSamplingRate() const {
return sampling_rate_;
}

/**
* @return True if this object is valid.
*/
virtual bool IsValid() const {
return is_valid_;
}

/**
* @param[in] waveform Waveform.
* @param[in] f0 Fundamental frequency in Hz.
* @param[out] aperiodicity Aperiodicity measure.
* @return True on success, false on failure.
*/
virtual bool Run(const std::vector<double>& waveform,
const std::vector<double>& f0,
std::vector<std::vector<double> >* aperiodicity) const;

private:
const int fft_length_;
const int frame_shift_;
const double sampling_rate_;

bool is_valid_;

DISALLOW_COPY_AND_ASSIGN(AperiodicityExtractionByWorld);
};

} // namespace sptk

#endif // SPTK_ANALYSIS_APERIODICITY_EXTRACTION_BY_WORLD_H_
55 changes: 55 additions & 0 deletions include/SPTK/analysis/aperiodicity_extraction_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// ------------------------------------------------------------------------ //
// Copyright 2021 SPTK Working Group //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ------------------------------------------------------------------------ //

#ifndef SPTK_ANALYSIS_APERIODICITY_EXTRACTION_INTERFACE_H_
#define SPTK_ANALYSIS_APERIODICITY_EXTRACTION_INTERFACE_H_

#include <vector> // std::vector

namespace sptk {

/**
* An interface of aperiodicity extraction.
*/
class AperiodicityExtractionInterface {
public:
virtual ~AperiodicityExtractionInterface() {
}

/**
* @return Frame shift.
*/
virtual int GetFrameShift() const = 0;

/**
* @return True if this object is valid.
*/
virtual bool IsValid() const = 0;

/**
* @param[in] waveform Waveform.
* @param[in] f0 Fundamental frequency in Hz.
* @param[out] aperiodicity Aperiodicity measure.
* @return True on success, false on failure.
*/
virtual bool Run(const std::vector<double>& waveform,
const std::vector<double>& f0,
std::vector<std::vector<double> >* aperiodicity) const = 0;
};

} // namespace sptk

#endif // SPTK_ANALYSIS_APERIODICITY_EXTRACTION_INTERFACE_H_
Loading

0 comments on commit 518b496

Please sign in to comment.