Audio{Format,Parser}: use shortcuts such as "dsd64" in log messages

This commit is contained in:
Max Kellermann
2017-01-17 09:25:18 +01:00
parent cd0c06ba6e
commit d7137586a9
5 changed files with 39 additions and 2 deletions

View File

@@ -45,6 +45,17 @@ StringBuffer<24>
ToString(const AudioFormat af)
{
StringBuffer<24> buffer;
if (af.format == SampleFormat::DSD && af.sample_rate > 0 &&
af.sample_rate % 44100 == 0) {
/* use shortcuts such as "dsd64" which implies the
sample rate */
snprintf(buffer.data(), buffer.capacity(), "dsd%u:%u",
af.sample_rate * 8 / 44100,
af.channels);
return buffer;
}
snprintf(buffer.data(), buffer.capacity(), "%u:%s:%u",
af.sample_rate, sample_format_to_string(af.format),
af.channels);

View File

@@ -137,6 +137,26 @@ ParseAudioFormat(const char *src, bool mask)
AudioFormat dest;
dest.Clear();
if (strncmp(src, "dsd", 3) == 0) {
/* allow format specifications such as "dsd64" which
implies the sample rate */
char *endptr;
auto dsd = strtoul(src + 3, &endptr, 10);
if (endptr > src + 3 && *endptr == ':' &&
dsd >= 32 && dsd <= 4096 && dsd % 2 == 0) {
dest.sample_rate = dsd * 44100 / 8;
dest.format = SampleFormat::DSD;
src = endptr + 1;
dest.channels = ParseChannelCount(src, mask, &src);
if (*src != 0)
throw FormatRuntimeError("Extra data after channel count: %s", src);
return dest;
}
}
/* parse sample rate */
dest.sample_rate = ParseSampleRate(src, mask, &src);