aboutsummaryrefslogtreecommitdiff
path: root/src/snap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/snap.cpp')
-rw-r--r--src/snap.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/snap.cpp b/src/snap.cpp
index 25632e9..eab7001 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -54,13 +54,12 @@ public:
Sound(const std::shared_ptr<Clock>& clock,
const std::string& filename,
- AlarmVolume volume,
- int duration_minutes,
+ unsigned int volume,
+ unsigned int duration_minutes,
bool loop):
m_clock(clock),
m_filename(filename),
m_volume(volume),
- m_duration_minutes(duration_minutes),
m_loop(loop),
m_canberra_id(get_next_canberra_id()),
m_loop_end_time(clock->localtime().add_full(0, 0, 0, 0, duration_minutes, 0.0))
@@ -133,18 +132,17 @@ private:
g_clear_pointer(&props, ca_proplist_destroy);
}
- static float get_gain_level(const AlarmVolume volume)
+ static float get_gain_level(unsigned int volume)
{
- /* These values aren't set in stone --
- arrived at from from manual tests on Nexus 4 */
- switch (volume)
- {
- case ALARM_VOLUME_VERY_QUIET: return -8;
- case ALARM_VOLUME_QUIET: return -4;
- case ALARM_VOLUME_LOUD: return 4;
- case ALARM_VOLUME_VERY_LOUD: return 8;
- default: return 0;
- }
+ const unsigned int clamped_volume = CLAMP(volume, 1, 100);
+
+ /* This range isn't set in stone --
+ arrived at from manual tests on Nextus 4 */
+ constexpr float gain_low = -10;
+ constexpr float gain_high = 10;
+
+ constexpr float gain_range = gain_high - gain_low;
+ return gain_low + (gain_range * (clamped_volume / 100.0f));
}
static void on_done_playing(ca_context*, uint32_t, int rv, void* gself)
@@ -183,8 +181,7 @@ private:
const std::shared_ptr<Clock> m_clock;
const std::string m_filename;
- const AlarmVolume m_volume;
- const int m_duration_minutes;
+ const unsigned int m_volume;
const bool m_loop;
const int32_t m_canberra_id;
const DateTime m_loop_end_time;
@@ -197,8 +194,8 @@ class SoundBuilder
public:
void set_clock(const std::shared_ptr<Clock>& c) {m_clock = c;}
void set_filename(const std::string& s) {m_filename = s;}
- void set_volume(const AlarmVolume v) {m_volume = v;}
- void set_duration_minutes(int i) {m_duration_minutes=i;}
+ void set_volume(const unsigned int v) {m_volume = v;}
+ void set_duration_minutes(int unsigned i) {m_duration_minutes=i;}
void set_looping(bool b) {m_looping=b;}
Sound* operator()() {
@@ -212,8 +209,8 @@ public:
private:
std::shared_ptr<Clock> m_clock;
std::string m_filename;
- AlarmVolume m_volume = ALARM_VOLUME_NORMAL;
- int m_duration_minutes = 30;
+ unsigned int m_volume = 50;
+ unsigned int m_duration_minutes = 30;
bool m_looping = true;
};