The audio resampling algorithm based on Fourier transform (complete C code included)

Source: Internet
Author: User

The audio sampling algorithm is mentioned earlier:

WebRTC Audio sampling algorithm with complete C + + sample code

An example of a concise interpolation audio resampling algorithm (with full C code)

A lot of friends have written to me in recent time, said some of their use of the situation and problems.

Frankly speaking, I have limited energy, but generally I will take the time to reply.

In most cases, read the code to solve the problem,

It's also a try.

Maybe, you solved it?

The WEBRTC sampling algorithm itself takes into account its own application scenarios,

So it has some limitations, such as not supporting arbitrary sample rates, and so on.

And the simple interpolation of this algorithm,

I've been using it personally because it's simple and straightforward.

I naturally did not go further to the scrutiny sampling algorithm,

Of course, there are many open-source sampling algorithms on the internet is also extremely good.

Always want to take time to do a balance of simplicity and quality of the algorithm out, nothing.

Recently has been in the death of the Fourier transform, online resources to see a basket.

Wandering to the end, there is no doubt that FFTW3 must be your first choice,

From the age of performance and the probability of use, well-deserved king.

Of course, by the way, some of the other FFT implementations, each with advantages and disadvantages.

For learning, as a reference is also the perfect choice.

Interested in the small partner, you can refer to it.

Https://github.com/cpuimage/StockhamFFT

Https://github.com/cpuimage/uFFT

Https://github.com/cpuimage/BluesteinCrz

Https://github.com/cpuimage/fftw3

Of course, the best reference, or FFTW3,

My git does the following:

1. Comb and adjust the directory structure

2. Remove some of the macro definitions that affect reading debugging and make big heads

3. Merge code to FFTW_API.C, remove some infrequently used code

Note: No rigorous test validation

Perhaps the meaning of this git existence is to make it easy for people to read and learn FFTW's algorithmic thinking,

and debugging, code deduction, and so on.

So there is a need for students can, refer to it.

Back to the topic of this time,

In the past, when the image algorithm, has been thinking about a problem,

Is it possible to resample images using the characteristics of the Fourier transform?

This is always a small stone in my heart, has not been put down.

Theoretically, it is only possible to estimate that the final quality is not guaranteed.

The best attempt is to re-sample audio, and in many cases

We often need to perform a Fourier transform on one audio, and then perform an on-or off-sample operation.

Is it possible to resample directly in the frequency domain?

Is this a measure of quality that can be guaranteed?

It turns out that this is feasible.

After a simple experiment, the audio resampling algorithm based on Fourier transform is baked.

The current example uses HSFFT, an open-source Fourier transform, to validate

The reason for not using FFTW3 is also simple, because the FFTW3 compiler comes in a bit of a hassle.

and Hsfft's function style is similar to the FFTW3, only the speed performance is inferior to FFTW3 only.

This is also in line with my requirements, the real application of the time to use FFTW3 replace it,

There is no need to use FFTW3 when validating ideas.

This is one of the reasons why I use clean resampling.

Each step must have policies and methods, not too much.

If you need it in certain circumstances, I can also matlab,python,delphi,c#,c++ and so on.

Language is just a tool, the key is thinking and thinking.

Paste the main code:

#ifndef MIN#defineMIN (A, B) ((a) < (b)? (a): (b))#endif voidFftresample (float*input,float*output,intSizein,intsizeout) {fft_t*fftin = (fft_t *)calloc(sizeof(fft_t), Sizein); fft_t*fftout = (fft_t *)calloc(sizeof(fft_t), sizeout); if(Fftin = = NULL | | fftout = =NULL) {        if(fftout) Free(fftout); if(Fftin) Free(Fftin);
Return } fft_real_object Fftplan= Fft_real_init (Sizein,1); Fft_r2c_exec (Fftplan, input, fftin); Free_real_fft (Fftplan); intHalfin = (Sizein/2) +1; intHalfout = (Sizeout/2) +1; for(inti =0; I < MIN (Halfin, halfout); ++i) {fftout[i].re=fftin[i].re; Fftout[i].im=fftin[i].im; } fft_real_object Ifftplan= Fft_real_init (Sizeout,-1); Fft_c2r_exec (Ifftplan, fftout, Output); Free_real_fft (Ifftplan); floatNorm =1. F/Sizein; for(inti =0; i < sizeout; ++i) {Output[i]= (Output[i] *norm); } Free(fftout); Free(Fftin);}

The algorithm is very simple, with a fashionable language to describe the algorithm, that is, "more return and less compensation."

Need to make up the FFT can be:

From polynomial multiplication to fast Fourier transform

Project Address:

Https://github.com/cpuimage/fftResample

With CMake compilation, the sample code is also concise.

Not much to explain it ~

Above, right when a.

If you have other related questions or needs, you can contact me to discuss the email.

e-mail address is:
[Email protected]

The audio resampling algorithm based on Fourier transform (complete C code included)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.