only resample when there is need

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@1276 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Michael Gernoth 2006-10-01 12:26:01 +00:00
parent b7b4327927
commit 8f8ea57234

View File

@ -159,9 +159,13 @@ rdpsnd_dsp_resample(unsigned char **out, unsigned char *in, unsigned int size,
int samplewidth = format->wBitsPerSample / 8; int samplewidth = format->wBitsPerSample / 8;
int i; int i;
if ((resample_to_bitspersample == format->wBitsPerSample) &&
(resample_to_channels == format->nChannels) &&
(resample_to_srate == format->nSamplesPerSec))
return 0;
if ((resample_to_bitspersample != format->wBitsPerSample) || if ((resample_to_bitspersample != format->wBitsPerSample) ||
(resample_to_channels != format->nChannels) || (resample_to_channels != format->nChannels) || (format->nSamplesPerSec != 22050))
((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050)))
{ {
if (!warned) if (!warned)
{ {
@ -172,33 +176,26 @@ rdpsnd_dsp_resample(unsigned char **out, unsigned char *in, unsigned int size,
return 0; return 0;
} }
if (format->nSamplesPerSec == 22050) outsize = size * 2;
*out = xmalloc(outsize);
/* Resample from 22050 to 44100 */
for (i = 0; i < (size / samplewidth); i++)
{ {
outsize = size * 2; /* On a stereo-channel we must make sure that left and right
*out = xmalloc(outsize); does not get mixed up, so we need to expand the sample-
data with channels in mind: 1234 -> 12123434
If we have a mono-channel, we can expand the data by simply
doubling the sample-data: 1234 -> 11223344 */
if (resample_to_channels == 2)
offset = ((i * 2) - (i & 1)) * samplewidth;
else
offset = (i * 2) * samplewidth;
/* Resample to 44100 */ memcpy(*out + offset, in + (i * samplewidth), samplewidth);
for (i = 0; i < (size / samplewidth); i++) memcpy(*out + (resample_to_channels * samplewidth + offset),
{ in + (i * samplewidth), samplewidth);
/* On a stereo-channel we must make sure that left and right
does not get mixed up, so we need to expand the sample-
data with channels in mind: 1234 -> 12123434
If we have a mono-channel, we can expand the data by simply
doubling the sample-data: 1234 -> 11223344 */
if (resample_to_channels == 2)
offset = ((i * 2) - (i & 1)) * samplewidth;
else
offset = (i * 2) * samplewidth;
memcpy(*out + offset, in + (i * samplewidth), samplewidth);
memcpy(*out + (resample_to_channels * samplewidth + offset),
in + (i * samplewidth), samplewidth);
}
}
else
{
outsize = 0;
} }
return outsize; return outsize;
@ -222,9 +219,7 @@ rdpsnd_dsp_process(STREAM s, struct audio_driver * current_driver, WAVEFORMATEX
out.data = NULL; out.data = NULL;
if (current_driver->wave_out_format_supported == rdpsnd_dsp_resample_supported) if (current_driver->wave_out_format_supported == rdpsnd_dsp_resample_supported)
{
out.size = rdpsnd_dsp_resample(&out.data, s->data, s->size, format); out.size = rdpsnd_dsp_resample(&out.data, s->data, s->size, format);
}
if (out.data == NULL) if (out.data == NULL)
{ {