7470 Fix crash when importing short audio (#9096)

(cherry picked from commit efc959a77f2fbdd25966d70b32da91a384db16ca)
Signed-off-by: Avery King <gperson@disroot.org>
This commit is contained in:
Dmitry Makarenko
2025-07-18 13:35:52 +03:00
committed by Avery King
parent 73ea436037
commit 830acf7838
2 changed files with 5 additions and 2 deletions

View File

@@ -137,9 +137,10 @@ std::optional<MusicalMeter> GetMusicalMeterFromSignal(
if (audio.GetSampleRate() <= 0)
return {};
const auto duration = 1. * audio.GetNumSamples() / audio.GetSampleRate();
if (duration > 60)
if (duration > 60 || duration < 1)
// A file longer than 1 minute is most likely not a loop, and processing
// it would be costly.
// A file shorter than 1 second is too short to be a loop.
return {};
DecimatingMirAudioReader decimatedAudio { audio };
return GetMeterUsingTatumQuantizationFit(

View File

@@ -21,7 +21,7 @@ namespace MIR
{
namespace
{
constexpr auto twoPi = 2 * 3.14159265358979323846;
constexpr auto twoPi = 2 * M_PI;
int GetFrameSize(int sampleRate)
{
@@ -94,6 +94,8 @@ int StftFrameProvider::GetSampleRate() const
double StftFrameProvider::GetFrameRate() const
{
if (mHopSize <= 0)
return 0;
return 1. * mAudio.GetSampleRate() / mHopSize;
}