summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Reid <dgreid@chromium.org>2012-03-26 01:12:33 -0700
committerDylan Reid <dgreid@chromium.org>2012-03-28 22:48:13 -0700
commit9ea33930817a59cd1ec72cfb3540611f7069a618 (patch)
treec83555e9b20a6abe94190a23631494cc19a66431
parent52017ffba20a94b4f7193109356f03903c7467ff (diff)
downloadadhd-9ea33930817a59cd1ec72cfb3540611f7069a618.tar.gz
CRAS: Add a configurable volume curve.
Create a new type of volume curve that allows for configurable max volume and step size for each volume step. BUG=chrome-os-partner:8155 TEST=updated volume curve unit tests. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: Iec7aea4793d15bbb730442f4c0d9ebf6b69eacff
-rw-r--r--cras/src/server/cras_volume_curve.c27
-rw-r--r--cras/src/server/cras_volume_curve.h9
-rw-r--r--cras/src/tests/volume_curve_unittest.cc12
3 files changed, 48 insertions, 0 deletions
diff --git a/cras/src/server/cras_volume_curve.c b/cras/src/server/cras_volume_curve.c
index b6719c75..3f7f385d 100644
--- a/cras/src/server/cras_volume_curve.c
+++ b/cras/src/server/cras_volume_curve.c
@@ -18,6 +18,19 @@ static long get_dBFS_default(const struct cras_volume_curve *curve,
return (volume - 100) * 100;
}
+/* Simple curve with configurable max volume and volume step. */
+struct stepped_curve {
+ struct cras_volume_curve curve;
+ long max_vol;
+ long step;
+};
+
+static long get_dBFS_step(const struct cras_volume_curve *curve, size_t volume)
+{
+ const struct stepped_curve *c = (const struct stepped_curve *)curve;
+ return c->max_vol - (c->step * (100 - volume));
+}
+
/*
* Exported Interface.
*/
@@ -31,6 +44,20 @@ struct cras_volume_curve *cras_volume_curve_create_default()
return curve;
}
+struct cras_volume_curve *cras_volume_curve_create_simple_step(
+ long max_volume,
+ long volume_step)
+{
+ struct stepped_curve *curve;
+ curve = (struct stepped_curve *)calloc(1, sizeof(*curve));
+ if (curve == NULL)
+ return NULL;
+ curve->curve.get_dBFS = get_dBFS_step;
+ curve->max_vol = max_volume;
+ curve->step = volume_step;
+ return &curve->curve;
+}
+
void cras_volume_curve_destroy(struct cras_volume_curve *curve)
{
free(curve);
diff --git a/cras/src/server/cras_volume_curve.h b/cras/src/server/cras_volume_curve.h
index a6a08c72..9683136c 100644
--- a/cras/src/server/cras_volume_curve.h
+++ b/cras/src/server/cras_volume_curve.h
@@ -25,6 +25,15 @@ struct cras_volume_curve {
*/
struct cras_volume_curve *cras_volume_curve_create_default();
+/* Creates a volume curve with a specified max volume and step.
+ * Args:
+ * max_volume - Maximum volume allowed in dBFS.
+ * volume_step - Number of dB to change for one volume tick.
+ */
+struct cras_volume_curve *cras_volume_curve_create_simple_step(
+ long max_volume,
+ long volume_step);
+
/* Destroys a curve created with cras_volume_curve_create_*.
* Args:
* curve - The curve to destroy.
diff --git a/cras/src/tests/volume_curve_unittest.cc b/cras/src/tests/volume_curve_unittest.cc
index f25d9563..5f40666d 100644
--- a/cras/src/tests/volume_curve_unittest.cc
+++ b/cras/src/tests/volume_curve_unittest.cc
@@ -19,6 +19,18 @@ TEST(VolumeCurve, DefaultCurve) {
EXPECT_EQ(0, curve->get_dBFS(curve, 100));
EXPECT_EQ(-10000, curve->get_dBFS(curve, 0));
EXPECT_EQ(-2500, curve->get_dBFS(curve, 75));
+ cras_volume_curve_destroy(curve);
+}
+
+TEST(VolumeCurve, SteppedCurve) {
+ struct cras_volume_curve *curve;
+ curve = cras_volume_curve_create_simple_step(-600, 75);
+ ASSERT_NE(static_cast<struct cras_volume_curve *>(NULL), curve);
+ EXPECT_EQ(-600 - 50 * 75, curve->get_dBFS(curve, 50));
+ EXPECT_EQ(-600, curve->get_dBFS(curve, 100));
+ EXPECT_EQ(-600 - 100 * 75, curve->get_dBFS(curve, 0));
+ EXPECT_EQ(-600 - 25 * 75, curve->get_dBFS(curve, 75));
+ cras_volume_curve_destroy(curve);
}
} // namespace