159 |
int samplewidth = format->wBitsPerSample / 8; |
int samplewidth = format->wBitsPerSample / 8; |
160 |
int i; |
int i; |
161 |
|
|
162 |
|
if ((resample_to_bitspersample == format->wBitsPerSample) && |
163 |
|
(resample_to_channels == format->nChannels) && |
164 |
|
(resample_to_srate == format->nSamplesPerSec)) |
165 |
|
return 0; |
166 |
|
|
167 |
if ((resample_to_bitspersample != format->wBitsPerSample) || |
if ((resample_to_bitspersample != format->wBitsPerSample) || |
168 |
(resample_to_channels != format->nChannels) || |
(resample_to_channels != format->nChannels) || (format->nSamplesPerSec != 22050)) |
|
((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050))) |
|
169 |
{ |
{ |
170 |
if (!warned) |
if (!warned) |
171 |
{ |
{ |
176 |
return 0; |
return 0; |
177 |
} |
} |
178 |
|
|
179 |
if (format->nSamplesPerSec == 22050) |
outsize = size * 2; |
180 |
{ |
*out = xmalloc(outsize); |
|
outsize = size * 2; |
|
|
*out = xmalloc(outsize); |
|
|
|
|
|
/* Resample to 44100 */ |
|
|
for (i = 0; i < (size / samplewidth); i++) |
|
|
{ |
|
|
/* 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); |
|
181 |
|
|
182 |
} |
/* Resample from 22050 to 44100 */ |
183 |
} |
for (i = 0; i < (size / samplewidth); i++) |
|
else |
|
184 |
{ |
{ |
185 |
outsize = 0; |
/* On a stereo-channel we must make sure that left and right |
186 |
|
does not get mixed up, so we need to expand the sample- |
187 |
|
data with channels in mind: 1234 -> 12123434 |
188 |
|
If we have a mono-channel, we can expand the data by simply |
189 |
|
doubling the sample-data: 1234 -> 11223344 */ |
190 |
|
if (resample_to_channels == 2) |
191 |
|
offset = ((i * 2) - (i & 1)) * samplewidth; |
192 |
|
else |
193 |
|
offset = (i * 2) * samplewidth; |
194 |
|
|
195 |
|
memcpy(*out + offset, in + (i * samplewidth), samplewidth); |
196 |
|
memcpy(*out + (resample_to_channels * samplewidth + offset), |
197 |
|
in + (i * samplewidth), samplewidth); |
198 |
|
|
199 |
} |
} |
200 |
|
|
201 |
return outsize; |
return outsize; |
219 |
out.data = NULL; |
out.data = NULL; |
220 |
|
|
221 |
if (current_driver->wave_out_format_supported == rdpsnd_dsp_resample_supported) |
if (current_driver->wave_out_format_supported == rdpsnd_dsp_resample_supported) |
|
{ |
|
222 |
out.size = rdpsnd_dsp_resample(&out.data, s->data, s->size, format); |
out.size = rdpsnd_dsp_resample(&out.data, s->data, s->size, format); |
|
} |
|
223 |
|
|
224 |
if (out.data == NULL) |
if (out.data == NULL) |
225 |
{ |
{ |