AIMP Forum

AIMP for Windows => Плеер / Player => Предложения / Suggestions => Звуковой движок / Sound Engine => Topic started by: MadMonday on July 12, 2022, 10:35:06

Title: Resampling
Post by: MadMonday on July 12, 2022, 10:35:06
Hey...

I really like AIMP and have been looking forward the project for a few years.

But it keeps pulling me back to WINAMP. And only for one reason.
          >>Procruste's Winamp DSP Plugin<<
A very small plugin (20k .dll), but a big master in one discipline: "Time Stretching".

I don't know any other resample plugin, that works as precisely and reliably as this one.
It has no frills and works on current hardware like it does 15 years ago. I use it every day.

Even if Winamp is running in the background and I'm editing large files in Photoshop, for example...
Procrustes resamples for hours consistently and accurate.

For me its absolute amazing that the plugin always keeps the tempo I set.
The guy who wrote this code was focused on adjusting everything in realtime, but very smooth
and without major fluctuations. The plugin works so fast and precise, it's fantastic.

Procrustes can adapt sound, tonality, modulation and frequency to a changed beat in milliseconds.
With singing or without. Faster and slower...
Everything sounds like before. There will be no "Barbie-Voice". :-)
Tempo speeds from 25% to 400% on a normalized scale.

I attached two versions. I know it was written entirely in assembler and these two versions are clones.
"Viruslav" has re-assembled ver.1.00 and re-released it slightly improved. Supposedly.
I don't know if this can work. "Re-assembly". Mainly because this is not an exe file, it's a .dll.
The original version was most likely written by his former boss.

But maybe it's not difficult after all. :-) Who knows...
Then I would be happy, if you could integrate this function into AIMP.
The sliders are already present under Sound Effects.
But the sliders are so sensitive. You cannot use the function in this way.

BUT NOW YOU CAN DO IT "better" :-))

May be here are the secrets of Procrustes "REAL-TIME SAMPLING":

Real-Time Resampling

We do it using a 50-tap windowed sinc filter whose coefficients are calculated in real-time. The following paragraphs explain the issue in more detail.


Introduction

Let us for example take the case where we want to play back an audio file at a different speed than its recording speed (like playing a vynil record at 33 instead of 45 RPM or vice-versa). It can be done using sample rate conversion (or simply resampling), and playing back the file at a constant "standard" rate (usually 44100 Hz). If we are playing the file at its original speed (100% speed), we are moving from the first to the last sample with a step equal to 1, and output the values of the samples 44100 times per second. If we have to play back the file at a lower speed, the step must be lower than 1, or it must be a fractional number between 0 and 1. If the speed is higher than 100%, the step must be higher than 1, and again can be a fractional number. Then we output the new values 44100 times per second again. But if the step is fractional, how can we get the values of these intermediate points? Of course the easiest and the fastest way is to use the nearest neighbour (zeroth order polynomial interpolation), but even without knowledge of digital signal processing theory, it is obvious that this method will produce serious artefacts and audible distortion. The problem is to interpolate between the samples of the original file to find the new values to be played.


The First Method

Time domain interpolation between the samples using polynomial interpolation. If the polynomial is of infinitely high order, the resulting value at the calculated point will have infinitely high precision. With 16-bit accuracy, the polynomial will have to be of order somewhere between several hundreds and several thousands. Lagrange interpolation can be used, but it is very time-consuming.
The simplest resampling routine uses a linear interpolation (first order polynomial) to approximate the exact values between the samples. Linear interpolation has two major problems:

*The magnitude (and the power) of all frequencies is reduced. The high frequencies are reduced more than the others, and it is very audible.

*The lost power produces non-harmonic "parasitic" signals with magnitude comparable to the magnitude of the true signal at high frequencies (over 10 kHz).

As a strength side of the linear interpolation, we can point that it is very fast – our test assembly code could be executed even on a 386 in real time!

A cubic (third order) interpolation can be used instead, but the results are only slightly (about 10 dB) better, and the execution time is longer, although a 486 can still execute it in real time.


The Method We Use

It is called "band limited interpolation", and is a frequency-domain interpretation of the interpolation problem. We will not go deeply into the theory of that kind of interpolation, but will only say that an interpolation filter is used to reconstruct the original analogue signal from its samples, however in our case it is done digitally, and only at specified points. The theory states that the ideal interpolation filter is the sinc function [sin(x) / x, –∞ < x < +∞]. Of course it is unrealisable. For 16-bit accuracy, several hundreds or thousands of points in the filter kernel have to be used. A very good approximation of the ideal sinc filter kernel is the so called "windowed sinc function", where the sinc function is truncated and forced to lessen its values faster toward the ends. This is done by multiplying it with an appropriate weighting function, which also has to be calculated.

Our resampling routine uses a 50-tap FIR (windowed sinc) filter to interpolate between the samples. We believe that the quality of this filter exceeds the capabilities of the human ear. Its non-harmonic signal attenuation is more than 96 dB for frequencies below 16 kHz, which exceeds the quality of the 16-bit representation of the signal! Up to 18-19 kHz, the attenuation of the non-harmonic signals is still very high. And there are no high-frequency losses!

The bad side is that it is relatively time-consuming. Because resampling is not a linear process, the filter coefficients are different at each moment, and have to be either calculated each time, or stored in a very long table. We do not use a table, but calculate them and do the convolution (filtering using the calculated values) in real-time. This requires calculation of sine and cosine, division and many multiplications and additions per a single point.

We have three different highly optimized versions of our resampling routine – FPU, SSE and 3DNow! All of them feature the same algorithm, which consists of real time calculation of 50 filter coefficients for each output sample (quite time-consuming), plus the filtering process itself using the calculated values.

*1*) The FPU resampling routine runs on all x86 processors which have a x87 floating point unit. It takes about 25% of the CPU time on Intel Pentium II 450 MHz, about 6% on Intel Pentium 4 – 2.1 GHz, about 54% on AMD K6-2 450 MHz, about 88% on VIA Ezra-T 600 MHz and about 4% on AMD Athlon XP 2000+ for a stereo file.

*2*) The SSE resampling routine runs on Intel Pentium III, Pentium 4, AMD Athlon XP, Athlon 64, VIA Nehemiah and all current and future processors which support or will support Intel MMX technology and Streaming SIMD Extensions. The routine uses highly optimized MMX and SSE code and takes about 2.5% of the CPU time on Intel Pentium 4 – 2.1 GHz and AMD Athlon XP 2000+ for a stereo file.

*3*) The 3DNow! resampling routine runs on AMD K6-2, K6-III, Athlon, Athlon XP, Athlon 64, VIA Ezra-T, and all current and future processors which support or will support Intel MMX and AMD 3DNow! technology. It uses highly optimized MMX and 3DNow! code and takes less than 15% of the CPU time on AMD K6-2 450 MHz, about 3% on AMD Athlon XP 2000+ and about 36% on VIA Ezra-T 600 MHz for a stereo file.

Note:The percentage numbers are not exact and are given for clarity only. In other words, "your mileage may vary".


Other Known Methods

There is another algorithm which uses the Fast Fourier Transform (FFT) to interpolate a whole block of samples.


If you think this is useful, maybe it's better to keep it a secret?
If so, take it. Delete this post.

Build-in the cool new feature (for me :-)) and I'll make a donation to the wayback machine. ;-)

Many greetings


=================

Addendum:

For anyone who's interested:
Look for a high-quality yet fast real-time resampling algorithm called "Sylea" (this is the wife of Procrustes :) )

Title: Re: Resampling
Post by: MadMonday on July 13, 2022, 20:22:33
Another private treasure from the depths of the net :

Quote
Προκρούστης™ (Procrustes): The Real-Time-Stretching Technology

Σίλεια™ (Sylea): The Real-Time Audio Resampling Technology

At last! A high-quality at a wide-range (from -50% to +200%), real-time-stretch technology that does not require a Cray®, and works in real-time even on slow x86 CPUs down to 233 MHz [if the CPU lacks an SIMD instruction set (3DNow! and SSE), else the speed doubles!]. Its dedicated transient processing provides the crispest possible attacks. Combined with the lack of any "phasiness", echos or other audible artefacts in a wide range of ratios, it makes it ideal for any purpose where quality and speed are equally important. That’s Προκρούστης™!

Σίλεια™ is a resampling technology that provides 100% mathematically correct resampling, thus ensuring the highest possible audio quality with the same wide range, real-time capabilities, and low CPU requirements as Προκρούστης™.

FPU, 3DNow! and SSE versions, written in highly optimised 100% pure assembly code, which are selected either automatically according to the CPU or manually, are available together in .DLL or object code format, suitable for linking with any 32-bit code on any OS, with a reference and usage examples in both Assembly and C++ to get you started instantly.

And these treasures don’t require you to rob a bank to license!


It's unique and THIS code MUST BE poetry.
It's time to bring it back to life!
Title: Re: Resampling
Post by: MadMonday on July 13, 2022, 23:51:34
For everyone who still doesn't know what I mean
and why I use the resampler every day
and don't want to be without it anymore...  ;D

Actually, it's that simple...
It just gives me a kick to hear the music a little faster.

File 01 with normal speed.
File 02 at 115% with Procrustes ver1.20a and Winamp ver5.8

Compare yourself...  8)