Commit 25164969 authored by Max Kellermann's avatar Max Kellermann

audio_format: add DSD sample format

Basic support for Direct Stream Digital. No conversion yet, and no decoder/output plugin support.
parent 3b565b5f
...@@ -71,6 +71,12 @@ sample_format_to_string(enum sample_format format) ...@@ -71,6 +71,12 @@ sample_format_to_string(enum sample_format format)
case SAMPLE_FORMAT_FLOAT: case SAMPLE_FORMAT_FLOAT:
return "f"; return "f";
case SAMPLE_FORMAT_DSD:
return "dsd";
case SAMPLE_FORMAT_DSD_LSBFIRST:
return "dsdl";
} }
/* unreachable */ /* unreachable */
......
...@@ -49,6 +49,18 @@ enum sample_format { ...@@ -49,6 +49,18 @@ enum sample_format {
* range is -1.0f to +1.0f. * range is -1.0f to +1.0f.
*/ */
SAMPLE_FORMAT_FLOAT, SAMPLE_FORMAT_FLOAT,
/**
* Direct Stream Digital. 1-bit samples; each frame has one
* byte (8 samples) per channel.
*/
SAMPLE_FORMAT_DSD,
/**
* Same as #SAMPLE_FORMAT_DSD, but the least significant bit
* comes first.
*/
SAMPLE_FORMAT_DSD_LSBFIRST,
}; };
static const unsigned MAX_CHANNELS = 8; static const unsigned MAX_CHANNELS = 8;
...@@ -175,6 +187,8 @@ audio_valid_sample_format(enum sample_format format) ...@@ -175,6 +187,8 @@ audio_valid_sample_format(enum sample_format format)
case SAMPLE_FORMAT_S24_P32: case SAMPLE_FORMAT_S24_P32:
case SAMPLE_FORMAT_S32: case SAMPLE_FORMAT_S32:
case SAMPLE_FORMAT_FLOAT: case SAMPLE_FORMAT_FLOAT:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
return true; return true;
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
...@@ -251,6 +265,11 @@ sample_format_size(enum sample_format format) ...@@ -251,6 +265,11 @@ sample_format_size(enum sample_format format)
case SAMPLE_FORMAT_FLOAT: case SAMPLE_FORMAT_FLOAT:
return 4; return 4;
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
/* each frame has 8 samples per channel */
return 1;
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
return 0; return 0;
} }
......
...@@ -87,6 +87,18 @@ parse_sample_format(const char *src, bool mask, ...@@ -87,6 +87,18 @@ parse_sample_format(const char *src, bool mask,
return true; return true;
} }
if (memcmp(src, "dsd", 3) == 0) {
if (src[3] == 'l') {
*sample_format_r = SAMPLE_FORMAT_DSD_LSBFIRST;
*endptr_r = src + 4;
} else {
*sample_format_r = SAMPLE_FORMAT_DSD;
*endptr_r = src + 3;
}
return true;
}
value = strtoul(src, &endptr, 10); value = strtoul(src, &endptr, 10);
if (endptr == src) { if (endptr == src) {
g_set_error(error_r, audio_parser_quark(), 0, g_set_error(error_r, audio_parser_quark(), 0,
......
...@@ -103,6 +103,8 @@ flac_convert(void *dest, ...@@ -103,6 +103,8 @@ flac_convert(void *dest,
case SAMPLE_FORMAT_S24: case SAMPLE_FORMAT_S24:
case SAMPLE_FORMAT_FLOAT: case SAMPLE_FORMAT_FLOAT:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
/* unreachable */ /* unreachable */
assert(false); assert(false);
......
...@@ -194,6 +194,8 @@ get_bitformat(enum sample_format sample_format) ...@@ -194,6 +194,8 @@ get_bitformat(enum sample_format sample_format)
{ {
switch (sample_format) { switch (sample_format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
return SND_PCM_FORMAT_UNKNOWN; return SND_PCM_FORMAT_UNKNOWN;
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
......
...@@ -396,6 +396,8 @@ sample_format_to_oss(enum sample_format format) ...@@ -396,6 +396,8 @@ sample_format_to_oss(enum sample_format format)
switch (format) { switch (format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_FLOAT: case SAMPLE_FORMAT_FLOAT:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
return AFMT_QUERY; return AFMT_QUERY;
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
......
...@@ -74,6 +74,8 @@ pcm_byteswap(struct pcm_buffer *buffer, enum sample_format format, ...@@ -74,6 +74,8 @@ pcm_byteswap(struct pcm_buffer *buffer, enum sample_format format,
return NULL; return NULL;
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
return src; return src;
case SAMPLE_FORMAT_S16: case SAMPLE_FORMAT_S16:
......
...@@ -77,6 +77,8 @@ pcm_convert_channels(struct pcm_buffer *buffer, enum sample_format format, ...@@ -77,6 +77,8 @@ pcm_convert_channels(struct pcm_buffer *buffer, enum sample_format format,
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
case SAMPLE_FORMAT_S24: case SAMPLE_FORMAT_S24:
case SAMPLE_FORMAT_FLOAT: case SAMPLE_FORMAT_FLOAT:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
g_set_error(error_r, pcm_convert_quark(), 0, g_set_error(error_r, pcm_convert_quark(), 0,
"Channel conversion not implemented for format '%s'", "Channel conversion not implemented for format '%s'",
sample_format_to_string(format)); sample_format_to_string(format));
......
...@@ -147,6 +147,8 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither, ...@@ -147,6 +147,8 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
switch (src_format) { switch (src_format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
break; break;
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
...@@ -265,6 +267,8 @@ pcm_convert_to_24(struct pcm_buffer *buffer, ...@@ -265,6 +267,8 @@ pcm_convert_to_24(struct pcm_buffer *buffer,
switch (src_format) { switch (src_format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
break; break;
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
...@@ -389,6 +393,8 @@ pcm_convert_to_32(struct pcm_buffer *buffer, ...@@ -389,6 +393,8 @@ pcm_convert_to_32(struct pcm_buffer *buffer,
switch (src_format) { switch (src_format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
break; break;
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
...@@ -524,6 +530,8 @@ pcm_convert_to_float(struct pcm_buffer *buffer, ...@@ -524,6 +530,8 @@ pcm_convert_to_float(struct pcm_buffer *buffer,
{ {
switch (src_format) { switch (src_format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
break; break;
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
......
...@@ -120,6 +120,8 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size, ...@@ -120,6 +120,8 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size,
switch (format) { switch (format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_S24: case SAMPLE_FORMAT_S24:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
/* not implemented */ /* not implemented */
return false; return false;
...@@ -229,6 +231,8 @@ pcm_add(void *buffer1, const void *buffer2, size_t size, ...@@ -229,6 +231,8 @@ pcm_add(void *buffer1, const void *buffer2, size_t size,
switch (format) { switch (format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_S24: case SAMPLE_FORMAT_S24:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
/* not implemented */ /* not implemented */
return false; return false;
......
...@@ -159,6 +159,8 @@ pcm_volume(void *buffer, size_t length, ...@@ -159,6 +159,8 @@ pcm_volume(void *buffer, size_t length,
switch (format) { switch (format) {
case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_UNDEFINED:
case SAMPLE_FORMAT_S24: case SAMPLE_FORMAT_S24:
case SAMPLE_FORMAT_DSD:
case SAMPLE_FORMAT_DSD_LSBFIRST:
/* not implemented */ /* not implemented */
return false; return false;
......
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