From 5028c30bc0c19fef8a3d023241d77678ca90c7f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 10 Oct 2023 12:39:04 -0400 Subject: [PATCH] audiofile: count samples with resampled format Change-Id: I451c66a9b9a8f806daa82406ca24936d4345b068 --- src/media/audio/sound/audiofile.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/media/audio/sound/audiofile.cpp b/src/media/audio/sound/audiofile.cpp index e5482b9e4a..f754f87b18 100644 --- a/src/media/audio/sound/audiofile.cpp +++ b/src/media/audio/sound/audiofile.cpp @@ -66,9 +66,9 @@ AudioFile::AudioFile(const std::string& fileName, unsigned int sampleRate, AVSam Resampler r {}; auto decoder = std::make_unique<MediaDecoder>( [&r, this, &buf, &total_samples](const std::shared_ptr<MediaFrame>& frame) mutable { - auto autoFrame = std::static_pointer_cast<AudioFrame>(frame); - total_samples += autoFrame->getFrameSize(); - buf.emplace_back(r.resample(std::move(autoFrame), format_)); + auto resampled = r.resample(std::move(std::static_pointer_cast<AudioFrame>(frame)), format_); + total_samples += resampled->getFrameSize(); + buf.emplace_back(std::move(resampled)); }); DeviceParams dev; dev.input = fileName; @@ -79,10 +79,10 @@ AudioFile::AudioFile(const std::string& fileName, unsigned int sampleRate, AVSam if (decoder->setupAudio() < 0) throw AudioFileException("Decoder setup failed: " + fileName); - + while (decoder->decode() != MediaDemuxer::Status::EndOfFile) ; - + buffer_->nb_samples = total_samples; buffer_->format = format_.sampleFormat; buffer_->sample_rate = format_.sample_rate; -- GitLab