mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
audio-resampler: small cleanups
This commit is contained in:
parent
e209c0d565
commit
cc9d8594fe
1 changed files with 46 additions and 64 deletions
|
@ -249,19 +249,6 @@ get_opt_enum (GstStructure * options, const gchar * name, GType type, gint def)
|
||||||
#include "dbesi0.c"
|
#include "dbesi0.c"
|
||||||
#define bessel dbesi0
|
#define bessel dbesi0
|
||||||
|
|
||||||
static inline gdouble
|
|
||||||
get_nearest_tap (gdouble x, gint n_taps)
|
|
||||||
{
|
|
||||||
gdouble a = fabs (x), res;;
|
|
||||||
|
|
||||||
if (a < 0.5)
|
|
||||||
res = 1.0;
|
|
||||||
else
|
|
||||||
res = 0.0;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline gdouble
|
static inline gdouble
|
||||||
get_linear_tap (gdouble x, gint n_taps)
|
get_linear_tap (gdouble x, gint n_taps)
|
||||||
{
|
{
|
||||||
|
@ -319,45 +306,6 @@ get_kaiser_tap (gdouble x, gint n_taps, gdouble Fc, gdouble beta)
|
||||||
#define PRECISION_S16 15
|
#define PRECISION_S16 15
|
||||||
#define PRECISION_S32 31
|
#define PRECISION_S32 31
|
||||||
|
|
||||||
static gdouble
|
|
||||||
make_taps (GstAudioResampler * resampler,
|
|
||||||
gdouble * tmp_taps, gdouble x, gint n_taps)
|
|
||||||
{
|
|
||||||
gdouble weight = 0.0;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
switch (resampler->method) {
|
|
||||||
case GST_AUDIO_RESAMPLER_METHOD_NEAREST:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GST_AUDIO_RESAMPLER_METHOD_LINEAR:
|
|
||||||
for (i = 0; i < n_taps; i++)
|
|
||||||
weight += tmp_taps[i] = get_linear_tap (x + i, resampler->n_taps);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GST_AUDIO_RESAMPLER_METHOD_CUBIC:
|
|
||||||
for (i = 0; i < n_taps; i++)
|
|
||||||
weight += tmp_taps[i] = get_cubic_tap (x + i, resampler->n_taps,
|
|
||||||
resampler->b, resampler->c);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GST_AUDIO_RESAMPLER_METHOD_BLACKMAN_NUTTALL:
|
|
||||||
for (i = 0; i < n_taps; i++)
|
|
||||||
weight += tmp_taps[i] =
|
|
||||||
get_blackman_nuttall_tap (x + i,
|
|
||||||
resampler->n_taps, resampler->cutoff);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GST_AUDIO_RESAMPLER_METHOD_KAISER:
|
|
||||||
for (i = 0; i < n_taps; i++)
|
|
||||||
weight += tmp_taps[i] =
|
|
||||||
get_kaiser_tap (x + i, resampler->n_taps,
|
|
||||||
resampler->cutoff, resampler->kaiser_beta);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MAKE_CONVERT_TAPS_INT_FUNC(type, precision) \
|
#define MAKE_CONVERT_TAPS_INT_FUNC(type, precision) \
|
||||||
static void \
|
static void \
|
||||||
convert_taps_##type##_c (gdouble *tmp_taps, gpointer taps, \
|
convert_taps_##type##_c (gdouble *tmp_taps, gpointer taps, \
|
||||||
|
@ -428,6 +376,44 @@ static ConvertTapsFunc convert_taps_funcs[] = {
|
||||||
#define convert_taps_gfloat convert_taps_funcs[2]
|
#define convert_taps_gfloat convert_taps_funcs[2]
|
||||||
#define convert_taps_gdouble convert_taps_funcs[3]
|
#define convert_taps_gdouble convert_taps_funcs[3]
|
||||||
|
|
||||||
|
static void
|
||||||
|
make_taps (GstAudioResampler * resampler, gdouble * res, gdouble x, gint n_taps)
|
||||||
|
{
|
||||||
|
gdouble weight = 0.0, *tmp_taps = resampler->tmp_taps;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
switch (resampler->method) {
|
||||||
|
case GST_AUDIO_RESAMPLER_METHOD_NEAREST:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GST_AUDIO_RESAMPLER_METHOD_LINEAR:
|
||||||
|
for (i = 0; i < n_taps; i++)
|
||||||
|
weight += tmp_taps[i] = get_linear_tap (x + i, resampler->n_taps);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GST_AUDIO_RESAMPLER_METHOD_CUBIC:
|
||||||
|
for (i = 0; i < n_taps; i++)
|
||||||
|
weight += tmp_taps[i] = get_cubic_tap (x + i, resampler->n_taps,
|
||||||
|
resampler->b, resampler->c);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GST_AUDIO_RESAMPLER_METHOD_BLACKMAN_NUTTALL:
|
||||||
|
for (i = 0; i < n_taps; i++)
|
||||||
|
weight += tmp_taps[i] =
|
||||||
|
get_blackman_nuttall_tap (x + i,
|
||||||
|
resampler->n_taps, resampler->cutoff);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GST_AUDIO_RESAMPLER_METHOD_KAISER:
|
||||||
|
for (i = 0; i < n_taps; i++)
|
||||||
|
weight += tmp_taps[i] =
|
||||||
|
get_kaiser_tap (x + i, resampler->n_taps,
|
||||||
|
resampler->cutoff, resampler->kaiser_beta);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
resampler->convert_taps (tmp_taps, res, weight, n_taps);
|
||||||
|
}
|
||||||
|
|
||||||
#define MAKE_COEFF_LINEAR_INT_FUNC(type,type2,prec) \
|
#define MAKE_COEFF_LINEAR_INT_FUNC(type,type2,prec) \
|
||||||
static inline void \
|
static inline void \
|
||||||
make_coeff_##type##_linear (gint num, gint denom, type *icoeff) \
|
make_coeff_##type##_linear (gint num, gint denom, type *icoeff) \
|
||||||
|
@ -625,12 +611,11 @@ get_taps_##type##_full (GstAudioResampler * resampler,
|
||||||
switch (resampler->filter_interpolation) { \
|
switch (resampler->filter_interpolation) { \
|
||||||
case GST_AUDIO_RESAMPLER_FILTER_INTERPOLATION_NONE: \
|
case GST_AUDIO_RESAMPLER_FILTER_INTERPOLATION_NONE: \
|
||||||
{ \
|
{ \
|
||||||
gdouble x, weight; \
|
gdouble x; \
|
||||||
gint n_taps = resampler->n_taps; \
|
gint n_taps = resampler->n_taps; \
|
||||||
\
|
\
|
||||||
x = 1.0 - n_taps / 2 - (gdouble) phase / n_phases; \
|
x = 1.0 - n_taps / 2 - (gdouble) phase / n_phases; \
|
||||||
weight = make_taps (resampler, resampler->tmp_taps, x, n_taps); \
|
make_taps (resampler, res, x, n_taps); \
|
||||||
convert_taps_##type (resampler->tmp_taps, res, weight, n_taps); \
|
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
default: \
|
default: \
|
||||||
|
@ -1157,6 +1142,9 @@ setup_functions (GstAudioResampler * resampler)
|
||||||
else {
|
else {
|
||||||
switch (resampler->filter_interpolation) {
|
switch (resampler->filter_interpolation) {
|
||||||
default:
|
default:
|
||||||
|
case GST_AUDIO_RESAMPLER_FILTER_INTERPOLATION_NONE:
|
||||||
|
fidx = 0;
|
||||||
|
break;
|
||||||
case GST_AUDIO_RESAMPLER_FILTER_INTERPOLATION_LINEAR:
|
case GST_AUDIO_RESAMPLER_FILTER_INTERPOLATION_LINEAR:
|
||||||
GST_DEBUG ("using linear interpolation filter function");
|
GST_DEBUG ("using linear interpolation filter function");
|
||||||
fidx = 0;
|
fidx = 0;
|
||||||
|
@ -1307,7 +1295,7 @@ resampler_calculate_taps (GstAudioResampler * resampler)
|
||||||
if (resampler->filter_interpolation !=
|
if (resampler->filter_interpolation !=
|
||||||
GST_AUDIO_RESAMPLER_FILTER_INTERPOLATION_NONE) {
|
GST_AUDIO_RESAMPLER_FILTER_INTERPOLATION_NONE) {
|
||||||
gint i, isize;
|
gint i, isize;
|
||||||
gdouble x, weight, *tmp_taps;
|
gdouble x;
|
||||||
gpointer taps;
|
gpointer taps;
|
||||||
|
|
||||||
switch (resampler->filter_interpolation) {
|
switch (resampler->filter_interpolation) {
|
||||||
|
@ -1324,13 +1312,10 @@ resampler_calculate_taps (GstAudioResampler * resampler)
|
||||||
|
|
||||||
alloc_taps_mem (resampler, bps, n_taps, oversample + isize);
|
alloc_taps_mem (resampler, bps, n_taps, oversample + isize);
|
||||||
|
|
||||||
tmp_taps = resampler->tmp_taps;
|
|
||||||
for (i = 0; i < oversample + isize; i++) {
|
for (i = 0; i < oversample + isize; i++) {
|
||||||
x = -(n_taps / 2) + i / (gdouble) oversample;
|
x = -(n_taps / 2) + i / (gdouble) oversample;
|
||||||
|
|
||||||
taps = (gint8 *) resampler->taps + i * resampler->taps_stride;
|
taps = (gint8 *) resampler->taps + i * resampler->taps_stride;
|
||||||
weight = make_taps (resampler, tmp_taps, x, n_taps);
|
make_taps (resampler, taps, x, n_taps);
|
||||||
resampler->convert_taps (tmp_taps, taps, weight, n_taps);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1539,10 +1524,7 @@ gst_audio_resampler_new (GstAudioResamplerMethod method,
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_audio_resampler_update (resampler, in_rate, out_rate, options);
|
gst_audio_resampler_update (resampler, in_rate, out_rate, options);
|
||||||
|
gst_audio_resampler_reset (resampler);
|
||||||
/* half of the filter is filled with 0 */
|
|
||||||
resampler->samp_index = 0;
|
|
||||||
resampler->samples_avail = resampler->n_taps / 2 - 1;
|
|
||||||
|
|
||||||
if (def_options)
|
if (def_options)
|
||||||
gst_structure_free (def_options);
|
gst_structure_free (def_options);
|
||||||
|
|
Loading…
Reference in a new issue