aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_resample.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pcm_resample.c')
-rw-r--r--src/pcm_resample.c81
1 files changed, 68 insertions, 13 deletions
diff --git a/src/pcm_resample.c b/src/pcm_resample.c
index 4a7578e09..4bc057a7e 100644
--- a/src/pcm_resample.c
+++ b/src/pcm_resample.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -27,26 +27,43 @@
#include <string.h>
#ifdef HAVE_LIBSAMPLERATE
+static bool lsr_enabled;
+#endif
+
+#ifdef HAVE_LIBSAMPLERATE
static bool
pcm_resample_lsr_enabled(void)
{
- return strcmp(config_get_string(CONF_SAMPLERATE_CONVERTER, ""),
- "internal") != 0;
+ return lsr_enabled;
}
#endif
-void pcm_resample_init(struct pcm_resample_state *state)
+bool
+pcm_resample_global_init(GError **error_r)
{
- memset(state, 0, sizeof(*state));
-
#ifdef HAVE_LIBSAMPLERATE
- if (pcm_resample_lsr_enabled()) {
- pcm_buffer_init(&state->in);
- pcm_buffer_init(&state->out);
- }
+ const char *converter =
+ config_get_string(CONF_SAMPLERATE_CONVERTER, "");
+
+ lsr_enabled = strcmp(converter, "internal") != 0;
+ if (lsr_enabled)
+ return pcm_resample_lsr_global_init(converter, error_r);
+ else
+ return true;
+#else
+ (void)error_r;
+ return true;
#endif
+}
- pcm_buffer_init(&state->buffer);
+void pcm_resample_init(struct pcm_resample_state *state)
+{
+#ifdef HAVE_LIBSAMPLERATE
+ if (pcm_resample_lsr_enabled())
+ pcm_resample_lsr_init(state);
+ else
+#endif
+ pcm_resample_fallback_init(state);
}
void pcm_resample_deinit(struct pcm_resample_state *state)
@@ -59,9 +76,47 @@ void pcm_resample_deinit(struct pcm_resample_state *state)
pcm_resample_fallback_deinit(state);
}
+void
+pcm_resample_reset(struct pcm_resample_state *state)
+{
+#ifdef HAVE_LIBSAMPLERATE
+ pcm_resample_lsr_reset(state);
+#else
+ (void)state;
+#endif
+}
+
+const float *
+pcm_resample_float(struct pcm_resample_state *state,
+ unsigned channels,
+ unsigned src_rate,
+ const float *src_buffer, size_t src_size,
+ unsigned dest_rate, size_t *dest_size_r,
+ GError **error_r)
+{
+#ifdef HAVE_LIBSAMPLERATE
+ if (pcm_resample_lsr_enabled())
+ return pcm_resample_lsr_float(state, channels,
+ src_rate, src_buffer, src_size,
+ dest_rate, dest_size_r,
+ error_r);
+#else
+ (void)error_r;
+#endif
+
+ /* sizeof(float)==sizeof(int32_t); the fallback resampler does
+ not do any math on the sample values, so this hack is
+ possible: */
+ return (const float *)
+ pcm_resample_fallback_32(state, channels,
+ src_rate, (const int32_t *)src_buffer,
+ src_size,
+ dest_rate, dest_size_r);
+}
+
const int16_t *
pcm_resample_16(struct pcm_resample_state *state,
- uint8_t channels,
+ unsigned channels,
unsigned src_rate, const int16_t *src_buffer, size_t src_size,
unsigned dest_rate, size_t *dest_size_r,
GError **error_r)
@@ -83,7 +138,7 @@ pcm_resample_16(struct pcm_resample_state *state,
const int32_t *
pcm_resample_32(struct pcm_resample_state *state,
- uint8_t channels,
+ unsigned channels,
unsigned src_rate, const int32_t *src_buffer, size_t src_size,
unsigned dest_rate, size_t *dest_size_r,
GError **error_r)