Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
takenori-y committed Jul 30, 2021
1 parent 3fb3e0c commit 976cf4b
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 72 deletions.
28 changes: 1 addition & 27 deletions doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -849,33 +849,7 @@ INPUT = \
../include/SPTK/analysis \
../include/SPTK/check \
../include/SPTK/compression \
../include/SPTK/conversion/all_pole_to_all_zero_digital_filter_coefficients.h \
../include/SPTK/conversion/autocorrelation_to_composite_sinusoidal_modeling.h \
../include/SPTK/conversion/cepstrum_to_autocorrelation.h \
../include/SPTK/conversion/cepstrum_to_minimum_phase_impulse_response.h \
../include/SPTK/conversion/cepstrum_to_negative_derivative_of_phase_spectrum.h \
../include/SPTK/conversion/composite_sinusoidal_modeling_to_autocorrelation.h \
../include/SPTK/conversion/filter_coefficients_to_group_delay.h \
../include/SPTK/conversion/filter_coefficients_to_phase_spectrum.h \
../include/SPTK/conversion/filter_coefficients_to_spectrum.h \
../include/SPTK/conversion/generalized_cepstrum_gain_normalization.h \
../include/SPTK/conversion/generalized_cepstrum_inverse_gain_normalization.h \
../include/SPTK/conversion/line_spectral_pairs_to_linear_predictive_coefficients.h \
../include/SPTK/conversion/linear_predictive_coefficients_to_cepstrum.h \
../include/SPTK/conversion/linear_predictive_coefficients_to_line_spectral_pairs.h \
../include/SPTK/conversion/linear_predictive_coefficients_to_parcor_coefficients.h \
../include/SPTK/conversion/log_area_ratio_to_parcor_coefficients.h \
../include/SPTK/conversion/mel_cepstrum_to_mlsa_digital_filter_coefficients.h \
../include/SPTK/conversion/mel_generalized_cepstrum_to_mel_generalized_cepstrum.h \
../include/SPTK/conversion/mel_generalized_cepstrum_to_spectrum.h \
../include/SPTK/conversion/mel_generalized_line_spectral_pairs_to_spectrum.h \
../include/SPTK/conversion/mlsa_digital_filter_coefficients_to_mel_cepstrum.h \
../include/SPTK/conversion/negative_derivative_of_phase_spectrum_to_cepstrum.h \
../include/SPTK/conversion/parcor_coefficients_to_linear_predictive_coefficients.h \
../include/SPTK/conversion/parcor_coefficients_to_log_area_ratio.h \
../include/SPTK/conversion/spectrum_to_spectrum.h \
../include/SPTK/conversion/waveform_to_autocorrelation.h \
../include/SPTK/conversion/waveform_to_spectrum.h \
../include/SPTK/conversion \
../include/SPTK/filter \
../include/SPTK/generation \
../include/SPTK/math \
Expand Down
1 change: 1 addition & 0 deletions doc/main/spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

spec
====

.. doxygenfile:: spec.cc

.. seealso:: :ref:`fftr` :ref:`phase` :ref:`grpdelay`
Expand Down
13 changes: 8 additions & 5 deletions include/SPTK/conversion/filter_coefficients_to_spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Interdisciplinary Graduate School of //
// Science and Engineering //
// //
// 1996-2019 Nagoya Institute of Technology //
// 1996-2020 Nagoya Institute of Technology //
// Department of Computer Science //
// //
// All rights reserved. //
Expand Down Expand Up @@ -70,8 +70,9 @@ namespace sptk {
* Type 0:
* @f[
* \begin{array}{cccc}
* 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, & 20
* \log_{10}|H(L/2)|. \end{array}
* 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, &
* 20 \log_{10}|H(L/2)|.
* \end{array}
* @f]
* Type 1:
* @f[
Expand Down Expand Up @@ -102,24 +103,27 @@ class FilterCoefficientsToSpectrum {
public:
Buffer() {
}

virtual ~Buffer() {
}

private:
RealValuedFastFourierTransform::Buffer fast_fourier_transform_buffer_;

std::vector<double> fast_fourier_transform_input_;
std::vector<double> fast_fourier_transform_real_output_;
std::vector<double> fast_fourier_transform_imaginary_output_;
std::vector<double> numerator_of_transfer_function_;
std::vector<double> denominator_of_transfer_function_;

friend class FilterCoefficientsToSpectrum;
DISALLOW_COPY_AND_ASSIGN(Buffer);
};

/**
* @param[in] num_numerator_order Order of numerator coefficients, @f$M@f$.
* @param[in] num_denominator_order Order of denominator coefficients,
* @f$N@f$.
* @f$N@f$.
* @param[in] fft_length FFT length, @f$L@f$.
* @param[in] output_format Output format.
* @param[in] epsilon Small value added to power spectrum.
Expand Down Expand Up @@ -200,7 +204,6 @@ class FilterCoefficientsToSpectrum {
const int fft_length_;

const RealValuedFastFourierTransform fast_fourier_transform_;

const SpectrumToSpectrum spectrum_to_spectrum_;

bool is_valid_;
Expand Down
15 changes: 5 additions & 10 deletions include/SPTK/conversion/spectrum_to_spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Interdisciplinary Graduate School of //
// Science and Engineering //
// //
// 1996-2019 Nagoya Institute of Technology //
// 1996-2020 Nagoya Institute of Technology //
// Department of Computer Science //
// //
// All rights reserved. //
Expand Down Expand Up @@ -60,8 +60,9 @@ namespace sptk {
* Type 0:
* @f[
* \begin{array}{cccc}
* 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, & 20
* \log_{10}|H(N/2)|. \end{array}
* 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, &
* 20 \log_{10}|H(N/2)|.
* \end{array}
* @f]
* Type 1:
* @f[
Expand Down Expand Up @@ -122,13 +123,7 @@ class SpectrumToSpectrum {
InputOutputFormats output_format, double epsilon,
double relative_floor_in_decibels);

virtual ~SpectrumToSpectrum() {
for (std::vector<SpectrumToSpectrum::OperationInterface*>::iterator itr(
operations_.begin());
itr != operations_.end(); ++itr) {
delete (*itr);
}
}
virtual ~SpectrumToSpectrum();

/**
* @return FFT length.
Expand Down
10 changes: 7 additions & 3 deletions include/SPTK/conversion/waveform_to_spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Interdisciplinary Graduate School of //
// Science and Engineering //
// //
// 1996-2019 Nagoya Institute of Technology //
// 1996-2020 Nagoya Institute of Technology //
// Department of Computer Science //
// //
// All rights reserved. //
Expand Down Expand Up @@ -67,8 +67,9 @@ namespace sptk {
* Type 0:
* @f[
* \begin{array}{cccc}
* 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, & 20
* \log_{10}|H(N/2)|. \end{array}
* 20 \log_{10}|H(0)|, & 20 \log_{10}|H(1)|, & \ldots, &
* 20 \log_{10}|H(N/2)|.
* \end{array}
* @f]
* Type 1:
* @f[
Expand Down Expand Up @@ -99,11 +100,13 @@ class WaveformToSpectrum {
public:
Buffer() {
}

virtual ~Buffer() {
}

private:
FilterCoefficientsToSpectrum::Buffer buffer_;

friend class WaveformToSpectrum;
DISALLOW_COPY_AND_ASSIGN(Buffer);
};
Expand Down Expand Up @@ -175,6 +178,7 @@ class WaveformToSpectrum {

private:
const FilterCoefficientsToSpectrum filter_coefficients_to_spectrum_;

const std::vector<double> dummy_for_filter_coefficients_to_spectrum_;

DISALLOW_COPY_AND_ASSIGN(WaveformToSpectrum);
Expand Down
23 changes: 10 additions & 13 deletions src/conversion/filter_coefficients_to_spectrum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Interdisciplinary Graduate School of //
// Science and Engineering //
// //
// 1996-2019 Nagoya Institute of Technology //
// 1996-2020 Nagoya Institute of Technology //
// Department of Computer Science //
// //
// All rights reserved. //
Expand Down Expand Up @@ -44,10 +44,9 @@

#include "SPTK/conversion/filter_coefficients_to_spectrum.h"

#include <algorithm> // std::copy, std::fill, std::transform, etc.
#include <algorithm> // std::copy, std::fill, std::transform
#include <cfloat> // DBL_MAX
#include <cstddef> // std::size_t
#include <functional> // std::bind, std::divides, std::multiplies, etc.

namespace sptk {

Expand Down Expand Up @@ -75,7 +74,7 @@ bool FilterCoefficientsToSpectrum::Run(
const std::vector<double>& denominator_coefficients,
std::vector<double>* spectrum,
FilterCoefficientsToSpectrum::Buffer* buffer) const {
// check inputs
// Check inputs.
const int numerator_length(num_numerator_order_ + 1);
const int denominator_length(num_denominator_order_ + 1);
if (!is_valid_ ||
Expand All @@ -87,7 +86,7 @@ bool FilterCoefficientsToSpectrum::Run(
return false;
}

// prepare memories
// Prepare memories.
const int output_length(fft_length_ / 2 + 1);
if (spectrum->size() != static_cast<std::size_t>(output_length)) {
spectrum->resize(output_length);
Expand All @@ -105,7 +104,7 @@ bool FilterCoefficientsToSpectrum::Run(
buffer->denominator_of_transfer_function_.resize(output_length);
}

// calculate numerators of transfer function
// Calculate numerators of transfer function.
if (1 != numerator_length) {
std::copy(numerator_coefficients.begin(), numerator_coefficients.end(),
buffer->fast_fourier_transform_input_.begin());
Expand All @@ -127,7 +126,7 @@ bool FilterCoefficientsToSpectrum::Run(
}
}

// calculate denominators of transfer function
// Calculate denominators of transfer function.
if (1 != denominator_length) {
buffer->fast_fourier_transform_input_[0] = 1.0;
std::copy(denominator_coefficients.begin() + 1,
Expand Down Expand Up @@ -155,13 +154,13 @@ bool FilterCoefficientsToSpectrum::Run(
}
}

// get gain of transfer function
// Get gain of transfer function.
const double gain(denominator_coefficients[0] * denominator_coefficients[0]);
if (0.0 == gain) {
return false;
}

// calculate power spectrum
// Calculate power spectrum.
if (1 == numerator_length && 1 == denominator_length) {
const double tmp(gain * numerator_coefficients[0] *
numerator_coefficients[0]);
Expand All @@ -172,14 +171,12 @@ bool FilterCoefficientsToSpectrum::Run(
std::transform(
buffer->denominator_of_transfer_function_.begin(),
buffer->denominator_of_transfer_function_.begin() + output_length,
spectrum->begin(),
std::bind(std::divides<double>(), tmp, std::placeholders::_1));
spectrum->begin(), [tmp](double y) { return tmp / y; });
} else if (1 != numerator_length && 1 == denominator_length) {
std::transform(
buffer->numerator_of_transfer_function_.begin(),
buffer->numerator_of_transfer_function_.begin() + output_length,
spectrum->begin(),
std::bind(std::multiplies<double>(), gain, std::placeholders::_1));
spectrum->begin(), [gain](double x) { return gain * x; });
} else {
std::transform(
buffer->numerator_of_transfer_function_.begin(),
Expand Down
17 changes: 13 additions & 4 deletions src/conversion/spectrum_to_spectrum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Interdisciplinary Graduate School of //
// Science and Engineering //
// //
// 1996-2019 Nagoya Institute of Technology //
// 1996-2020 Nagoya Institute of Technology //
// Department of Computer Science //
// //
// All rights reserved. //
Expand Down Expand Up @@ -44,9 +44,9 @@

#include "SPTK/conversion/spectrum_to_spectrum.h"

#include <algorithm> // std::copy, std::max, std::max_element, etc.
#include <algorithm> // std::copy, std::max, std::max_element, std::transform
#include <cfloat> // DBL_MAX
#include <cmath> // std::exp, std::log, std::log10, std::pow, etc.
#include <cmath> // std::exp, std::log, std::log10, std::pow, std::sqrt
#include <cstddef> // std::size_t

namespace {
Expand Down Expand Up @@ -462,15 +462,24 @@ SpectrumToSpectrum::SpectrumToSpectrum(int fft_length,
}
}

SpectrumToSpectrum::~SpectrumToSpectrum() {
for (std::vector<SpectrumToSpectrum::OperationInterface*>::iterator itr(
operations_.begin());
itr != operations_.end(); ++itr) {
delete (*itr);
}
}

bool SpectrumToSpectrum::Run(const std::vector<double>& input,
std::vector<double>* output) const {
// check inputs
// Check inputs.
const int length(fft_length_ / 2 + 1);
if (!is_valid_ || input.size() != static_cast<std::size_t>(length) ||
NULL == output) {
return false;
}

// Prepare memories.
if (output->size() != static_cast<std::size_t>(length)) {
output->resize(length);
}
Expand Down
2 changes: 1 addition & 1 deletion src/conversion/waveform_to_spectrum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Interdisciplinary Graduate School of //
// Science and Engineering //
// //
// 1996-2019 Nagoya Institute of Technology //
// 1996-2020 Nagoya Institute of Technology //
// Department of Computer Science //
// //
// All rights reserved. //
Expand Down
15 changes: 6 additions & 9 deletions src/main/spec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Interdisciplinary Graduate School of //
// Science and Engineering //
// //
// 1996-2019 Nagoya Institute of Technology //
// 1996-2020 Nagoya Institute of Technology //
// Department of Computer Science //
// //
// All rights reserved. //
Expand Down Expand Up @@ -129,16 +129,17 @@ void PrintUsage(std::ostream* stream) {
* - @b stdout
* - double-type spectrum
*
* The below example performs spectral analysis with a small value to add to the power spectrum.
* The below example performs spectral analysis. To prevent @f$log(0)@f$,
* a small value is add to power spectrum using @c -e option.
*
* @code{.sh}
* frame -l 400 -p 80 data.d | window -l 400 -L 512 | spec -l 512 -e 1e-6 > data.spec
* frame -l 400 data.d | window -l 400 -L 512 | spec -l 512 -e 1e-6 > data.sp
* @endcode
*
* Also, in the following example, the floor value is set as -30 dB per frame.
* Instead a relative floor value of spectrum can be set using @c -E option.
*
* @code{.sh}
* spec -E -30 data.d > data.spec
* spec -E -30 data.d2 > data.sp
* @endcode
*
* @param[in] argc Number of arguments.
Expand Down Expand Up @@ -281,7 +282,6 @@ int main(int argc, char* argv[]) {
return 1;
}

// open stream
std::ifstream ifs_for_numerator;
if (is_numerator_specified) {
ifs_for_numerator.open(numerator_coefficients_file,
Expand Down Expand Up @@ -355,9 +355,7 @@ int main(int argc, char* argv[]) {
return 1;
}
}

} else {
// get input file
const int num_input_files(argc - optind);
if (1 < num_input_files) {
std::ostringstream error_message;
Expand All @@ -367,7 +365,6 @@ int main(int argc, char* argv[]) {
}
const char* input_file(0 == num_input_files ? NULL : argv[optind]);

// open stream
std::ifstream ifs;
ifs.open(input_file, std::ios::in | std::ios::binary);
if (ifs.fail() && NULL != input_file) {
Expand Down

0 comments on commit 976cf4b

Please sign in to comment.