[vlc-devel] [PATCH] cleanup fine grain control of playback rate
Rov Juvano
rovjuvano at users.sourceforge.net
Thu Jul 3 09:43:47 CEST 2008
- Reverts rate-{slower,faster} to previous 2x behavior
- Adds rate-{slower,faster}-step (inc/dec by musical semi-tone ~1.05x)
- Adds rate-normal
---
src/input/input.c | 60 +++++++++++--------------------------------
src/input/input_internal.h | 2 +
2 files changed, 18 insertions(+), 44 deletions(-)
diff --git a/src/input/input.c b/src/input/input.c
index 90ce56a..ac203d4 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -34,6 +34,7 @@
#include <ctype.h>
#include <limits.h>
#include <assert.h>
+#include <math.h>
#include "input_internal.h"
@@ -98,7 +99,7 @@ static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_atta
* Variables for _public_ use:
* * Get and Set:
* - state
- * - rate,rate-slower, rate-faster
+ * - rate, rate-slower, rate-faster, rate-slower-step, rate-faster-step
* - position, position-offset
* - time, time-offset
* - title,title-next,title-prev
@@ -1599,54 +1600,25 @@ static bool Control( input_thread_t *p_input, int i_type,
case INPUT_CONTROL_SET_RATE:
case INPUT_CONTROL_SET_RATE_SLOWER:
case INPUT_CONTROL_SET_RATE_FASTER:
+ case INPUT_CONTROL_SET_RATE_SLOWER_STEP:
+ case INPUT_CONTROL_SET_RATE_FASTER_STEP:
{
int i_rate;
if( i_type == INPUT_CONTROL_SET_RATE )
- {
i_rate = val.i_int;
- }
- else
- {
- static const int ppi_factor[][2] = {
- {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
- {1,1},
- {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
- {0,0}
- };
- int i_error;
- int i_idx;
- int i;
-
- i_error = INT_MAX;
- i_idx = -1;
- for( i = 0; ppi_factor[i][0] != 0; i++ )
- {
- const int i_test_r = INPUT_RATE_DEFAULT * ppi_factor[i][0] / ppi_factor[i][1];
- const int i_test_e = abs(p_input->p->i_rate - i_test_r);
- if( i_test_e < i_error )
- {
- i_idx = i;
- i_error = i_test_e;
- }
- }
- assert( i_idx >= 0 && ppi_factor[i_idx][0] != 0 );
-
- if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
- {
- if( ppi_factor[i_idx+1][0] > 0 )
- i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx+1][0] / ppi_factor[i_idx+1][1];
- else
- i_rate = INPUT_RATE_MAX+1;
- }
- else
- {
- assert( i_type == INPUT_CONTROL_SET_RATE_FASTER );
- if( i_idx > 0 )
- i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx-1][0] / ppi_factor[i_idx-1][1];
- else
- i_rate = INPUT_RATE_MIN-1;
- }
+ else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
+ i_rate = p_input->p->i_rate / 2;
+ else if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
+ i_rate = p_input->p->i_rate * 2;
+ else { /* STEP */
+ double d_exp = 12 * log( (double)INPUT_RATE_DEFAULT / p_input->p->i_rate ) / log( 2 );
+ int i_exp = (int) ( ( d_exp > 0 ) ? d_exp + .5 : d_exp - .5 );
+ if( i_type == INPUT_CONTROL_SET_RATE_SLOWER_STEP )
+ i_exp--;
+ else
+ i_exp++;
+ i_rate = INPUT_RATE_DEFAULT / pow( 2, (double)i_exp / 12 );
}
if( i_rate < INPUT_RATE_MIN )
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 580b4fd..01075ad 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -166,6 +166,8 @@ enum input_control_e
INPUT_CONTROL_SET_RATE,
INPUT_CONTROL_SET_RATE_SLOWER,
INPUT_CONTROL_SET_RATE_FASTER,
+ INPUT_CONTROL_SET_RATE_SLOWER_STEP,
+ INPUT_CONTROL_SET_RATE_FASTER_STEP,
INPUT_CONTROL_SET_POSITION,
INPUT_CONTROL_SET_POSITION_OFFSET,
--
1.5.4.3
More information about the vlc-devel
mailing list