From 68d50dc0a6cf6886d0d6e01447bf15f3411c739f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 29 Sep 2004 22:04:44 +0000 Subject: add sample spec parameters to pacat git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@251 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/sample.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'polyp/sample.c') diff --git a/polyp/sample.c b/polyp/sample.c index 65ae8ff3..8c30386b 100644 --- a/polyp/sample.c +++ b/polyp/sample.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "sample.h" @@ -68,10 +69,10 @@ pa_usec_t pa_bytes_to_usec(uint64_t length, const struct pa_sample_spec *spec) { int pa_sample_spec_valid(const struct pa_sample_spec *spec) { assert(spec); - if (!spec->rate || !spec->channels) + if (spec->rate <= 0 || spec->channels <= 0) return 0; - if (spec->format >= PA_SAMPLE_MAX) + if (spec->format >= PA_SAMPLE_MAX || spec->format < 0) return 0; return 1; @@ -134,3 +135,27 @@ void pa_bytes_snprint(char *s, size_t l, unsigned v) { else snprintf(s, l, "%u B", (unsigned) v); } + +enum pa_sample_format pa_parse_sample_format(const char *format) { + + if (strcmp(format, "s16le") == 0) + return PA_SAMPLE_S16LE; + else if (strcmp(format, "s16be") == 0) + return PA_SAMPLE_S16BE; + else if (strcmp(format, "s16ne") == 0 || strcmp(format, "s16") == 0 || strcmp(format, "16") == 0) + return PA_SAMPLE_S16NE; + else if (strcmp(format, "u8") == 0 || strcmp(format, "8") == 0) + return PA_SAMPLE_U8; + else if (strcmp(format, "float32") == 0 || strcmp(format, "float32ne") == 0) + return PA_SAMPLE_FLOAT32; + else if (strcmp(format, "float32le") == 0) + return PA_SAMPLE_FLOAT32LE; + else if (strcmp(format, "float32be") == 0) + return PA_SAMPLE_FLOAT32BE; + else if (strcmp(format, "ulaw") == 0) + return PA_SAMPLE_ULAW; + else if (strcmp(format, "alaw") == 0) + return PA_SAMPLE_ALAW; + + return -1; +} -- cgit