Commit 603ce87a authored by Max Kellermann's avatar Max Kellermann

AudioFormat: split the printf() calls in ToString()

Prepare for formatting masks.
parent 4b16a8bf
...@@ -44,16 +44,21 @@ AudioFormat::ApplyMask(AudioFormat mask) noexcept ...@@ -44,16 +44,21 @@ AudioFormat::ApplyMask(AudioFormat mask) noexcept
StringBuffer<24> StringBuffer<24>
ToString(const AudioFormat af) noexcept ToString(const AudioFormat af) noexcept
{ {
StringBuffer<24> buffer;
char *p = buffer.data();
if (af.format == SampleFormat::DSD && af.sample_rate > 0 && if (af.format == SampleFormat::DSD && af.sample_rate > 0 &&
af.sample_rate % 44100 == 0) { af.sample_rate % 44100 == 0) {
/* use shortcuts such as "dsd64" which implies the /* use shortcuts such as "dsd64" which implies the
sample rate */ sample rate */
return StringFormat<24>("dsd%u:%u", p += sprintf(p, "dsd%u:", af.sample_rate * 8 / 44100);
af.sample_rate * 8 / 44100, } else {
af.channels); p += sprintf(p, "%u:%s:",
af.sample_rate,
sample_format_to_string(af.format));
} }
return StringFormat<24>("%u:%s:%u", p += sprintf(p, "%u", af.channels);
af.sample_rate, sample_format_to_string(af.format),
af.channels); return buffer;
} }
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