[FFmpeg-devel] [PATCH] swresample: allow double precision beta value for the Kaiser window

Ganesh Ajjanagadde gajjanagadde at gmail.com
Sat Nov 7 16:18:33 CET 2015


Kaiser windows inherently don't require beta to be an integer. This was
an arbitrary restriction. Moreover, soxr does not require it, and in
fact often estimates beta to a non-integral value.

Thus, this patch allows greater flexibility for swresample clients.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 doc/resampler.texi                  | 2 +-
 libswresample/options.c             | 2 +-
 libswresample/resample.c            | 4 ++--
 libswresample/resample.h            | 2 +-
 libswresample/soxr_resample.c       | 2 +-
 libswresample/swresample_internal.h | 4 ++--
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/doc/resampler.texi b/doc/resampler.texi
index 155230f..cb7d536 100644
--- a/doc/resampler.texi
+++ b/doc/resampler.texi
@@ -220,7 +220,7 @@ select Kaiser windowed sinc
 @end table
 
 @item kaiser_beta
-For swr only, set Kaiser window beta value. Must be an integer in the
+For swr only, set Kaiser window beta value. Must be a double float value in the
 interval [2,16], default value is 9.
 
 @item output_sample_bits
diff --git a/libswresample/options.c b/libswresample/options.c
index 2bf8ab1..654102a 100644
--- a/libswresample/options.c
+++ b/libswresample/options.c
@@ -120,7 +120,7 @@ static const AVOption options[]={
     { "blackman_nuttall", "select Blackman Nuttall windowed sinc", 0             , AV_OPT_TYPE_CONST, { .i64 = SWR_FILTER_TYPE_BLACKMAN_NUTTALL }, INT_MIN, INT_MAX, PARAM, "filter_type" },
     { "kaiser"          , "select Kaiser windowed sinc" , 0                      , AV_OPT_TYPE_CONST, { .i64 = SWR_FILTER_TYPE_KAISER           }, INT_MIN, INT_MAX, PARAM, "filter_type" },
 
-{ "kaiser_beta"         , "set swr Kaiser window beta"  , OFFSET(kaiser_beta)    , AV_OPT_TYPE_INT  , {.i64=9                     }, 2      , 16        , PARAM },
+{ "kaiser_beta"         , "set swr Kaiser window beta"  , OFFSET(kaiser_beta)    , AV_OPT_TYPE_DOUBLE  , {.dbl=9                     }, 2      , 16        , PARAM },
 
 { "output_sample_bits"  , "set swr number of output sample bits", OFFSET(dither.output_sample_bits), AV_OPT_TYPE_INT  , {.i64=0   }, 0      , 64        , PARAM },
 {0}
diff --git a/libswresample/resample.c b/libswresample/resample.c
index 1a0c369..9f5e10e 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -142,7 +142,7 @@ static double bessel(double x) {
  * @return 0 on success, negative on error
  */
 static int build_filter(ResampleContext *c, void *filter, double factor, int tap_count, int alloc, int phase_count, int scale,
-                        int filter_type, int kaiser_beta){
+                        int filter_type, double kaiser_beta){
     int ph, i;
     double x, y, w, t;
     double *tab = av_malloc_array(tap_count+1,  sizeof(*tab));
@@ -283,7 +283,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap
 }
 
 static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
-                                    double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta,
+                                    double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta,
                                     double precision, int cheby)
 {
     double cutoff = cutoff0? cutoff0 : 0.97;
diff --git a/libswresample/resample.h b/libswresample/resample.h
index 99a89b7..a126b11 100644
--- a/libswresample/resample.h
+++ b/libswresample/resample.h
@@ -44,7 +44,7 @@ typedef struct ResampleContext {
     int phase_mask;
     int linear;
     enum SwrFilterType filter_type;
-    int kaiser_beta;
+    double kaiser_beta;
     double factor;
     enum AVSampleFormat format;
     int felem_size;
diff --git a/libswresample/soxr_resample.c b/libswresample/soxr_resample.c
index 535e9ce..807f508 100644
--- a/libswresample/soxr_resample.c
+++ b/libswresample/soxr_resample.c
@@ -30,7 +30,7 @@
 #include <soxr.h>
 
 static struct ResampleContext *create(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
-        double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta, double precision, int cheby){
+        double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby){
     soxr_error_t error;
 
     soxr_datatype_t type =
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index bf0cec7..5c46dda 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -69,7 +69,7 @@ struct DitherContext {
 };
 
 typedef struct ResampleContext * (* resample_init_func)(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear,
-                                    double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta, double precision, int cheby);
+                                    double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby);
 typedef void    (* resample_free_func)(struct ResampleContext **c);
 typedef int     (* multiple_resample_func)(struct ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed);
 typedef int     (* resample_flush_func)(struct SwrContext *c);
@@ -128,7 +128,7 @@ struct SwrContext {
     int linear_interp;                              /**< if 1 then the resampling FIR filter will be linearly interpolated */
     double cutoff;                                  /**< resampling cutoff frequency (swr: 6dB point; soxr: 0dB point). 1.0 corresponds to half the output sample rate */
     int filter_type;                                /**< swr resampling filter type */
-    int kaiser_beta;                                /**< swr beta value for Kaiser window (only applicable if filter_type == AV_FILTER_TYPE_KAISER) */
+    double kaiser_beta;                                /**< swr beta value for Kaiser window (only applicable if filter_type == AV_FILTER_TYPE_KAISER) */
     double precision;                               /**< soxr resampling precision (in bits) */
     int cheby;                                      /**< soxr: if 1 then passband rolloff will be none (Chebyshev) & irrational ratio approximation precision will be higher */
 
-- 
2.6.2



More information about the ffmpeg-devel mailing list