Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pitch_spec #34

Merged
merged 11 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rename
  • Loading branch information
takenori-y committed May 16, 2023
commit d0fdcc2be5f812cb74836b50e728c5c8e0ad376e
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ set(MAIN_SOURCES
${SOURCE_DIR}/main/phase.cc
${SOURCE_DIR}/main/pitch.cc
${SOURCE_DIR}/main/pitch_mark.cc
${SOURCE_DIR}/main/pitch_spec.cc
${SOURCE_DIR}/main/poledf.cc
${SOURCE_DIR}/main/pqmf.cc
${SOURCE_DIR}/main/quantize.cc
Expand All @@ -328,7 +329,6 @@ set(MAIN_SOURCES
${SOURCE_DIR}/main/smcep.cc
${SOURCE_DIR}/main/snr.cc
${SOURCE_DIR}/main/sopr.cc
${SOURCE_DIR}/main/sp.cc
${SOURCE_DIR}/main/spec.cc
${SOURCE_DIR}/main/step.cc
${SOURCE_DIR}/main/swab.cc
Expand Down
2 changes: 2 additions & 0 deletions doc/main/ap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ ap

.. doxygenfile:: ap.cc

.. seealso:: :ref:`pitch`

.. doxygenclass:: sptk::AperiodicityExtraction
:members:
11 changes: 11 additions & 0 deletions doc/main/pitch_spec.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.. _pitch_spec:

pitch_spec
==========

.. doxygenfile:: pitch_spec.cc

.. seealso:: :ref:`spec` :ref:`pitch`

.. doxygenclass:: sptk::SpectrumExtraction
:members:
38 changes: 19 additions & 19 deletions src/main/sp.cc → src/main/pitch_spec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const sptk::SpectrumToSpectrum::InputOutputFormats kDefaultOutputFormat(
void PrintUsage(std::ostream* stream) {
// clang-format off
*stream << std::endl;
*stream << " sp - spectrum extraction" << std::endl;
*stream << " pitch_spec - pitch-adaptive spectral estimation" << std::endl;
*stream << std::endl;
*stream << " usage:" << std::endl;
*stream << " sp [ options ] f0file [ infile ] > stdout" << std::endl;
*stream << " pitch_spec [ options ] f0file [ infile ] > stdout" << std::endl; // NOLINT
*stream << " options:" << std::endl;
*stream << " -a a : algorithm used for ( int)[" << std::setw(5) << std::right << kDefaultAlgorithm << "][ 0 <= a <= 0 ]" << std::endl; // NOLINT
*stream << " spectrum estimation" << std::endl;
Expand Down Expand Up @@ -82,7 +82,7 @@ void PrintUsage(std::ostream* stream) {
} // namespace

/**
* @a sp [ @e option ] @e f0file [ @e infile ]
* @a pitch_spec [ @e option ] @e f0file [ @e infile ]
*
* - @b -a @e int
* - algorithm used for spectrum extraction
Expand Down Expand Up @@ -115,7 +115,7 @@ void PrintUsage(std::ostream* stream) {
*
* @code{.sh}
* pitch -s 16 -p 80 -L 80 -H 200 -o 1 < data.d > data.f0
* sp -s 16 -p 80 -q 1 data.f0 < data.d > data.sp
* pitch_spec -s 16 -p 80 -q 1 data.f0 < data.d > data.sp
* @endcode
*
* @param[in] argc Number of arguments.
Expand Down Expand Up @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) {
std::ostringstream error_message;
error_message << "The argument for the -a option must be an integer "
<< "in the range of " << min << " to " << max;
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
algorithm = static_cast<sptk::SpectrumExtraction::Algorithms>(tmp);
Expand All @@ -159,9 +159,9 @@ int main(int argc, char* argv[]) {
if (!sptk::ConvertStringToInteger(optarg, &fft_length) ||
fft_length <= 3) {
std::ostringstream error_message;
error_message << "The argument for the -l option must be a power of "
"2 and greater than 3";
sptk::PrintErrorMessage("sp", error_message);
error_message
<< "The argument for the -l option must be greater than 3";
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
break;
Expand All @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) {
std::ostringstream error_message;
error_message
<< "The argument for the -p option must be a positive integer";
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
break;
Expand All @@ -185,7 +185,7 @@ int main(int argc, char* argv[]) {
std::ostringstream error_message;
error_message << "The argument for the -s option must be in a number "
<< "in the interval [" << min << ", " << max << "]";
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
break;
Expand All @@ -199,7 +199,7 @@ int main(int argc, char* argv[]) {
std::ostringstream error_message;
error_message << "The argument for the -q option must be an integer "
<< "in the range of " << min << " to " << max;
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
input_format = static_cast<InputFormats>(tmp);
Expand All @@ -216,7 +216,7 @@ int main(int argc, char* argv[]) {
std::ostringstream error_message;
error_message << "The argument for the -o option must be an integer "
<< "in the range of " << min << " to " << max;
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
output_format =
Expand Down Expand Up @@ -246,7 +246,7 @@ int main(int argc, char* argv[]) {
} else {
std::ostringstream error_message;
error_message << "Just two input files, f0file and infile, are required";
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}

Expand All @@ -259,7 +259,7 @@ int main(int argc, char* argv[]) {
if (ifs.fail()) {
std::ostringstream error_message;
error_message << "Cannot open file " << f0_file;
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
std::istream& input_stream(ifs);
Expand Down Expand Up @@ -301,7 +301,7 @@ int main(int argc, char* argv[]) {
if (ifs.fail() && NULL != raw_file) {
std::ostringstream error_message;
error_message << "Cannot open file " << raw_file;
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
std::istream& input_stream(ifs.fail() ? std::cin : ifs);
Expand All @@ -318,7 +318,7 @@ int main(int argc, char* argv[]) {
if (!spectrum_extraction.IsValid()) {
std::ostringstream error_message;
error_message << "FFT length must be a power of 2";
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}

Expand All @@ -330,7 +330,7 @@ int main(int argc, char* argv[]) {
std::ostringstream error_message;
error_message
<< "Failed to extract spectrum (consider increasing FFT length)";
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}

Expand All @@ -341,14 +341,14 @@ int main(int argc, char* argv[]) {
if (!spectrum_to_spectrum.Run(tmp, &output)) {
std::ostringstream error_message;
error_message << "Failed to convert spectrum";
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}

if (!sptk::WriteStream(0, output_length, output, &std::cout, NULL)) {
std::ostringstream error_message;
error_message << "Failed to write spectrum";
sptk::PrintErrorMessage("sp", error_message);
sptk::PrintErrorMessage("pitch_spec", error_message);
return 1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_sp.bats → test/test_pitch_spec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

sptk3=tools/sptk/bin
sptk4=bin
tmp=test_sp
tmp=test_pitch_spec
data=asset/data.short

setup() {
Expand All @@ -31,6 +31,6 @@ teardown() {
@test "sp: valgrind" {
$sptk3/x2x +sd $data > $tmp/0
$sptk4/pitch $tmp/0 > $tmp/1
run valgrind $sptk4/sp -l 1024 $tmp/1 $tmp/0
run valgrind $sptk4/pitch_spec -l 1024 $tmp/1 $tmp/0
[ "$(echo "${lines[-1]}" | sed -r 's/.*SUMMARY: ([0-9]*) .*/\1/')" -eq 0 ]
}