diff options
Diffstat (limited to 'src/pcm/PcmConvert.cxx')
-rw-r--r-- | src/pcm/PcmConvert.cxx | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx index 0552962aa..5501d8ddf 100644 --- a/src/pcm/PcmConvert.cxx +++ b/src/pcm/PcmConvert.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "PcmConvert.hxx" +#include "ConfiguredResampler.hxx" #include "AudioFormat.hxx" #include "util/ConstBuffer.hxx" #include "util/Error.hxx" @@ -33,7 +34,7 @@ const Domain pcm_convert_domain("pcm_convert"); bool pcm_convert_global_init(Error &error) { - return pcm_resample_global_init(error); + return pcm_resampler_global_init(error); } PcmConvert::PcmConvert() @@ -66,39 +67,51 @@ PcmConvert::Open(AudioFormat _src_format, AudioFormat _dest_format, if (format.format == SampleFormat::DSD) format.format = SampleFormat::FLOAT; - if (format.format != dest_format.format && - !format_converter.Open(format.format, dest_format.format, error)) + enable_resampler = format.sample_rate != dest_format.sample_rate; + if (enable_resampler) { + if (!resampler.Open(format, dest_format.sample_rate, error)) + return false; + + format.format = resampler.GetOutputSampleFormat(); + format.sample_rate = dest_format.sample_rate; + } + + enable_format = format.format != dest_format.format; + if (enable_format && + !format_converter.Open(format.format, dest_format.format, error)) { + if (enable_resampler) + resampler.Close(); return false; + } + format.format = dest_format.format; - if (format.channels != dest_format.channels && + enable_channels = format.channels != dest_format.channels; + if (enable_channels && !channels_converter.Open(format.format, format.channels, dest_format.channels, error)) { - format_converter.Close(); + if (enable_format) + format_converter.Close(); + if (enable_resampler) + resampler.Close(); return false; } - if (format.sample_rate != dest_format.sample_rate && - !resampler.Open(format, dest_format.sample_rate, error)) - return false; - return true; } void PcmConvert::Close() { - if (src_format.channels != dest_format.channels) + if (enable_channels) channels_converter.Close(); - - if (src_format.format != dest_format.format) + if (enable_format) format_converter.Close(); + if (enable_resampler) + resampler.Close(); dsd.Reset(); - if (src_format.sample_rate != dest_format.sample_rate) - resampler.Close(); - #ifndef NDEBUG src_format.Clear(); dest_format.Clear(); @@ -127,28 +140,29 @@ PcmConvert::Convert(const void *src, size_t src_size, format.format = SampleFormat::FLOAT; } - if (format.format != dest_format.format) { - buffer = format_converter.Convert(buffer, error); + if (enable_resampler) { + buffer = resampler.Resample(buffer, error); if (buffer.IsNull()) return nullptr; - format.format = dest_format.format; + format.format = resampler.GetOutputSampleFormat(); + format.sample_rate = dest_format.sample_rate; } - if (format.channels != dest_format.channels) { - buffer = channels_converter.Convert(buffer, error); + if (enable_format) { + buffer = format_converter.Convert(buffer, error); if (buffer.IsNull()) return nullptr; - format.channels = dest_format.channels; + format.format = dest_format.format; } - if (format.sample_rate != dest_format.sample_rate) { - buffer = resampler.Resample(buffer, error); + if (enable_channels) { + buffer = channels_converter.Convert(buffer, error); if (buffer.IsNull()) return nullptr; - format.sample_rate = dest_format.sample_rate; + format.channels = dest_format.channels; } *dest_size_r = buffer.size; |