MCPcopy Create free account
hub / github.com/davy7125/polyphone / computeLoopQuality

Method computeLoopQuality

sources/core/sample/sampleutils.cpp:1207–1264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1205}
1206
1207float SampleUtils::computeLoopQuality(QVector<float> vData, quint32 loopStart, quint32 loopEnd, quint32 checkNumber, bool bipolar, float maxValue)
1208{
1209 const float * data = vData.constData();
1210 quint32 length = vData.size();
1211 if (loopStart < 2 || loopStart >= loopEnd || loopEnd >= length)
1212 return 0;
1213
1214 // Compute the difference at the loop points and a bit before
1215 int n = 1;
1216 float result = getDiffForLoopQuality(data, loopStart, loopEnd);
1217
1218 quint32 offset = 3;
1219 for (quint32 i = 1; i < checkNumber; i++)
1220 {
1221 offset += (M_PI_2 /* something irrational */ + i - 1) * i;
1222 if (loopStart > 3 + offset)
1223 {
1224 result += getDiffForLoopQuality(data, loopStart - offset - 1, loopEnd - offset - 1);
1225 n += 1;
1226 }
1227
1228 }
1229
1230 if (bipolar)
1231 {
1232 // Also take into account data following the loop point
1233 offset = 3;
1234 for (quint32 i = 1; i < checkNumber; i++)
1235 {
1236 offset += (M_PI_2 /* something irrational */ + i - 1) * i;
1237
1238 if (loopEnd + 3 + offset < (quint32)vData.size())
1239 {
1240 result += getDiffForLoopQuality(data, loopStart + offset - 1, loopEnd + offset - 1);
1241 n += 1;
1242 }
1243 }
1244 }
1245
1246 // Maximum value inside the loop
1247 float max = maxValue;
1248 if (max < 0)
1249 {
1250 max = 0.00045f;
1251 float tmp;
1252 for (quint32 i = loopStart; i <= loopEnd; i++)
1253 {
1254 tmp = data[i];
1255 if (tmp > max)
1256 max = tmp;
1257 else if (-tmp > max)
1258 max = -tmp;
1259 }
1260 }
1261
1262 // Differences are relative to the maximum
1263 return result / (max * n);
1264}

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected