diff options
author | Max Kellermann <max@duempel.org> | 2009-11-10 17:11:34 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-12-02 22:29:50 +0100 |
commit | c412d6251e9cd3abe735b7622af4003502e54f72 (patch) | |
tree | 7344c13f62e4cc788c830c05d21bb7b5b47f5866 /src/audio_parser.c | |
parent | 68c2cfbb4067b2292e1ff1d4e7716ff370903f84 (diff) | |
download | mpd-c412d6251e9cd3abe735b7622af4003502e54f72.tar.gz mpd-c412d6251e9cd3abe735b7622af4003502e54f72.tar.xz mpd-c412d6251e9cd3abe735b7622af4003502e54f72.zip |
audio_format: changed "bits" to "enum sample_format"
This patch prepares support for floating point samples (and probably
other formats). It changes the meaning of the "bits" attribute from a
bit count to a symbolic value.
Diffstat (limited to '')
-rw-r--r-- | src/audio_parser.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/audio_parser.c b/src/audio_parser.c index df87be325..210ea7a62 100644 --- a/src/audio_parser.c +++ b/src/audio_parser.c @@ -27,6 +27,7 @@ #include "audio_format.h" #include "audio_check.h" +#include <assert.h> #include <stdlib.h> /** @@ -65,14 +66,16 @@ parse_sample_rate(const char *src, bool mask, uint32_t *sample_rate_r, } static bool -parse_sample_format(const char *src, bool mask, uint8_t *bits_r, +parse_sample_format(const char *src, bool mask, + enum sample_format *sample_format_r, const char **endptr_r, GError **error_r) { unsigned long value; char *endptr; + enum sample_format sample_format; if (mask && *src == '*') { - *bits_r = 0; + *sample_format_r = SAMPLE_FORMAT_UNDEFINED; *endptr_r = src + 1; return true; } @@ -82,10 +85,34 @@ parse_sample_format(const char *src, bool mask, uint8_t *bits_r, g_set_error(error_r, audio_parser_quark(), 0, "Failed to parse the sample format"); return false; - } else if (!audio_check_sample_format(value, error_r)) + } + + switch (value) { + case 8: + sample_format = SAMPLE_FORMAT_S8; + break; + + case 16: + sample_format = SAMPLE_FORMAT_S16; + break; + + case 24: + sample_format = SAMPLE_FORMAT_S24_P32; + break; + + case 32: + sample_format = SAMPLE_FORMAT_S32; + break; + + default: + g_set_error(error_r, audio_parser_quark(), 0, + "Invalid sample format: %lu", value); return false; + } + + assert(audio_valid_sample_format(sample_format)); - *bits_r = value; + *sample_format_r = sample_format; *endptr_r = endptr; return true; } @@ -121,7 +148,8 @@ audio_format_parse(struct audio_format *dest, const char *src, bool mask, GError **error_r) { uint32_t rate; - uint8_t bits, channels; + enum sample_format sample_format; + uint8_t channels; audio_format_clear(dest); @@ -138,7 +166,7 @@ audio_format_parse(struct audio_format *dest, const char *src, /* parse sample format */ - if (!parse_sample_format(src, mask, &bits, &src, error_r)) + if (!parse_sample_format(src, mask, &sample_format, &src, error_r)) return false; if (*src++ != ':') { @@ -158,7 +186,7 @@ audio_format_parse(struct audio_format *dest, const char *src, return false; } - audio_format_init(dest, rate, bits, channels); + audio_format_init(dest, rate, sample_format, channels); return true; } |