aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-10-08 14:06:24 +0200
committerMax Kellermann <max@duempel.org>2011-10-08 14:51:26 +0200
commit3057d19cdf904210d443c3c706ab98709613e9a5 (patch)
treed3ebae0b77cf23d608ad17b92cdff753d3201a84 /src
parent8dd83a2cf3c104f30155368b313d06b3d9f96e65 (diff)
downloadmpd-3057d19cdf904210d443c3c706ab98709613e9a5.tar.gz
mpd-3057d19cdf904210d443c3c706ab98709613e9a5.tar.xz
mpd-3057d19cdf904210d443c3c706ab98709613e9a5.zip
pcm_resample_lsr: move common code to lsr_process()
Diffstat (limited to 'src')
-rw-r--r--src/pcm_resample_libsamplerate.c49
1 files changed, 17 insertions, 32 deletions
diff --git a/src/pcm_resample_libsamplerate.c b/src/pcm_resample_libsamplerate.c
index a71659d51..ccee76d04 100644
--- a/src/pcm_resample_libsamplerate.c
+++ b/src/pcm_resample_libsamplerate.c
@@ -142,6 +142,21 @@ pcm_resample_set(struct pcm_resample_state *state,
return true;
}
+static bool
+lsr_process(struct pcm_resample_state *state, GError **error_r)
+{
+ if (state->error == 0)
+ state->error = src_process(state->state, &state->data);
+ if (state->error) {
+ g_set_error(error_r, libsamplerate_quark(), state->error,
+ "libsamplerate has failed: %s",
+ src_strerror(state->error));
+ return false;
+ }
+
+ return true;
+}
+
const int16_t *
pcm_resample_lsr_16(struct pcm_resample_state *state,
uint8_t channels,
@@ -154,7 +169,6 @@ pcm_resample_lsr_16(struct pcm_resample_state *state,
SRC_DATA *data = &state->data;
size_t data_in_size;
size_t data_out_size;
- int error;
int16_t *dest_buffer;
assert((src_size % (sizeof(*src_buffer) * channels)) == 0);
@@ -164,14 +178,6 @@ pcm_resample_lsr_16(struct pcm_resample_state *state,
if (!success)
return NULL;
- /* there was an error previously, and nothing has changed */
- if (state->error) {
- g_set_error(error_r, libsamplerate_quark(), state->error,
- "libsamplerate has failed: %s",
- src_strerror(state->error));
- return NULL;
- }
-
data->input_frames = src_size / sizeof(*src_buffer) / channels;
data_in_size = data->input_frames * sizeof(float) * channels;
data->data_in = pcm_buffer_get(&state->in, data_in_size);
@@ -183,14 +189,8 @@ pcm_resample_lsr_16(struct pcm_resample_state *state,
src_short_to_float_array(src_buffer, data->data_in,
data->input_frames * channels);
- error = src_process(state->state, data);
- if (error) {
- g_set_error(error_r, libsamplerate_quark(), error,
- "libsamplerate has failed: %s",
- src_strerror(error));
- state->error = error;
+ if (!lsr_process(state, error_r))
return NULL;
- }
*dest_size_r = data->output_frames_gen *
sizeof(*dest_buffer) * channels;
@@ -233,7 +233,6 @@ pcm_resample_lsr_32(struct pcm_resample_state *state,
SRC_DATA *data = &state->data;
size_t data_in_size;
size_t data_out_size;
- int error;
int32_t *dest_buffer;
assert((src_size % (sizeof(*src_buffer) * channels)) == 0);
@@ -243,14 +242,6 @@ pcm_resample_lsr_32(struct pcm_resample_state *state,
if (!success)
return NULL;
- /* there was an error previously, and nothing has changed */
- if (state->error) {
- g_set_error(error_r, libsamplerate_quark(), state->error,
- "libsamplerate has failed: %s",
- src_strerror(state->error));
- return NULL;
- }
-
data->input_frames = src_size / sizeof(*src_buffer) / channels;
data_in_size = data->input_frames * sizeof(float) * channels;
data->data_in = pcm_buffer_get(&state->in, data_in_size);
@@ -262,14 +253,8 @@ pcm_resample_lsr_32(struct pcm_resample_state *state,
src_int_to_float_array(src_buffer, data->data_in,
data->input_frames * channels);
- error = src_process(state->state, data);
- if (error) {
- g_set_error(error_r, libsamplerate_quark(), error,
- "libsamplerate has failed: %s",
- src_strerror(error));
- state->error = error;
+ if (!lsr_process(state, error_r))
return NULL;
- }
*dest_size_r = data->output_frames_gen *
sizeof(*dest_buffer) * channels;