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
This commit is contained in:
parent
a70ecdc00c
commit
fbb3a94f17
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user