Skip to content

Commit b0e8793

Browse files
committed
SRC: smenc: handle pitch detection error
Signed-off-by: Stefan Westerfeld <[email protected]>
1 parent 3ddd990 commit b0e8793

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/smenc.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,26 @@ main (int argc, char **argv)
417417
exit (1);
418418
}
419419
}
420-
if (options.fundamental_freq_detect_note)
420+
auto detect_note = [&]
421421
{
422422
double note = detect_pitch (wav_data);
423+
if (note < 0)
424+
{
425+
fprintf (stderr, "%s: pitch detection failed\n", options.program_name.c_str());
426+
exit (1);
427+
}
428+
return note;
429+
};
430+
if (options.fundamental_freq_detect_note)
431+
{
432+
double note = detect_note();
423433
int round_note = lrint (note);
424434
options.fundamental_freq = freqFromNote (round_note);
425435
sm_printf ("Detected midi note %.2f, rounded to %d, fundamental frequency %.2f.\n", note, round_note, options.fundamental_freq);
426436
}
427437
if (options.fundamental_freq_detect_freq)
428438
{
429-
double note = detect_pitch (wav_data);
439+
double note = detect_note();
430440
options.fundamental_freq = freqFromNote (note);
431441
sm_printf ("Detected midi note %.2f, fundamental frequency %.2f.\n", note, options.fundamental_freq);
432442
}

0 commit comments

Comments
 (0)