![]() |
Sprex![]() |
||||||
|
| |||||||
|
Garbage modeling Adding words Microphones Open Mic Real-time response Sample rate conversion Grammars, dictionaries, and "vocabularies" Other FAQs Other Sprex Products/Services Exit> |
This requires a bit of DSP hacking. I've done and debugged this kind
of thing in the past in a not-very-clean way (simple linear
interpolation between samples) which works but sacrifices quality.
The theory of how to do it cleanly is in, for example, Bracewell's
Fourier Transform and its Applications, p194 (McGraw-Hill 1986),
basically you convolve the sampled output with the "sinc" function
(sin(pi*t)/pi*t) at each output time, presumably windowing the sinc
function values at some distance from zero. Here's a non-debugged
pass at the core function.
signed short *double_sample_rate(signed short *in,int len,int order) {
/* *in is an array of shorts of length len.
* order is the number of sinc multiply-adds to do in the
* convolution that approximates each output sample.
* free the returned buffer when you're done with it.
* The return value is a pointer to the doubled-in-size output buffer
* containing a doubled-in-sample-rate version of the input.
*/
const float sinc[] = { 0.6366, -0.2122, 0.1273, -0.0909, 0.0707, -0.0579,
0.0490, -0.0424, 0.0374, -0.0335, 0.0303, -0.0277 }
int i,j,k,m;
float sum;
/* keep order between 1 and 12, the size of sinc[] */
if (order > 12) order = 12; if (order < 1) order = 1;
/* malloc output buffer */
if (out = (signed short *)malloc(sizeof(signed short)*len*2)) {
return(NULL);
}
/* foreach input sample generate two output samples */
for (m = 0; m < len; m++) {
out[m*2] = in[m];
/* out[m*2+1] = sum over k = 0..order of sinc[k]*in[m+1+-(k+1)] */
for (sum=0.0,k=0; k
|
||||||
Copyright © 1996-2005
Sprex, Inc.
All rights reserved.
|