132 |
int err; |
int err; |
133 |
#endif |
#endif |
134 |
|
|
|
#ifndef HAVE_LIBSAMPLERATE |
|
|
if (device_srate != 44100 && device_srate != 22050) |
|
|
return False; |
|
|
#endif |
|
|
|
|
135 |
if (device_bitspersample != 16 && device_bitspersample != 8) |
if (device_bitspersample != 16 && device_bitspersample != 8) |
136 |
return False; |
return False; |
137 |
|
|
165 |
return False; |
return False; |
166 |
if ((format->wBitsPerSample != 8) && (format->wBitsPerSample != 16)) |
if ((format->wBitsPerSample != 8) && (format->wBitsPerSample != 16)) |
167 |
return False; |
return False; |
|
#ifndef HAVE_LIBSAMPLERATE |
|
|
if ((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050)) |
|
|
return False; |
|
|
#endif |
|
168 |
|
|
169 |
return True; |
return True; |
170 |
} |
} |
176 |
#ifdef HAVE_LIBSAMPLERATE |
#ifdef HAVE_LIBSAMPLERATE |
177 |
SRC_DATA resample_data; |
SRC_DATA resample_data; |
178 |
float *infloat, *outfloat; |
float *infloat, *outfloat; |
|
int innum, outnum; |
|
179 |
int err; |
int err; |
180 |
#else |
#else |
181 |
int offset; |
int ratio1k = (resample_to_srate * 1000) / format->nSamplesPerSec; |
182 |
#endif |
#endif |
183 |
|
int innum, outnum; |
184 |
static BOOL warned = False; |
static BOOL warned = False; |
185 |
unsigned char *tmpdata = NULL; |
unsigned char *tmpdata = NULL; |
186 |
int samplewidth = format->wBitsPerSample / 8; |
int samplewidth = format->wBitsPerSample / 8; |
223 |
warned = True; |
warned = True; |
224 |
} |
} |
225 |
|
|
226 |
|
innum = size / samplewidth; |
227 |
|
|
228 |
/* Do the resampling */ |
/* Do the resampling */ |
229 |
#ifdef HAVE_LIBSAMPLERATE |
#ifdef HAVE_LIBSAMPLERATE |
230 |
if (src_converter == NULL) |
if (src_converter == NULL) |
233 |
return 0; |
return 0; |
234 |
} |
} |
235 |
|
|
236 |
innum = size / samplewidth; |
outnum = ((float) innum * ((float) resample_to_srate / (float) format->nSamplesPerSec)) + 1; |
|
outnum = ((float)innum * ((float)resample_to_srate / (float)format->nSamplesPerSec)) + 1; |
|
237 |
|
|
238 |
infloat = xmalloc(sizeof(float) * innum); |
infloat = xmalloc(sizeof(float) * innum); |
239 |
outfloat = xmalloc(sizeof(float) * outnum); |
outfloat = xmalloc(sizeof(float) * outnum); |
255 |
|
|
256 |
outsize = resample_data.output_frames_gen * resample_to_channels * samplewidth; |
outsize = resample_data.output_frames_gen * resample_to_channels * samplewidth; |
257 |
*out = xmalloc(outsize); |
*out = xmalloc(outsize); |
258 |
src_float_to_short_array(outfloat, (short *) *out, resample_data.output_frames_gen * resample_to_channels); |
src_float_to_short_array(outfloat, (short *) *out, |
259 |
|
resample_data.output_frames_gen * resample_to_channels); |
260 |
xfree(outfloat); |
xfree(outfloat); |
261 |
|
|
262 |
#else |
#else |
263 |
if (format->nSamplesPerSec != 22050) |
/* Michaels simple linear resampler */ |
264 |
|
if (resample_to_srate < format->nSamplesPerSec) |
265 |
{ |
{ |
266 |
if (!warned) |
warning("downsampling currently not supported!\n"); |
|
{ |
|
|
warning("unsupported source samplerate (%u), not resampling!\n", |
|
|
format->nSamplesPerSec); |
|
|
warned = True; |
|
|
} |
|
267 |
return 0; |
return 0; |
268 |
} |
} |
269 |
|
|
270 |
outsize = size * 2; |
outnum = (innum * ratio1k) / 1000; |
271 |
|
|
272 |
|
outsize = outnum * samplewidth; |
273 |
*out = xmalloc(outsize); |
*out = xmalloc(outsize); |
274 |
|
bzero(*out, outsize); |
275 |
|
|
276 |
/* Resample from 22050 to 44100 */ |
for (i = 0; i < outsize / (resample_to_channels * samplewidth); i++) |
|
for (i = 0; i < (size / samplewidth); i++) |
|
277 |
{ |
{ |
278 |
/* On a stereo-channel we must make sure that left and right |
int source = ((i + ratio1k / 1000 - 1) * 1000) / ratio1k; |
|
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; |
|
279 |
|
|
280 |
memcpy(*out + offset, in + (i * samplewidth), samplewidth); |
if (source * resample_to_channels + samplewidth > size) |
281 |
memcpy(*out + (resample_to_channels * samplewidth + offset), |
break; |
|
in + (i * samplewidth), samplewidth); |
|
282 |
|
|
283 |
|
if (resample_to_channels == 2) |
284 |
|
{ |
285 |
|
memcpy(*out + (i * resample_to_channels * samplewidth), |
286 |
|
in + (source * resample_to_channels * samplewidth), samplewidth); |
287 |
|
memcpy(*out + (i * resample_to_channels * samplewidth) + samplewidth, |
288 |
|
in + (source * resample_to_channels * samplewidth) + samplewidth, |
289 |
|
samplewidth); |
290 |
|
} |
291 |
|
else |
292 |
|
{ |
293 |
|
memcpy(*out + (i * samplewidth), in + (source * samplewidth), samplewidth); |
294 |
|
} |
295 |
} |
} |
296 |
|
outsize = i * resample_to_channels * samplewidth; |
297 |
#endif |
#endif |
298 |
|
|
299 |
if (tmpdata != NULL) |
if (tmpdata != NULL) |