hello!
I’m trying to build a “peak array” to display an audio file waveform.
I wrote that piece of code :
peaksArraySize = (int)(audioFormatReader->lengthInSamples/blockSize);
peaksArray = BlockMinMax[peaksArraySize];
int64 posInAudioFile = 0;
int posInArray = 0;
float minLeft = 1;
float maxLeft = -1;
float minRight = 1;
float maxRight = -1;
int buildingWaveformPercentCompleted;
while (posInAudioFile < audioFormatReader->lengthInSamples) {
buildingWaveformPercentCompleted = posInAudioFile*100/audioFormatReader->lengthInSamples;
audioFormatReader->readMaxLevels(posInAudioFile,posInAudioFile+blockSize,minLeft,maxLeft,minRight,maxRight);
peaksArray[posInArray].min = std::min(minLeft,minRight);
peaksArray[posInArray].max = std::max(maxLeft,maxRight);
posInAudioFile+=blockSize;
posInArray++;
peakBuildingInProgress(buildingWaveformPercentCompleted);
}
peaksAreBuilt();
but it’s very very slow, it seems to take exponentially more time as the file is read.
Should I use something else than the AudioFormatReader ?
Many thanks for helping a newbie!
Geoffroy