This file is part of polypaudio.
polypaudio is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
+ it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Lesser General Public License
along with polypaudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
#include <stdio.h>
#include <assert.h>
#include <math.h>
+#include <string.h>
#include "sample.h"
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;
return 20*log10((double) v/PA_VOLUME_NORM);
}
+#define USER_DECIBEL_RANGE 30
+
+double pa_volume_to_user(pa_volume_t v) {
+ double dB = pa_volume_to_dB(v);
+
+ return dB < -USER_DECIBEL_RANGE ? 0 : dB/USER_DECIBEL_RANGE+1;
+}
+
+pa_volume_t pa_volume_from_user(double v) {
+
+ if (v <= 0)
+ return PA_VOLUME_MUTED;
+
+ return pa_volume_from_dB((v-1)*USER_DECIBEL_RANGE);
+}
+
void pa_bytes_snprint(char *s, size_t l, unsigned v) {
if (v >= ((unsigned) 1024)*1024*1024)
snprintf(s, l, "%0.1f GB", ((double) v)/1024/1024/1024);
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;
+}