MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / clip_audio_length

Method clip_audio_length

src/common/audio/audio_reader.cpp:367–388  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

365
366// ---------------------------------------------------------------------------
367bool AudioReader::clip_audio_length(audio_data_t& audio, double max_duration_second)
368{
369 if (audio.sample_rate <= 0 || audio.channels <= 0 || max_duration_second <= 0.0) {
370 return false;
371 }
372
373 if (audio.duration_seconds <= max_duration_second) {
374 return true; // nothing to clip
375 }
376
377 size_t max_frames = static_cast<size_t>(max_duration_second * audio.sample_rate);
378 size_t max_samples = max_frames * audio.channels;
379
380 if (max_samples < audio.samples.size()) {
381 audio.samples.resize(max_samples);
382 audio.num_samples = max_samples;
383 audio.num_frames = max_frames;
384 audio.duration_seconds = static_cast<double>(max_frames) / audio.sample_rate;
385 }
386
387 return true;
388}

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected