[SDL] Just can't get it done: resample sound
William Petiot
william at exoide.com
Sat Apr 3 15:28:45 PST 2004
You should try to think about your problem in another way..
try to fill destination array _from_ the src array, not the opposite
this would be something like this :
// WARNING : this code is untested, just written on the fly
// not optimized at all, certainly full of bugs
// btw: resampling without interpolation or filtering will sound weird :)
typedef unsigned long sample; // assuming 16 bits stereo
void resample(sample **ptr_dest,int *ptr_ndest, sample *src,int nsrc, float
factor)
{
int ndest,i ;
sample *dest;
ndest = (int) (nsrc / factor); // new size
dest = (sample *)malloc(ndest);
for (i = 0; i < ndest; ++i) {
// filling all destination samples from source
dest[i] = src[(int)(i*factor)];
// note that we work in "sample" unit (1 sample is 4 bytes)
}
// filling caller parameters
*ptr_dest = dest;
*ptr_ndest = ndest;
}
then, call this with :
sample *my_sample;
int my_sample_size;
sample *my_resampled;
int my_resampled_size;
// code to fill my_sample, load from disk etc
...
resample(&my_resampled,&my_resampled_size,my_sample,my_sample_size);
...
// use the sample
...
free(my_resampled);
Hope it helps. This code is only for explanations, it's suboptimal.
William.
On Saturday 03 April 2004 19:47, Johannes Bauer wrote:
> Hi folks,
>
> I posted here a while ago a message in which I asked for some help in
> resampling a sound sample in order to increase/decrease the pitch. I
> tried it back then and just couldn't get it done. Then I tried again
> right now and - once again - the result is all messed up. This is
> totally driving me nuts. Here's what I have:
[...]
More information about the SDL
mailing list