OS[n] = IS[(int)(x / y) * n];
where x/y is the relative offset factor.
The above solution is the easiest one around - the only problem being some the samples being duplicated if the output signal is at a lower sampling rate and some of the samples being decimated if the other way around. The result is a hissy sound. Just to leave space for error, is the above code correct or is there some better algorithm around (suitable for real-time use!)?
Thanks in advance,
Crispy
Resampling
Hi,
I need to resample a signal sampled at an arbitrary sampling rate to another signal with an arbitrary sampling rate. I know how this is done, but for some reason the outcome is not exactly what I expected. There are two ways to do the resampling - through the frequency domain which is not an option because I need to resample data (potentailly so much that it will slow down other processes or swamp the cpu) in real-time, and by decimation/duplication (sychronized resampling). I''m using the latter so that for:
output signal OS @ x Hz and
inpit signal IS @ y Hz
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
I used your algorithm for my music software (but insisted on the same source sample rate for speed). I also have a ''HQ'' mode that smooths the sound very nicely. For that I pre-interpolated my source sound x4 so that duplicating samples will only occur whne you play at 2 octaves below the original sound (in practise this doesn''t happen: 2 octaves down is -l-o-w-). for higher frequencies I calculated the skip and calculated the mean of every sample skipped, including the fractional samples at the start and end. This worked and the quality is truly perfect. Fast enough for real time? It''s about 2 or 3 times slower than the other method... but my software has a switch for that.
Cornutopia Games
http://www.cornutopia.net
Bytten Independent Games Magazine
http://www.bytten.com
Cornutopia Games
http://www.cornutopia.net
Bytten Independent Games Magazine
http://www.bytten.com
Thanks for the reply!
Just to make sure I understood you correctly before I start actually coding it (as your solution seems just as makeshift as mine and based on how you described the result, works):
>>For that I pre-interpolated my source sound x4
You simply increased the sampling rate by four, interpolating added samples?
>>duplicating samples will only occur whne you play at 2 octaves below the original sound
2 octaves is not very low. I''m aiming for 3 - 3.5 octaves below middle C (the standard reach of the piano). I guess a higher interpolation rate would suffice in this case... The good thing is, though, most notes should remain in the 4 primary octaves.
>>for higher frequencies I calculated the skip and calculated the mean of every sample skipped,
>>including the fractional samples at the start and end
You basically computed the average of any n samples skipped resulting in a compact interpolated version of the original signal?
>>This worked and the quality is truly perfect
Sorry to break this to you, but you can''t have "perfect" conversion quality via transformations in the time domain. While this will allow you simple pitch changes by means of lossy sampling rate conversion (as opposed to frequency pitch shift, meaning an FFT, shift and an IFFT), it will bring along a loss of information. If you''ve managed to make it inaudible to the listener, that''s great! That''s what really counts.
I''ve been doing some additional research on the subject and came across this place. It describes the bandlimited interpolation, though at the first glance the math was a wee bit confusing for me. You also need to be familiar with basic DSP terms such as lowpass, bandpass, convolution, etc. In case anyone''s interested...
Crispy
Crispy
Just to make sure I understood you correctly before I start actually coding it (as your solution seems just as makeshift as mine and based on how you described the result, works):
>>For that I pre-interpolated my source sound x4
You simply increased the sampling rate by four, interpolating added samples?
>>duplicating samples will only occur whne you play at 2 octaves below the original sound
2 octaves is not very low. I''m aiming for 3 - 3.5 octaves below middle C (the standard reach of the piano). I guess a higher interpolation rate would suffice in this case... The good thing is, though, most notes should remain in the 4 primary octaves.
>>for higher frequencies I calculated the skip and calculated the mean of every sample skipped,
>>including the fractional samples at the start and end
You basically computed the average of any n samples skipped resulting in a compact interpolated version of the original signal?
>>This worked and the quality is truly perfect
Sorry to break this to you, but you can''t have "perfect" conversion quality via transformations in the time domain. While this will allow you simple pitch changes by means of lossy sampling rate conversion (as opposed to frequency pitch shift, meaning an FFT, shift and an IFFT), it will bring along a loss of information. If you''ve managed to make it inaudible to the listener, that''s great! That''s what really counts.
I''ve been doing some additional research on the subject and came across this place. It describes the bandlimited interpolation, though at the first glance the math was a wee bit confusing for me. You also need to be familiar with basic DSP terms such as lowpass, bandpass, convolution, etc. In case anyone''s interested...
Crispy
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement