summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-01-17 09:25:18 +0100
committerMax Kellermann <max@musicpd.org>2017-01-17 22:42:23 +0100
commitd7137586a991d19662bfe5d2fb14529ede799545 (patch)
tree9417f5025ca1548c084b6bfbbdce401b72aef1f2 /src
parentcd0c06ba6e0a6ee22f4e238f8e20ee3d80ca5ee7 (diff)
Audio{Format,Parser}: use shortcuts such as "dsd64" in log messages
Diffstat (limited to 'src')
-rw-r--r--src/AudioFormat.cxx11
-rw-r--r--src/AudioParser.cxx20
2 files changed, 31 insertions, 0 deletions
diff --git a/src/AudioFormat.cxx b/src/AudioFormat.cxx
index c3ebb2e6f..9a9f8ab5e 100644
--- a/src/AudioFormat.cxx
+++ b/src/AudioFormat.cxx
@@ -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);
diff --git a/src/AudioParser.cxx b/src/AudioParser.cxx
index 55e01b0cc..b2811cd94 100644
--- a/src/AudioParser.cxx
+++ b/src/AudioParser.cxx
@@ -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);