Skip to content

Commit

Permalink
fix lpc2lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
takenori-y committed Dec 5, 2023
1 parent 058615f commit bc4a615
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class LinearPredictiveCoefficientsToLineSpectralPairs {

/**
* @param[in] num_order Order of coefficients, @f$M@f$.
* @param[in] num_split Number of splits of unit circle.
* @param[in] num_split Number of splits of unit circle quadrant.
* @param[in] num_iteration Number of iterations.
* @param[in] convergence_threshold Convergence threshold.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ LinearPredictiveCoefficientsToLineSpectralPairs::
num_iteration_(num_iteration),
convergence_threshold_(convergence_threshold),
is_valid_(true) {
if (num_order_ < 0 || num_split_ <= 0 || num_iteration_ <= 0 ||
if (num_order_ < 0 || num_split_ <= 0 || num_iteration_ < 0 ||
convergence_threshold_ < 0.0) {
is_valid_ = false;
return;
Expand Down Expand Up @@ -123,9 +123,7 @@ bool LinearPredictiveCoefficientsToLineSpectralPairs::Run(

// Search roots of polynomials.
const double delta(1.0 / num_split_);
const double x_max(1.0 - delta);
const double x_min(-1.0 - delta);
for (double x(x_max); x_min < x; x -= delta) {
for (double x(1.0 - delta); -1.0 <= x; x -= delta) {
double y(CalculateChebyshevPolynomial(*c, x));

if (y * y_prev <= 0.0) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/lpc2lsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void PrintUsage(std::ostream* stream) {
*stream << " -h : print this message" << std::endl;
*stream << " (level 2)" << std::endl;
*stream << " -n n : number of splits of unit circle ( int)[" << std::setw(5) << std::right << kDefaultNumSplit << "][ 1 <= n <= ]" << std::endl; // NOLINT
*stream << " -i i : maximum number of iterations ( int)[" << std::setw(5) << std::right << kDefaultNumIteration << "][ 1 <= i <= ]" << std::endl; // NOLINT
*stream << " -i i : maximum number of iterations ( int)[" << std::setw(5) << std::right << kDefaultNumIteration << "][ 0 <= i <= ]" << std::endl; // NOLINT
*stream << " -d d : convergence threshold (double)[" << std::setw(5) << std::right << kDefaultConvergenceThreshold << "][ 0.0 <= d <= ]" << std::endl; // NOLINT
*stream << " infile:" << std::endl;
*stream << " linear predictive coefficients (double)[stdin]" << std::endl; // NOLINT
Expand Down Expand Up @@ -106,9 +106,9 @@ void PrintUsage(std::ostream* stream) {
* \arg @c 2 frequency in kHz
* \arg @c 3 frequency in Hz
* - @b -n @e int
* - number of splits of unit circle @f$(1 \le S)@f$
* - number of splits of unit circle quadrant @f$(1 \le S)@f$
* - @b -i @e int
* - maximum number of iterations @f$(1 \le N)@f$
* - maximum number of iterations @f$(0 \le N)@f$
* - @b -d @e double
* - convergence threshold @f$(0 \le \epsilon)@f$
* - @b infile @e str
Expand Down Expand Up @@ -206,10 +206,10 @@ int main(int argc, char* argv[]) {
}
case 'i': {
if (!sptk::ConvertStringToInteger(optarg, &num_iteration) ||
num_iteration <= 0) {
num_iteration < 0) {
std::ostringstream error_message;
error_message
<< "The argument for the -i option must be a positive integer";
error_message << "The argument for the -i option must be a "
<< "non-negative integer";
sptk::PrintErrorMessage("lpc2lsp", error_message);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_lpc2lsp.bats
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ teardown() {

@test "lpc2lsp: reversibility" {
$sptk3/nrand -l 400 | $sptk3/lpc -l 400 -m 12 > $tmp/1
$sptk4/lpc2lsp -m 12 $tmp/1 | $sptk4/lsp2lpc -m 12 > $tmp/2
$sptk4/lpc2lsp -m 12 -i 4 $tmp/1 | $sptk4/lsp2lpc -m 12 > $tmp/2
run $sptk4/aeq $tmp/1 $tmp/2
[ "$status" -eq 0 ]
}
Expand Down

0 comments on commit bc4a615

Please sign in to comment.