From 63399bbfd8cc8c1a71ea5ee933177b06ed389eff Mon Sep 17 00:00:00 2001 From: fryshorts Date: Sat, 13 Dec 2014 16:13:20 +0100 Subject: [PATCH] libobs: Add peak hold property to volmeter Add a property to the volume meter that specifies the time for which peak value should be held until it is reset. --- libobs/obs-audio-controls.c | 27 +++++++++++++++++++++++++++ libobs/obs-audio-controls.h | 15 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/libobs/obs-audio-controls.c b/libobs/obs-audio-controls.c index 8a58ac107..e010a242c 100644 --- a/libobs/obs-audio-controls.c +++ b/libobs/obs-audio-controls.c @@ -58,6 +58,8 @@ struct obs_volmeter { unsigned int channels; unsigned int update_ms; unsigned int update_frames; + unsigned int peakhold_ms; + unsigned int peakhold_frames; }; static const char *fader_signals[] = { @@ -302,6 +304,7 @@ static void volmeter_update_audio_settings(obs_volmeter_t *volmeter) volmeter->channels = audio_output_get_channels(audio); volmeter->update_frames = volmeter->update_ms * sr / 1000; + volmeter->peakhold_frames = volmeter->peakhold_ms * sr / 1000; } obs_fader_t *obs_fader_create(enum obs_fader_type type) @@ -535,6 +538,7 @@ obs_volmeter_t *obs_volmeter_create(enum obs_fader_type type) volmeter->type = type; obs_volmeter_set_update_interval(volmeter, 50); + obs_volmeter_set_peak_hold(volmeter, 1500); return volmeter; fail: @@ -635,3 +639,26 @@ unsigned int obs_volmeter_get_update_interval(obs_volmeter_t *volmeter) return interval; } + +void obs_volmeter_set_peak_hold(obs_volmeter_t *volmeter, const unsigned int ms) +{ + if (!volmeter) + return; + + pthread_mutex_lock(&volmeter->mutex); + volmeter->peakhold_ms = ms; + volmeter_update_audio_settings(volmeter); + pthread_mutex_unlock(&volmeter->mutex); +} + +unsigned int obs_volmeter_get_peak_hold(obs_volmeter_t *volmeter) +{ + if (!volmeter) + return 0; + + pthread_mutex_lock(&volmeter->mutex); + const unsigned int peakhold = volmeter->peakhold_ms; + pthread_mutex_unlock(&volmeter->mutex); + + return peakhold; +} diff --git a/libobs/obs-audio-controls.h b/libobs/obs-audio-controls.h index e34a2249b..857c6816a 100644 --- a/libobs/obs-audio-controls.h +++ b/libobs/obs-audio-controls.h @@ -236,6 +236,21 @@ EXPORT void obs_volmeter_set_update_interval(obs_volmeter_t *volmeter, */ EXPORT unsigned int obs_volmeter_get_update_interval(obs_volmeter_t *volmeter); +/** + * @brief Set the peak hold time for the volume meter + * @param volmeter pointer to the volume meter object + * @param ms peak hold time in ms + */ +EXPORT void obs_volmeter_set_peak_hold(obs_volmeter_t *volmeter, + const unsigned int ms); + +/** + * @brief Get the peak hold time for the volume meter + * @param volmeter pointer to the volume meter object + * @return the peak hold time in ms + */ +EXPORT unsigned int obs_volmeter_get_peak_hold(obs_volmeter_t *volmeter); + #ifdef __cplusplus } #endif