From 6c818bb37a55ca44cb6241a29a836332191b476c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 13 Dec 2016 20:55:48 +0100 Subject: [PATCH] AudioFormat: add method WithMask(), shortcut for ApplyMask() --- src/AudioFormat.hxx | 7 +++++++ src/decoder/DecoderControl.cxx | 3 +-- src/output/OutputThread.cxx | 3 +-- test/run_convert.cxx | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/AudioFormat.hxx b/src/AudioFormat.hxx index 891056338..37d806af1 100644 --- a/src/AudioFormat.hxx +++ b/src/AudioFormat.hxx @@ -159,6 +159,13 @@ struct AudioFormat { void ApplyMask(AudioFormat mask); + gcc_pure + AudioFormat WithMask(AudioFormat mask) const { + AudioFormat result = *this; + result.ApplyMask(mask); + return result; + } + /** * Returns the size of each (mono) sample in bytes. */ diff --git a/src/decoder/DecoderControl.cxx b/src/decoder/DecoderControl.cxx index f2915a3f7..259d51a1f 100644 --- a/src/decoder/DecoderControl.cxx +++ b/src/decoder/DecoderControl.cxx @@ -64,8 +64,7 @@ DecoderControl::SetReady(const AudioFormat audio_format, assert(audio_format.IsValid()); in_audio_format = audio_format; - out_audio_format = audio_format; - out_audio_format.ApplyMask(configured_audio_format); + out_audio_format = audio_format.WithMask(configured_audio_format); seekable = _seekable; total_time = _duration; diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index 513d6babb..bce998949 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -159,8 +159,7 @@ AudioOutput::Open() assert(filter_audio_format.IsValid()); - out_audio_format = filter_audio_format; - out_audio_format.ApplyMask(config_audio_format); + out_audio_format = filter_audio_format.WithMask(config_audio_format); mutex.unlock(); diff --git a/test/run_convert.cxx b/test/run_convert.cxx index 13d69a242..f4a3f1adc 100644 --- a/test/run_convert.cxx +++ b/test/run_convert.cxx @@ -49,8 +49,8 @@ try { const auto in_audio_format = ParseAudioFormat(argv[1], false); const auto out_audio_format_mask = ParseAudioFormat(argv[2], false); - auto out_audio_format = in_audio_format; - out_audio_format.ApplyMask(out_audio_format_mask); + const auto out_audio_format = + in_audio_format.WithMask(out_audio_format_mask); const size_t in_frame_size = in_audio_format.GetFrameSize();