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

Prepare for formatting masks.
This commit is contained in:
Max Kellermann 2018-08-02 21:17:54 +02:00
parent 4b16a8bf84
commit 603ce87ac2

View File

@ -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;
}