summaryrefslogtreecommitdiffstats
path: root/polyp/sample.c
diff options
context:
space:
mode:
Diffstat (limited to 'polyp/sample.c')
-rw-r--r--polyp/sample.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/polyp/sample.c b/polyp/sample.c
index edfe1959..3019f93b 100644
--- a/polyp/sample.c
+++ b/polyp/sample.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <assert.h>
+#include <math.h>
#include "sample.h"
@@ -104,3 +105,17 @@ pa_volume_t pa_volume_multiply(pa_volume_t a, pa_volume_t b) {
return (pa_volume_t) p;
}
+
+pa_volume_t pa_volume_from_dB(double f) {
+ if (f <= -200)
+ return PA_VOLUME_MUTED;
+
+ return (pa_volume_t) (pow(10, f/20)*PA_VOLUME_NORM);
+}
+
+double pa_volume_to_dB(pa_volume_t v) {
+ if (v == PA_VOLUME_MUTED)
+ return -200;
+
+ return 20*log10((double) v/PA_VOLUME_NORM);
+}