diff mbox

[FFmpeg-devel] ffplay: change keyboard volume control to logarithmic

Message ID 20170205003109.13327-1-cus@passwd.hu
State Accepted
Commit 3aae1eff1263a91086f48ae5162aa28f8f9dc072
Headers show

Commit Message

Marton Balint Feb. 5, 2017, 12:31 a.m. UTC
The command line parameter remains linear.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 ffplay.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Marton Balint Feb. 8, 2017, 9:52 p.m. UTC | #1
On Sun, 5 Feb 2017, Marton Balint wrote:

> The command line parameter remains linear.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> ffplay.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/ffplay.c b/ffplay.c
> index 1c9db73..cf138dc 100644
> --- a/ffplay.c
> +++ b/ffplay.c
> @@ -73,8 +73,8 @@ const int program_birth_year = 2003;
> /* Calculate actual buffer size keeping in mind not cause too frequent audio callbacks */
> #define SDL_AUDIO_MAX_CALLBACKS_PER_SEC 30
> 
> -/* Step size for volume control */
> -#define SDL_VOLUME_STEP (SDL_MIX_MAXVOLUME / 50)
> +/* Step size for volume control in dB */
> +#define SDL_VOLUME_STEP (0.75)
> 
> /* no AV sync correction is done if below the minimum AV sync threshold */
> #define AV_SYNC_THRESHOLD_MIN 0.04
> @@ -1450,9 +1450,11 @@ static void toggle_mute(VideoState *is)
>     is->muted = !is->muted;
> }
> 
> -static void update_volume(VideoState *is, int sign, int step)
> +static void update_volume(VideoState *is, int sign, double step)
> {
> -    is->audio_volume = av_clip(is->audio_volume + sign * step, 0, SDL_MIX_MAXVOLUME);
> +    double volume_level = is->audio_volume ? (20 * log(is->audio_volume / (double)SDL_MIX_MAXVOLUME) / log(10)) : -1000.0;
> +    int new_volume = lrint(SDL_MIX_MAXVOLUME * pow(10.0, (volume_level + sign * step) / 20.0));
> +    is->audio_volume = av_clip(is->audio_volume == new_volume ? (is->audio_volume + sign) : new_volume, 0, SDL_MIX_MAXVOLUME);
> }
> 
> static void step_to_next_frame(VideoState *is)
> --

Pushed.

Regards,
Marton
diff mbox

Patch

diff --git a/ffplay.c b/ffplay.c
index 1c9db73..cf138dc 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -73,8 +73,8 @@  const int program_birth_year = 2003;
 /* Calculate actual buffer size keeping in mind not cause too frequent audio callbacks */
 #define SDL_AUDIO_MAX_CALLBACKS_PER_SEC 30
 
-/* Step size for volume control */
-#define SDL_VOLUME_STEP (SDL_MIX_MAXVOLUME / 50)
+/* Step size for volume control in dB */
+#define SDL_VOLUME_STEP (0.75)
 
 /* no AV sync correction is done if below the minimum AV sync threshold */
 #define AV_SYNC_THRESHOLD_MIN 0.04
@@ -1450,9 +1450,11 @@  static void toggle_mute(VideoState *is)
     is->muted = !is->muted;
 }
 
-static void update_volume(VideoState *is, int sign, int step)
+static void update_volume(VideoState *is, int sign, double step)
 {
-    is->audio_volume = av_clip(is->audio_volume + sign * step, 0, SDL_MIX_MAXVOLUME);
+    double volume_level = is->audio_volume ? (20 * log(is->audio_volume / (double)SDL_MIX_MAXVOLUME) / log(10)) : -1000.0;
+    int new_volume = lrint(SDL_MIX_MAXVOLUME * pow(10.0, (volume_level + sign * step) / 20.0));
+    is->audio_volume = av_clip(is->audio_volume == new_volume ? (is->audio_volume + sign) : new_volume, 0, SDL_MIX_MAXVOLUME);
 }
 
 static void step_to_next_frame(VideoState *is)