From 3255261dd7ba9eda3e49ed9b84131c8d93653084 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 7 Jul 2014 20:35:17 -0500 Subject: use GStreamer's full volume range. --- src/snap.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index cea09d7..8a86521 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -131,10 +131,17 @@ private: gst_element_set_state (m_play, GST_STATE_PLAYING); } + // convert settings range [1..100] to gst playbin's range is [0...1.0] gdouble get_volume() const { - // input int range is [1..100]; gst playbin's range is [0...1.0] - return CLAMP(m_volume, 1, 100) / 100.0; + constexpr int in_range_lo = 1; + constexpr int in_range_hi = 100; + const double in = CLAMP(m_volume, in_range_lo, in_range_hi); + const double pct = (in - in_range_lo) / (in_range_hi - in_range_lo); + + constexpr double out_range_lo = 0.0; + constexpr double out_range_hi = 1.0; + return out_range_lo + (pct * (out_range_hi - out_range_lo)); } static gboolean bus_callback(GstBus*, GstMessage* msg, gpointer gself) -- cgit v1.2.3