diff --git a/src/BlockFile.cpp b/src/BlockFile.cpp index aaa2a5c24..12c051163 100644 --- a/src/BlockFile.cpp +++ b/src/BlockFile.cpp @@ -213,6 +213,16 @@ void *BlockFile::CalcSummary(samplePtr buffer, sampleCount len, CopySamples(buffer, format, (samplePtr)fbuffer, floatSample, len); + CalcSummaryFromBuffer(fbuffer, len, summary256, summary64K); + + delete[] fbuffer; + + return fullSummary.get(); +} + +void BlockFile::CalcSummaryFromBuffer(const float *fbuffer, sampleCount len, + float *summary256, float *summary64K) +{ sampleCount sumLen; sampleCount i, j, jcount; @@ -306,10 +316,6 @@ void *BlockFile::CalcSummary(samplePtr buffer, sampleCount len, mMin = min; mMax = max; - - delete[] fbuffer; - - return fullSummary.get(); } static void ComputeMinMax256(float *summary256, diff --git a/src/BlockFile.h b/src/BlockFile.h index 3fbaf53c2..a9f17dca1 100644 --- a/src/BlockFile.h +++ b/src/BlockFile.h @@ -167,10 +167,15 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { protected: /// Calculate summary data for the given sample data + /// Overrides have differing details of memory management virtual void *CalcSummary(samplePtr buffer, sampleCount len, sampleFormat format, // This gets filled, if the caller needs to deallocate. Else it is null. ArrayOf &cleanup); + // Common, nonvirtual calculation routine for the use of the above + void CalcSummaryFromBuffer(const float *fbuffer, sampleCount len, + float *summary256, float *summary64K); + /// Read the summary section of the file. Derived classes implement. virtual bool ReadSummary(void *data) = 0; diff --git a/src/blockfile/ODDecodeBlockFile.cpp b/src/blockfile/ODDecodeBlockFile.cpp index 4626118ab..d25066cda 100644 --- a/src/blockfile/ODDecodeBlockFile.cpp +++ b/src/blockfile/ODDecodeBlockFile.cpp @@ -415,95 +415,8 @@ void *ODDecodeBlockFile::CalcSummary(samplePtr buffer, sampleCount len, CopySamples(buffer, format, (samplePtr)fbuffer, floatSample, len); } - sampleCount sumLen; - sampleCount i, j, jcount; - - float min, max; - float sumsq; - - // Recalc 256 summaries - sumLen = (len + 255) / 256; - - - for (i = 0; i < sumLen; i++) { - min = fbuffer[i * 256]; - max = fbuffer[i * 256]; - sumsq = ((float)min) * ((float)min); - jcount = 256; - if (i * 256 + jcount > len) - jcount = len - i * 256; - for (j = 1; j < jcount; j++) { - float f1 = fbuffer[i * 256 + j]; - sumsq += ((float)f1) * ((float)f1); - if (f1 < min) - min = f1; - else if (f1 > max) - max = f1; - } - - float rms = (float)sqrt(sumsq / jcount); - - summary256[i * 3] = min; - summary256[i * 3 + 1] = max; - summary256[i * 3 + 2] = rms; - } - - for (i = sumLen; i < mSummaryInfo.frames256; i++) { - // filling in the remaining bits with non-harming/contributing values - summary256[i * 3] = FLT_MAX; // min - summary256[i * 3 + 1] = -FLT_MAX; // max - summary256[i * 3 + 2] = 0.0f; // rms - } - - // Recalc 64K summaries - sumLen = (len + 65535) / 65536; - - for (i = 0; i < sumLen; i++) { - min = summary256[3 * i * 256]; - max = summary256[3 * i * 256 + 1]; - sumsq = (float)summary256[3 * i * 256 + 2]; - sumsq *= sumsq; - - for (j = 1; j < 256; j++) { - if (summary256[3 * (i * 256 + j)] < min) - min = summary256[3 * (i * 256 + j)]; - if (summary256[3 * (i * 256 + j) + 1] > max) - max = summary256[3 * (i * 256 + j) + 1]; - float r1 = summary256[3 * (i * 256 + j) + 2]; - sumsq += r1*r1; - } - - float rms = (float)sqrt(sumsq / 256); - - summary64K[i * 3] = min; - summary64K[i * 3 + 1] = max; - summary64K[i * 3 + 2] = rms; - } - for (i = sumLen; i < mSummaryInfo.frames64K; i++) { - summary64K[i * 3] = 0.0f; - summary64K[i * 3 + 1] = 0.0f; - summary64K[i * 3 + 2] = 0.0f; - } - - // Recalc block-level summary - min = summary64K[0]; - max = summary64K[1]; - sumsq = (float)summary64K[2]; - sumsq *= sumsq; - - for (i = 1; i < sumLen; i++) { - if (summary64K[3*i] < min) - min = summary64K[3*i]; - else if (summary64K[3*i+1] > max) - max = summary64K[3*i+1]; - float r1 = (float)summary64K[3*i+2]; - sumsq += (r1*r1); - } - - mMin = min; - mMax = max; - mRMS = sqrt(sumsq / sumLen); + BlockFile::CalcSummaryFromBuffer(fbuffer, len, summary256, summary64K); //if we've used the float sample.. if(format!=floatSample) diff --git a/src/blockfile/ODPCMAliasBlockFile.cpp b/src/blockfile/ODPCMAliasBlockFile.cpp index b548da2e1..f88ba4ea4 100644 --- a/src/blockfile/ODPCMAliasBlockFile.cpp +++ b/src/blockfile/ODPCMAliasBlockFile.cpp @@ -482,95 +482,8 @@ void *ODPCMAliasBlockFile::CalcSummary(samplePtr buffer, sampleCount len, CopySamples(buffer, format, (samplePtr)fbuffer, floatSample, len); } - sampleCount sumLen; - sampleCount i, j, jcount; - - float min, max; - float sumsq; - - // Recalc 256 summaries - sumLen = (len + 255) / 256; - - - for (i = 0; i < sumLen; i++) { - min = fbuffer[i * 256]; - max = fbuffer[i * 256]; - sumsq = ((float)min) * ((float)min); - jcount = 256; - if (i * 256 + jcount > len) - jcount = len - i * 256; - for (j = 1; j < jcount; j++) { - float f1 = fbuffer[i * 256 + j]; - sumsq += ((float)f1) * ((float)f1); - if (f1 < min) - min = f1; - else if (f1 > max) - max = f1; - } - - float rms = (float)sqrt(sumsq / jcount); - - summary256[i * 3] = min; - summary256[i * 3 + 1] = max; - summary256[i * 3 + 2] = rms; - } - - for (i = sumLen; i < mSummaryInfo.frames256; i++) { - // filling in the remaining bits with non-harming/contributing values - summary256[i * 3] = FLT_MAX; // min - summary256[i * 3 + 1] = -FLT_MAX; // max - summary256[i * 3 + 2] = 0.0f; // rms - } - - // Recalc 64K summaries - sumLen = (len + 65535) / 65536; - - for (i = 0; i < sumLen; i++) { - min = summary256[3 * i * 256]; - max = summary256[3 * i * 256 + 1]; - sumsq = (float)summary256[3 * i * 256 + 2]; - sumsq *= sumsq; - - for (j = 1; j < 256; j++) { - if (summary256[3 * (i * 256 + j)] < min) - min = summary256[3 * (i * 256 + j)]; - if (summary256[3 * (i * 256 + j) + 1] > max) - max = summary256[3 * (i * 256 + j) + 1]; - float r1 = summary256[3 * (i * 256 + j) + 2]; - sumsq += r1*r1; - } - - float rms = (float)sqrt(sumsq / 256); - - summary64K[i * 3] = min; - summary64K[i * 3 + 1] = max; - summary64K[i * 3 + 2] = rms; - } - for (i = sumLen; i < mSummaryInfo.frames64K; i++) { - summary64K[i * 3] = 0.0f; - summary64K[i * 3 + 1] = 0.0f; - summary64K[i * 3 + 2] = 0.0f; - } - - // Recalc block-level summary - min = summary64K[0]; - max = summary64K[1]; - sumsq = (float)summary64K[2]; - sumsq *= sumsq; - - for (i = 1; i < sumLen; i++) { - if (summary64K[3*i] < min) - min = summary64K[3*i]; - if (summary64K[3*i+1] > max) - max = summary64K[3*i+1]; - float r1 = (float)summary64K[3*i+2]; - sumsq += (r1*r1); - } - - mMin = min; - mMax = max; - mRMS = sqrt(sumsq / sumLen); + BlockFile::CalcSummaryFromBuffer(fbuffer, len, summary256, summary64K); //if we've used the float sample.. if(format!=floatSample)