[pulseaudio-discuss] [PATCH 2/4] Enabled libsoxr resampler backend.
Andrey Semashev
andrey.semashev at gmail.com
Tue Nov 11 13:39:26 PST 2014
Also fixed a bug in sample_format_more_precise for 32-bit integer sample formats.
---
src/pulsecore/resampler.c | 32 ++++++++++++++++++++++++++++++--
src/pulsecore/resampler.h | 5 +++++
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 8b30c24..66101f6 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -111,6 +111,17 @@ 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_LQ] = pa_resampler_soxr_init,
+ [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_LQ] = NULL,
+ [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) {
@@ -234,7 +245,7 @@ static bool sample_format_more_precise(pa_sample_format_t a, pa_sample_format_t
case PA_SAMPLE_S32LE:
case PA_SAMPLE_S32BE:
if (b == PA_SAMPLE_FLOAT32LE || b == PA_SAMPLE_FLOAT32BE ||
- b == PA_SAMPLE_S32LE || b == PA_SAMPLE_FLOAT32BE)
+ b == PA_SAMPLE_S32LE || b == PA_SAMPLE_S32BE)
return false;
else
return true;
@@ -287,6 +298,19 @@ static pa_sample_format_t choose_work_format(
work_format = PA_SAMPLE_S16NE;
break;
+ case PA_RESAMPLER_SOXR_LQ:
+ case PA_RESAMPLER_SOXR_MQ:
+ case PA_RESAMPLER_SOXR_HQ:
+ case PA_RESAMPLER_SOXR_VHQ:
+ /* Note: libsoxr can potentially work with PA_SAMPLE_S32NE as well */
+ if (!map_required &&
+ (a == PA_SAMPLE_S16LE || a == PA_SAMPLE_S16BE || sample_format_more_precise(PA_SAMPLE_S16NE, a)) &&
+ (b == PA_SAMPLE_S16LE || b == PA_SAMPLE_S16BE || sample_format_more_precise(PA_SAMPLE_S16NE, b)))
+ work_format = PA_SAMPLE_S16NE;
+ else
+ work_format = PA_SAMPLE_FLOAT32NE;
+ break;
+
default:
work_format = PA_SAMPLE_FLOAT32NE;
}
@@ -601,7 +625,11 @@ static const char * const resample_methods[] = {
"ffmpeg",
"auto",
"copy",
- "peaks"
+ "peaks",
+ "soxr-lq",
+ "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..ebb7050 100644
--- a/src/pulsecore/resampler.h
+++ b/src/pulsecore/resampler.h
@@ -59,6 +59,10 @@ typedef enum pa_resample_method {
PA_RESAMPLER_AUTO, /* automatic select based on sample format */
PA_RESAMPLER_COPY,
PA_RESAMPLER_PEAKS,
+ PA_RESAMPLER_SOXR_LQ,
+ PA_RESAMPLER_SOXR_MQ,
+ PA_RESAMPLER_SOXR_HQ,
+ PA_RESAMPLER_SOXR_VHQ,
PA_RESAMPLER_MAX
} pa_resample_method_t;
@@ -163,6 +167,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
More information about the pulseaudio-discuss
mailing list