aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/pcm_resample.c6
-rw-r--r--src/pcm_resample.h4
-rw-r--r--src/pcm_resample_libsamplerate.c22
3 files changed, 14 insertions, 18 deletions
diff --git a/src/pcm_resample.c b/src/pcm_resample.c
index 0a6fa0148..647d9b4f6 100644
--- a/src/pcm_resample.c
+++ b/src/pcm_resample.c
@@ -17,6 +17,7 @@
*/
#include "pcm_resample.h"
+#include "config.h"
#include <string.h>
@@ -24,5 +25,10 @@ void pcm_resample_init(struct pcm_resample_state *state)
{
memset(state, 0, sizeof(*state));
+#ifdef HAVE_LIBSAMPLERATE
+ pcm_buffer_init(&state->in);
+ pcm_buffer_init(&state->out);
+#endif
+
pcm_buffer_init(&state->buffer);
}
diff --git a/src/pcm_resample.h b/src/pcm_resample.h
index 8a428d90b..66a746ae2 100644
--- a/src/pcm_resample.h
+++ b/src/pcm_resample.h
@@ -35,8 +35,8 @@ struct pcm_resample_state {
#ifdef HAVE_LIBSAMPLERATE
SRC_STATE *state;
SRC_DATA data;
- size_t data_in_size;
- size_t data_out_size;
+
+ struct pcm_buffer in, out;
struct {
unsigned src_rate;
diff --git a/src/pcm_resample_libsamplerate.c b/src/pcm_resample_libsamplerate.c
index 7e58db4a4..2f672b5a2 100644
--- a/src/pcm_resample_libsamplerate.c
+++ b/src/pcm_resample_libsamplerate.c
@@ -34,6 +34,8 @@ void pcm_resample_deinit(struct pcm_resample_state *state)
if (state->state != NULL)
state->state = src_delete(state->state);
+ pcm_buffer_deinit(&state->in);
+ pcm_buffer_deinit(&state->out);
pcm_buffer_deinit(&state->buffer);
}
@@ -136,17 +138,11 @@ pcm_resample_16(struct pcm_resample_state *state,
data->input_frames = src_size / sizeof(*src_buffer) / channels;
data_in_size = data->input_frames * sizeof(float) * channels;
- if (data_in_size > state->data_in_size) {
- state->data_in_size = data_in_size;
- data->data_in = g_realloc(data->data_in, data_in_size);
- }
+ data->data_in = pcm_buffer_get(&state->in, data_in_size);
data->output_frames = (src_size * dest_rate + src_rate - 1) / src_rate;
data_out_size = data->output_frames * sizeof(float) * channels;
- if (data_out_size > state->data_out_size) {
- state->data_out_size = data_out_size;
- data->data_out = g_realloc(data->data_out, data_out_size);
- }
+ data->data_out = pcm_buffer_get(&state->out, data_out_size);
src_short_to_float_array(src_buffer, data->data_in,
data->input_frames * channels);
@@ -212,17 +208,11 @@ pcm_resample_24(struct pcm_resample_state *state,
data->input_frames = src_size / sizeof(*src_buffer) / channels;
data_in_size = data->input_frames * sizeof(float) * channels;
- if (data_in_size > state->data_in_size) {
- state->data_in_size = data_in_size;
- data->data_in = g_realloc(data->data_in, data_in_size);
- }
+ data->data_in = pcm_buffer_get(&state->in, data_in_size);
data->output_frames = (src_size * dest_rate + src_rate - 1) / src_rate;
data_out_size = data->output_frames * sizeof(float) * channels;
- if (data_out_size > state->data_out_size) {
- state->data_out_size = data_out_size;
- data->data_out = g_realloc(data->data_out, data_out_size);
- }
+ data->data_out = pcm_buffer_get(&state->out, data_out_size);
src_int_to_float_array(src_buffer, data->data_in,
data->input_frames * channels);