[pulseaudio-discuss] [PATCH 2/4] Enabled libsoxr resampler backend.

Peter Meerwald pmeerw at pmeerw.net
Mon Jan 12 08:36:19 PST 2015


> Added ID and names for the resampler presets and also updated the working sample rate deduction to take the new resampler into account.

what to do with PA_RESAMPLER_VARIABLE_RATE?

resampler_soxr_update_rates() just recreates the context, I guess this 
will lead to crackling sound (not tested)

probably SOXR should be added to the clause in fix_method() which checks 
for PA_RESAMPLER_VARIABLE_RATE?

p.

> ---
>  src/pulsecore/resampler.c | 30 ++++++++++++++++++++++++++----
>  src/pulsecore/resampler.h |  4 ++++
>  2 files changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
> index 183d05f..8a80b7d 100644
> --- a/src/pulsecore/resampler.c
> +++ b/src/pulsecore/resampler.c
> @@ -111,6 +111,15 @@ static int (* const init_table[])(pa_resampler *r) = {
>      [PA_RESAMPLER_AUTO]                    = NULL,
>      [PA_RESAMPLER_COPY]                    = copy_init,
>      [PA_RESAMPLER_PEAKS]                   = pa_resampler_peaks_init,
> +#ifdef HAVE_SOXR
> +    [PA_RESAMPLER_SOXR_MQ]                 = pa_resampler_soxr_init,
> +    [PA_RESAMPLER_SOXR_HQ]                 = pa_resampler_soxr_init,
> +    [PA_RESAMPLER_SOXR_VHQ]                = pa_resampler_soxr_init,
> +#else
> +    [PA_RESAMPLER_SOXR_MQ]                 = NULL,
> +    [PA_RESAMPLER_SOXR_HQ]                 = NULL,
> +    [PA_RESAMPLER_SOXR_VHQ]                = NULL,
> +#endif
>  };
>  
>  static pa_resample_method_t choose_auto_resampler(pa_resample_flags_t flags) {
> @@ -278,10 +287,20 @@ static pa_sample_format_t choose_work_format(
>              }
>                                                  /* Else fall trough */
>          case PA_RESAMPLER_PEAKS:
> -            if (a == PA_SAMPLE_S16NE || b == PA_SAMPLE_S16NE)
> +            /* PEAKS, COPY and TRIVIAL do not benefit from increased
> +             * working precision, so for better performance use s16ne
> +             * if either input or output fits in it. */
> +            if (a == PA_SAMPLE_S16NE || b == PA_SAMPLE_S16NE) {
>                  work_format = PA_SAMPLE_S16NE;
> -            else if (sample_format_more_precise(a, PA_SAMPLE_S16NE) ||
> -                     sample_format_more_precise(b, PA_SAMPLE_S16NE))
> +                break;
> +            }
> +                                                /* Else fall trough */
> +        case PA_RESAMPLER_SOXR_MQ:
> +        case PA_RESAMPLER_SOXR_HQ:
> +        case PA_RESAMPLER_SOXR_VHQ:
> +            /* Do processing with max precision of input and output. */
> +            if (sample_format_more_precise(a, PA_SAMPLE_S16NE) ||
> +                sample_format_more_precise(b, PA_SAMPLE_S16NE))
>                  work_format = PA_SAMPLE_FLOAT32NE;
>              else
>                  work_format = PA_SAMPLE_S16NE;
> @@ -601,7 +620,10 @@ static const char * const resample_methods[] = {
>      "ffmpeg",
>      "auto",
>      "copy",
> -    "peaks"
> +    "peaks",
> +    "soxr-mq",
> +    "soxr-hq",
> +    "soxr-vhq"
>  };
>  
>  const char *pa_resample_method_to_string(pa_resample_method_t m) {
> diff --git a/src/pulsecore/resampler.h b/src/pulsecore/resampler.h
> index 5a84cf0..a0306e7 100644
> --- a/src/pulsecore/resampler.h
> +++ b/src/pulsecore/resampler.h
> @@ -59,6 +59,9 @@ typedef enum pa_resample_method {
>      PA_RESAMPLER_AUTO, /* automatic select based on sample format */
>      PA_RESAMPLER_COPY,
>      PA_RESAMPLER_PEAKS,
> +    PA_RESAMPLER_SOXR_MQ,
> +    PA_RESAMPLER_SOXR_HQ,
> +    PA_RESAMPLER_SOXR_VHQ,
>      PA_RESAMPLER_MAX
>  } pa_resample_method_t;
>  
> @@ -163,6 +166,7 @@ int pa_resampler_libsamplerate_init(pa_resampler *r);
>  int pa_resampler_peaks_init(pa_resampler *r);
>  int pa_resampler_speex_init(pa_resampler *r);
>  int pa_resampler_trivial_init(pa_resampler*r);
> +int pa_resampler_soxr_init(pa_resampler *r);
>  
>  /* Resampler-specific quirks */
>  bool pa_speex_is_fixed_point(void);
> -- 
> 2.1.0
> 
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
> 

-- 

Peter Meerwald
+43-664-2444418 (mobile)


More information about the pulseaudio-discuss mailing list