132 |
int err; |
int err; |
133 |
#endif |
#endif |
134 |
|
|
135 |
#ifdef HAVE_LIBSAMPLERATE |
#ifndef HAVE_LIBSAMPLERATE |
|
if (device_bitspersample != 16) |
|
|
return False; |
|
|
#else |
|
136 |
if (device_srate != 44100 && device_srate != 22050) |
if (device_srate != 44100 && device_srate != 22050) |
137 |
return False; |
return False; |
138 |
|
#endif |
139 |
|
|
140 |
if (device_bitspersample != 16 && device_bitspersample != 8) |
if (device_bitspersample != 16 && device_bitspersample != 8) |
141 |
return False; |
return False; |
|
#endif |
|
142 |
|
|
143 |
if (device_channels != 1 && device_channels != 2) |
if (device_channels != 1 && device_channels != 2) |
144 |
return False; |
return False; |
168 |
return False; |
return False; |
169 |
if ((format->nChannels != 1) && (format->nChannels != 2)) |
if ((format->nChannels != 1) && (format->nChannels != 2)) |
170 |
return False; |
return False; |
|
#ifdef HAVE_LIBSAMPLERATE |
|
|
if (format->wBitsPerSample != 16) |
|
|
return False; |
|
|
#else |
|
171 |
if ((format->wBitsPerSample != 8) && (format->wBitsPerSample != 16)) |
if ((format->wBitsPerSample != 8) && (format->wBitsPerSample != 16)) |
172 |
return False; |
return False; |
173 |
|
#ifndef HAVE_LIBSAMPLERATE |
174 |
if ((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050)) |
if ((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050)) |
175 |
return False; |
return False; |
176 |
#endif |
#endif |
186 |
SRC_DATA resample_data; |
SRC_DATA resample_data; |
187 |
float *infloat, *outfloat; |
float *infloat, *outfloat; |
188 |
int innum, outnum; |
int innum, outnum; |
189 |
|
int err; |
190 |
#else |
#else |
191 |
int offset; |
int offset; |
|
int i; |
|
192 |
#endif |
#endif |
193 |
static BOOL warned = False; |
static BOOL warned = False; |
194 |
|
unsigned char *tmpdata = NULL; |
195 |
int samplewidth = format->wBitsPerSample / 8; |
int samplewidth = format->wBitsPerSample / 8; |
196 |
int outsize = 0; |
int outsize = 0; |
197 |
|
int i; |
198 |
|
|
199 |
if ((resample_to_bitspersample == format->wBitsPerSample) && |
if ((resample_to_bitspersample == format->wBitsPerSample) && |
200 |
(resample_to_channels == format->nChannels) && |
(resample_to_channels == format->nChannels) && |
203 |
|
|
204 |
#ifdef B_ENDIAN |
#ifdef B_ENDIAN |
205 |
if (!stream_be) |
if (!stream_be) |
206 |
rdpsnd_dsp_swapbytes(in, size, format) |
rdpsnd_dsp_swapbytes(in, size, format); |
207 |
#endif |
#endif |
208 |
if ((resample_to_channels != format->nChannels) || |
|
209 |
(resample_to_bitspersample != format->wBitsPerSample)) |
/* Expand 8bit input-samples to 16bit */ |
210 |
|
#ifndef HAVE_LIBSAMPLERATE /* libsamplerate needs 16bit samples */ |
211 |
|
if (format->wBitsPerSample != resample_to_bitspersample) |
212 |
|
#endif |
213 |
|
{ |
214 |
|
/* source: 8 bit, dest: 16bit */ |
215 |
|
if (format->wBitsPerSample == 8) |
216 |
{ |
{ |
217 |
warning("unsupported resample-settings (%u -> %u/%u -> %u/%u -> %u), not resampling!\n", format->nSamplesPerSec, resample_to_srate, format->wBitsPerSample, resample_to_bitspersample, format->nChannels, resample_to_channels); |
tmpdata = xmalloc(size * 2); |
218 |
warned = True; |
for (i = 0; i < size; i++) |
219 |
|
{ |
220 |
|
tmpdata[i * 2] = in[i]; |
221 |
|
tmpdata[(i * 2) + 1] = 0x00; |
222 |
|
} |
223 |
|
in = tmpdata; |
224 |
|
samplewidth = 16 / 2; |
225 |
|
size *= 2; |
226 |
} |
} |
227 |
|
} |
228 |
|
|
229 |
|
if (resample_to_channels != format->nChannels) |
230 |
|
{ |
231 |
|
warning("unsupported resample-settings (%u -> %u/%u -> %u/%u -> %u), not resampling!\n", format->nSamplesPerSec, resample_to_srate, format->wBitsPerSample, resample_to_bitspersample, format->nChannels, resample_to_channels); |
232 |
|
warned = True; |
233 |
|
} |
234 |
|
|
235 |
|
/* Do the resampling */ |
236 |
#ifdef HAVE_LIBSAMPLERATE |
#ifdef HAVE_LIBSAMPLERATE |
237 |
if (src_converter == NULL) |
if (src_converter == NULL) |
238 |
{ |
{ |
241 |
} |
} |
242 |
|
|
243 |
innum = size / samplewidth; |
innum = size / samplewidth; |
244 |
outnum = innum * (resample_to_srate / format->nSamplesPerSec); |
outnum = ((float)innum * ((float)resample_to_srate / (float)format->nSamplesPerSec)) + 1; |
245 |
|
|
246 |
infloat = xmalloc(sizeof(float) * innum); |
infloat = xmalloc(sizeof(float) * innum); |
247 |
outfloat = xmalloc(sizeof(float) * outnum); |
outfloat = xmalloc(sizeof(float) * outnum); |
256 |
resample_data.src_ratio = (double) resample_to_srate / (double) format->nSamplesPerSec; |
resample_data.src_ratio = (double) resample_to_srate / (double) format->nSamplesPerSec; |
257 |
resample_data.end_of_input = 0; |
resample_data.end_of_input = 0; |
258 |
|
|
259 |
src_process(src_converter, &resample_data); |
if ((err = src_process(src_converter, &resample_data)) != 0) |
260 |
|
error("src_process: %s", src_strerror(err)); |
261 |
|
|
262 |
xfree(infloat); |
xfree(infloat); |
263 |
|
|
264 |
outsize = outnum * samplewidth; |
outsize = resample_data.output_frames_gen * resample_to_channels * samplewidth; |
265 |
*out = xmalloc(outsize); |
*out = xmalloc(outsize); |
266 |
src_float_to_short_array(outfloat, (short *) *out, outnum); |
src_float_to_short_array(outfloat, (short *) *out, resample_data.output_frames_gen * resample_to_channels); |
267 |
xfree(outfloat); |
xfree(outfloat); |
268 |
|
|
269 |
#else |
#else |
301 |
} |
} |
302 |
#endif |
#endif |
303 |
|
|
304 |
|
if (tmpdata != NULL) |
305 |
|
xfree(tmpdata); |
306 |
|
|
307 |
|
/* Shrink 16bit output-samples to 8bit */ |
308 |
|
#ifndef HAVE_LIBSAMPLERATE /* libsamplerate produces 16bit samples */ |
309 |
|
if (format->wBitsPerSample != resample_to_bitspersample) |
310 |
|
#endif |
311 |
|
{ |
312 |
|
/* source: 16 bit, dest: 8 bit */ |
313 |
|
if (resample_to_bitspersample == 8) |
314 |
|
{ |
315 |
|
for (i = 0; i < outsize; i++) |
316 |
|
{ |
317 |
|
*out[i] = *out[i * 2]; |
318 |
|
} |
319 |
|
outsize /= 2; |
320 |
|
} |
321 |
|
} |
322 |
|
|
323 |
#ifdef B_ENDIAN |
#ifdef B_ENDIAN |
324 |
if (!stream_be) |
if (!stream_be) |
325 |
rdpsnd_dsp_swapbytes(*out, outsize, format) |
rdpsnd_dsp_swapbytes(*out, outsize, format); |
326 |
#endif |
#endif |
327 |
return outsize; |
return outsize; |
328 |
} |
} |
329 |
|
|
330 |
STREAM |
STREAM |