aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_utils.c
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2007-05-23 10:31:07 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2007-05-23 10:31:07 +0000
commitfbb3a94f17836aa33de78fd73db0f5d54464379d (patch)
tree657629c023edd6eea29bb498d7a94ab003c32219 /src/pcm_utils.c
parenta70ecdc00c588d824ae87d3084a5155140b70c99 (diff)
downloadmpd-fbb3a94f17836aa33de78fd73db0f5d54464379d.tar.gz
mpd-fbb3a94f17836aa33de78fd73db0f5d54464379d.tar.xz
mpd-fbb3a94f17836aa33de78fd73db0f5d54464379d.zip
Switching to the lsr simple API. The problem with the full API is that the
number of channels is specified when the converter state is created. Previously this was only done once, thus breaking horribly when the input audio suddenly had a different channel count. A new state could be created every time the number of channels changes, but this could happen many times a second if resampling to two different formats at once. The simple API doesn't have this problem, as channel count is an argument to the conversion function itself. git-svn-id: https://svn.musicpd.org/mpd/trunk@6229 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/pcm_utils.c')
-rw-r--r--src/pcm_utils.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index ca5d6ca5c..4cf5f2a7d 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -191,31 +191,18 @@ static int pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
mpd_uint32 outSampleRate, char *outBuffer,
size_t outSize)
{
- static SRC_STATE *state;
+ static int convalgo = -1;
static SRC_DATA data;
static size_t dataInSize;
static size_t dataOutSize;
size_t curDataInSize;
size_t curDataOutSize;
- double ratio;
int error;
- if (!state) {
- state = src_new(pcm_getSampleRateConverter(), channels, &error);
- if (!state) {
- ERROR("Cannot create new samplerate state: %s\n",
- src_strerror(error));
- return 0;
- }
- DEBUG("Samplerate converter initialized\n");
- }
+ if (convalgo < 0)
+ convalgo = pcm_getSampleRateConverter();
- ratio = (double)outSampleRate / (double)inSampleRate;
- if (ratio != data.src_ratio) {
- DEBUG("Setting samplerate conversion ratio to %.2lf\n", ratio);
- src_set_ratio(state, ratio);
- data.src_ratio = ratio;
- }
+ data.src_ratio = (double)outSampleRate / (double)inSampleRate;
data.input_frames = inSize / 2 / channels;
curDataInSize = data.input_frames * sizeof(float) * channels;
@@ -234,9 +221,10 @@ static int pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
src_short_to_float_array((short *)inBuffer, data.data_in,
data.input_frames * channels);
- error = src_process(state, &data);
+ error = src_simple(&data, convalgo, channels);
if (error) {
- ERROR("Cannot process samples: %s\n", src_strerror(error));
+ ERROR("error processing samples with libsamplerate: %s\n",
+ src_strerror(error));
return 0;
}