Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU intensity of resampling #239

Open
geoffw64 opened this issue Dec 17, 2024 · 4 comments
Open

CPU intensity of resampling #239

geoffw64 opened this issue Dec 17, 2024 · 4 comments

Comments

@geoffw64
Copy link

Hey Dan,
I have a question about resampling, as it seems to be expensive in terms of CPU.

Declarations:
univector audio_resampled(2229);
univector audio(2048);
samplerate_converter resampler = samplerate_converter(resample_quality::draft, 48000, 44100);

For each chunk of 2048 samples:
resampler.process(audio_resampled, audio);

This consumes approx. 40 sec CPU to process 4.9 million samples, on my 2018 Mac Mini (2.7GHz Core i5 with 6 cores). Is there are less CPU intensive way to do this?

Appreciate your help.

Thanks in advance,
Geoff.

@geoffw64
Copy link
Author

Bump…. any feedback on this issue?
Thanks in advance.
Geoff.

@dancazarin
Copy link
Member

Hey Geoff, I don't think there's a better way to handle resampling—your code looks good. The speed seems reasonable given the amount of data and the 2.7 GHz CPU. The number of cores doesn't matter here because resampling uses a single thread. Just ensure that you're using release (optimized) build and avx2 is enabled (or multiarch). Can you please post the output of library_version() function?

@geoffw64
Copy link
Author

Hey Dan,

Thanks for your response.

library_version() produced KFR 6.0.4 debug avx2 64-bit (clang-15.0.0/macos) +in +ve

I was building for Debug. Changing Xcode Scheme to Release build and it now consumes less than 4 seconds CPU. An order of magnitude faster!

I have the -Os and -mavx2 options set in Xcode for both Debug and Release builds. Looks like mavx2 is in effect.

Do I need to specify any #define in my C++ program for further optimisation? I don't need multi-architecture.

Reason for my interest in performance of this feature is that I'm resampling (and applying filtering) at playback time.

I appreciate your help. Fantastic library BTW - great work.

Cheers,
Geoff.

@dancazarin
Copy link
Member

Multiarchitecture is controlled by KFR_ENABLE_MULTIARCH cmake variable.
You can set it to off by appending -DKFR_ENABLE_MULTIARCH=OFF to your cmake command line.
Setting KFR_ARCH also makes sense if you target single architecture, for example -DKFR_ARCH=avx2. This automatically sets all required compiler flags. Please remove cmake cache (CMakeCache.txt in your build directory) before changing cmake variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants