]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
mtmd: correcting duplicate empty audio chunks for short inputs (#26536)
authorAbhinay Krishna <redacted>
Tue, 4 Aug 2026 20:05:56 +0000 (16:05 -0400)
committerGitHub <redacted>
Tue, 4 Aug 2026 20:05:56 +0000 (22:05 +0200)
* correcting duplicate empty audio chunks for short inputs

* tests.sh code restored

tools/mtmd/mtmd-audio.cpp

index 7fbc18ea939676dea5f72f040249e82ddff8b7b8..ca4b64efa4a4c77e73bb4c9f82037fd6e3f99f4a 100644 (file)
@@ -556,10 +556,8 @@ bool mtmd_audio_preprocessor_whisper::preprocess(const float *                 s
     }
 
     std::vector<float> smpl;
-    // if input is too short, pad with zeros
-    // this is to avoid potential issues with stage1/2 padding in log_mel_spectrogram
-    // TODO: maybe handle this better
-    size_t min_samples = (size_t) hparams.audio_sample_rate * (hparams.audio_chunk_len + 1);  // +1 second margin
+    // reflection padding needs one sample plus half an FFT window
+    size_t min_samples = (size_t) hparams.audio_n_fft / 2 + 1;
     if (n_samples < min_samples) {
         smpl.resize(min_samples, 0.0f);
         std::memcpy(smpl.data(), samples, n_samples * sizeof(float));