Hi to all,
I’m new to the Juce framework and I’m trying to integrate it in one of my Qt project to replace some part that is done with some other libraries.
At the moment I would like to use the AudioFormatReader to read a wave file in chunk to create some visualization instead of the libsndfile library I’m currently using, but I’m noticing a really big gap in performance between the two library, and I’m trying to understand why.
To contextualize the situation I’m currently reading a stereo wav file in chunk of around 5113 frames into a multidimensional float/double array that I will process after.
The read done with libsndfile is done in this way:
double chunk = new double[ 2(region_end_frame - region_start_frame)];
if (sf_seek(sndFile, region_start_frame, SEEK_SET) == -1) {
perror(“seek error in AudioUtil::peakForRegion function\n”);
return this->regionPeak;
}if(sf_readf_double(sndFile, chunk, (region_end_frame - region_start_frame) ) == 0) {
return this->regionPeak;
}
sndFile is the resource handle to the opened wave file by the libsndfile library.
This code is executed in around 25/26 microseconds.
The libsnd is the version 1.1.0 and is static linked by cmake in the project.
The one done with AudioFormatReader is done in this way:
int frameCount = region_end_frame - region_start_frame;
float** audioBuffer = new float*[audioReader->numChannels];
for(uint i = 0; i < audioReader->numChannels; ++i) {
audioBuffer[i] = new float[frameCount];
}audioReader->read(audioBuffer, audioReader->numChannels, region_start_frame, frameCount);
The audioReader is the AudioFormatReader created using the AudioFormatManager::createReaderFor().
This code is executed in 330/350 microseconds.
The Juce framework is added as a submodule of my project in cmake (I’m using add_subdirectory to add the juce directory and target_link_libraries to include juce:: and juce::juce_audio_formats in the compilation)
As you can see there’s more then 10x difference in time reading the same amount of data from the same file on the same computer.
What can be the cause? Am I missing something? Maybe I’ve left some “debugging” option active including the Juce library with cmake that is slowing down the reading?
There’s a more efficient way to read samples in Juce that I’m missing?
Hope to have written enough information.
Thanks to all!
Cheers
Daniele