Better-sounding wave~ object?
The sound artifacts of the wave~ object's resampling bug me when I play things back at a slower speed, even in high quality mode. I noticed the interpolation method is linear, and wondered if there was an object that did the same functions with a better-sounding algorithm? I don't mind 10x the CPU use, I just want it to sound good. Is anything out there?
The low quality interpolation is linear, the high quality probably cubic, which would be the standard (more expensive) way of interpolation.
Maybe you simply expected something else to hear? Its very dependent on the material. If you feed it with sounds from an aliased source, you might hear artifacts which had been out of your personal hearing range. You could aways filter the result or the content...
Anyway, its hard to imagine what you hear and what you wanted to hear with words which just say "artifacts"...
Never expect that someone else hears and interprets the same as you do...
Stefan
stefantiedje wrote on Sun, 21 June 2009 00:16The low quality interpolation is linear, the high quality probably cubic, which would be the standard (more expensive) way of interpolation.
Maybe you simply expected something else to hear? Its very dependent on the material. If you feed it with sounds from an aliased source, you might hear artifacts which had been out of your personal hearing range. You could aways filter the result or the content...
Anyway, its hard to imagine what you hear and what you wanted to hear with words which just say "artifacts"...
Never expect that someone else hears and interprets the same as you do...
Stefan
The maxhelp file for wave~ says,
"set interpolation mode: 0=no interp, 1=linear interp high quality, 2=linear interp low quality.(default is 1). mode 2 is faster than mode 1, but has more interpolation artifacts and cannot play buffer~s of arbitrary length."
I took this to mean that modes 1 and 2 were both linear interpolation, but the help file may be misleading. Is mode 1 actually cubic?
Regarding the artifacts in mode 1 (high quality), they can be measured in Max directly using the spectrum~ object. I just did this test:
1) Record a full scale sine wave (I chose 10kHz as an extreme) to a .wav file
2) Read the .wav into a buffer~ object
3) Playback the .wav using a wave~ object at normal speed
4) Decrease the playback speed and watch what happens to the spectrum
The spectrum in step 1 is a single spike at 10k with a small skirt. The spectrum in step 4 becomes closer and closer to a triangle wave spectrum as playback speed decreases. There are audible and visible harmonics of the original sine wave. This distortion is what I am trying to get away from. I hear it on everything that I run through a wave~ object at slower speeds.
I could filter if I was dealing with single sine waves, but on anything with complex harmonic content it becomes impossible.
Are there no standards objects to work around this?
As I understand it:
slower = RE SAMPLED - taking every 0.Xth (or X.Xth for faster) sample, rather than each sample.
By definition, re sampling will introduce artifacts.
See
Oppenheim and Schaefer Discrete-Time Signal Processing
for the facts, but these facts use quite high level math..be prepared.
To stop the distortion you hear, one must use a very expensive "brick-wall sinc" filter (or one of similar quality)
built to the original sample rate and the desired sampling rate ("tuning"),...this will be a filter with many poles and zeros: complex enough that the artifacts are not audible.
Linear and cubic spline interpolation will not generally do this.
Please check out "Secret Rabbit Code" (Sample Rate Converter) athttp://www.mega-nerd.com/SRC/
This code offers effective filters and works quite well. (Julius O. Smith wrote a seminal article on this, please check out his page on this @ http://ccrma-www.stanford.edu/~jos/resample/ ).
lookin at the MSP object repository, I don't see.....well.....
Hmm...we (the community) could probably use a port of SRC to a Msp object....this would do as you wish, but up until the latest generation of processors it was probably too cpu intensive to make a common real-time object. Probably we could use it now in msp in realtime...but it's not cheap, CPU-wise!!!
if you had wanted to separate length of sound from pitch change (evidently, you do not), it is even more difficult: fft and granular approaches are both in vogue, with differing results...
and each is not cheap on processing....
just my tuppence,
char lieb, aka j2k
PS:
"Are there no standards objects to work around this?"
Huh? Resampling is ALWAYS a complex DSP issue. If we insisted that "EVERY OBJECT IN MSP BE ALIAS FREE", one could practically NOTHING worthwhile in MSP with a standard CPU...
MSP can and does do the best it can with lowering the level of distortion (linear interpolation, etc.), but by definition, the act of resampling introduces distortion, and getting "totally" rid of it is
a) practically impossible
b) produces diminishing returns for huge cpu cycle expenditures.
so... I'll look at making (open source) SRC into a msp object..
perhaps others not employed as application/database production support for a huge property insurance corp. as it enters the hurricane season in Florida will have more time ("M.O.G., pray for us coders now and at the hour of some horrific catastrophe...")
Good luck, & do try to get through the SRC site docs, and maybe Julius' article in order to understand what is involved: I guarantee you, it would help your electronic music chops....
cfb
I'm not sure what frequencies OP is listening to, but (thinking aloud)... could a cycle~ with a larger wavetable do the trick? Something like 32768 samples? That just eats some memory without taking a lot of CPU (except a little at initialization time).
Alternately, there was a suggestion a few years ago that current processors could possibly handle actually calculating sin() in realtime.
Either of the above would be straightforward for a 3PO developer to build.
couldn't jean-francois' jitter time stretch thing be adapted to this?
Mike S wrote on Wed, 24 June 2009 18:57couldn't jean-francois' jitter time stretch thing be adapted to this?
i dont see the point in beeing able of playing 8 bit 8 khz files
with as less artefacts as possible, but just as an idea:
8000 = 48000/6
so as long as you set your hardware to 48k, you do not need
to interpolate anything.
-110
I'm not trying to resample a sine wave specifically, it was just an example to explain what was meant by "artifacts."
This originally came up in my Turntable Surgeon project that simulates record scratching. Using the wave~ object sounds bad to me at slow rotation speeds. Compared to an actual record moving slowly, it has much more distortion given the linear interpolation. Signal processing theory says that distortion can be eliminated. In practical terms, it can at least be a lot better.
Charles,
I read Julius Smith's work as often as I can. I do embedded audio systems, so I deal with signal processing and audio DSP every day. That's why I'm surprised there is no support for some sort of windowed sinc/polyphase/etc mode of interpolation. It seems like a reasonably standard process by now. Yes, it is a lot more MACs to do the FIR filtering involved, but I'd gladly put up with 10x the cpu use plus the extra memory needed for a big windowed sinc LUT. I'm not asking for perfection, just something better.
I can write DSP algorithms, but I don't have the knowledge or time to learn how to properly make an MSP external. Is there any way that I can write an algorithm that someone else could implement into the wave~ object as an alternate quality mode?
I think groove~ does better interpolation, but I could be wrong.
mz