From 603ce87ac27ac766601d8d9398d466101bee2bb0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 2 Aug 2018 21:17:54 +0200 Subject: [PATCH] AudioFormat: split the printf() calls in ToString() Prepare for formatting masks. --- src/AudioFormat.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/AudioFormat.cxx b/src/AudioFormat.cxx index 13d3709f9..c4c654357 100644 --- a/src/AudioFormat.cxx +++ b/src/AudioFormat.cxx @@ -44,16 +44,21 @@ AudioFormat::ApplyMask(AudioFormat mask) noexcept StringBuffer<24> ToString(const AudioFormat af) noexcept { + StringBuffer<24> buffer; + char *p = buffer.data(); + if (af.format == SampleFormat::DSD && af.sample_rate > 0 && af.sample_rate % 44100 == 0) { /* use shortcuts such as "dsd64" which implies the sample rate */ - return StringFormat<24>("dsd%u:%u", - af.sample_rate * 8 / 44100, - af.channels); + p += sprintf(p, "dsd%u:", af.sample_rate * 8 / 44100); + } else { + p += sprintf(p, "%u:%s:", + af.sample_rate, + sample_format_to_string(af.format)); } - return StringFormat<24>("%u:%s:%u", - af.sample_rate, sample_format_to_string(af.format), - af.channels); + p += sprintf(p, "%u", af.channels); + + return buffer; }