Commit 30c20118 authored by Adrien Béraud's avatar Adrien Béraud

resampler: add shortcut for AudioFrame

Change-Id: I2455975e8383f446f92ba685d6e1ffc9af766729
Reviewed-by: Philippe Gorley's avatarPhilippe Gorley <philippe.gorley@savoirfairelinux.com>
parent db1ef33d
......@@ -100,4 +100,33 @@ Resampler::resample(const AudioBuffer& dataIn, AudioBuffer& dataOut)
output->nb_samples, output->channels);
}
std::unique_ptr<AudioFrame>
Resampler::resample(std::unique_ptr<AudioFrame>&& in, const AudioFormat& format)
{
if (in->pointer()->sample_rate == format.sample_rate &&
in->pointer()->channels == format.nb_channels &&
(AVSampleFormat)in->pointer()->format == format.sampleFormat)
{
return std::move(in);
}
auto output = std::make_unique<AudioFrame>(format);
resample(in->pointer(), output->pointer());
return output;
}
std::shared_ptr<AudioFrame>
Resampler::resample(std::shared_ptr<AudioFrame>&& in, const AudioFormat& format)
{
if (in->pointer()->sample_rate == format.sample_rate &&
in->pointer()->channels == format.nb_channels &&
(AVSampleFormat)in->pointer()->format == format.sampleFormat)
{
return std::move(in);
}
auto output = std::make_shared<AudioFrame>(format);
resample(in->pointer(), output->pointer());
return output;
}
} // namespace ring
......@@ -51,6 +51,9 @@ class Resampler {
*/
void resample(const AudioBuffer& dataIn, AudioBuffer& dataOut);
std::unique_ptr<AudioFrame> resample(std::unique_ptr<AudioFrame>&& in, const AudioFormat& out);
std::shared_ptr<AudioFrame> resample(std::shared_ptr<AudioFrame>&& in, const AudioFormat& out);
private:
NON_COPYABLE(Resampler);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment