Audio{Format,Parser}: use shortcuts such as "dsd64" in log messages
This commit is contained in:
parent
cd0c06ba6e
commit
d7137586a9
1
NEWS
1
NEWS
|
@ -1,6 +1,7 @@
|
|||
ver 0.20.3 (not yet released)
|
||||
* protocol
|
||||
- "playlistadd" creates new playlist if it does not exist, as documented
|
||||
* use shortcuts such as "dsd64" in log messages
|
||||
|
||||
ver 0.20.2 (2017/01/15)
|
||||
* input
|
||||
|
|
|
@ -598,7 +598,11 @@ systemctl start mpd.socket</programlisting>
|
|||
<varname>32</varname> (signed 32 bit integer
|
||||
samples), <varname>f</varname> (32 bit floating
|
||||
point, -1.0 to 1.0), "<varname>dsd</varname>" means
|
||||
DSD (Direct Stream Digital).
|
||||
DSD (Direct Stream Digital). For DSD, there are
|
||||
special cases such as "<varname>dsd64</varname>",
|
||||
which allows you to omit the sample rate
|
||||
(e.g. <parameter>dsd512:2</parameter> for stereo
|
||||
DSD512, i.e. 22.5792 MHz).
|
||||
</para>
|
||||
<para>
|
||||
The sample rate is special for DSD:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -67,7 +67,8 @@ static constexpr AudioFormatStringTest af_string_tests[] = {
|
|||
{ AudioFormat(44100, SampleFormat::S16, 2), "44100:16:2" },
|
||||
{ AudioFormat(48000, SampleFormat::S24_P32, 6), "48000:24:6" },
|
||||
{ AudioFormat(192000, SampleFormat::FLOAT, 2), "192000:f:2" },
|
||||
{ AudioFormat(352800, SampleFormat::DSD, 2), "352800:dsd:2" },
|
||||
{ AudioFormat(352801, SampleFormat::DSD, 2), "352801:dsd:2" },
|
||||
{ AudioFormat(352800, SampleFormat::DSD, 2), "dsd64:2" },
|
||||
};
|
||||
|
||||
static constexpr AudioFormatStringTest af_mask_tests[] = {
|
||||
|
|
Loading…
Reference in New Issue