# HG changeset patch # User mas01cr # Date 1192632293 0 # Node ID 26ec0906adb9341c11b8b2a494e1b645d125f581 # Parent 394c8419217c8d98714048403a1a46a7eb725906 Be a bit more careful about qNorm handling and freeing: don't assign qNorm anywhere, but use a (new) interior pointer instead. Also fix test 0023 for the correct results. diff -r 394c8419217c -r 26ec0906adb9 audioDB.cpp --- a/audioDB.cpp Wed Oct 17 14:35:23 2007 +0000 +++ b/audioDB.cpp Wed Oct 17 14:44:53 2007 +0000 @@ -1393,6 +1393,7 @@ // Copy the L2 norm values to core to avoid disk random access later on memcpy(sNorm, l2normTable, dbVectors*sizeof(double)); + double* qnPtr = qNorm; double* snPtr = sNorm; for(i=0; inumFiles; i++){ if(trackTable[i]>=sequenceLength){ @@ -1452,10 +1453,10 @@ } w=sequenceLength-1; i=1; - tmp1=*qNorm; + tmp1=*qnPtr; while(w--) - *qNorm+=qNorm[i++]; - ps = qNorm+1; + *qnPtr+=qnPtr[i++]; + ps = qnPtr+1; w=numVectors-sequenceLength; // +1 -1 while(w--){ tmp2=*ps; @@ -1463,7 +1464,7 @@ tmp1=tmp2; ps++; } - ps = qNorm; + ps = qnPtr; qMeanL2 = 0; w=numVectors-sequenceLength+1; while(w--){ @@ -1554,7 +1555,7 @@ cerr << "query point: " << queryPoint << endl; cerr.flush(); } query=query+queryPoint*dbH->dim; - qNorm=qNorm+queryPoint; + qnPtr=qnPtr+queryPoint; numVectors=wL; } @@ -1684,9 +1685,9 @@ // Search for minimum distance by shingles (concatenated vectors) for(j=0;j<=numVectors-wL;j+=HOP_SIZE) for(k=0;k<=trackTable[track]-wL;k+=HOP_SIZE){ - thisDist=2-(2/(qNorm[j]*sNorm[trackIndexOffset+k]))*DD[j][k]; + thisDist=2-(2/(qnPtr[j]*sNorm[trackIndexOffset+k]))*DD[j][k]; if(verbosity>10) { - cerr << thisDist << " " << qNorm[j] << " " << sNorm[trackIndexOffset+k] << endl; + cerr << thisDist << " " << qnPtr[j] << " " << sNorm[trackIndexOffset+k] << endl; } // Gather chi^2 statistics if(thisDistSILENCE_THRESH && sNorm[trackIndexOffset+k]>SILENCE_THRESH && + (USE_THRESH && qnPtr[j]>SILENCE_THRESH && sNorm[trackIndexOffset+k]>SILENCE_THRESH && // Are both query and target windows above mean energy? - (qNorm[j]>qMeanL2*.25 && sNorm[trackIndexOffset+k]>sMeanL2[track]*.25))) // && diffL2 < DIFF_THRESH ))) + (qnPtr[j]>qMeanL2*.25 && sNorm[trackIndexOffset+k]>sMeanL2[track]*.25))) // && diffL2 < DIFF_THRESH ))) thisDist=thisDist; // Computed above else thisDist=1000000.0; @@ -1897,6 +1898,7 @@ // Copy the L2 norm values to core to avoid disk random access later on memcpy(sNorm, l2normTable, dbVectors*sizeof(double)); double* snPtr = sNorm; + double* qnPtr = qNorm; for(i=0; inumFiles; i++){ if(trackTable[i]>=sequenceLength){ tmp1=*snPtr; @@ -1955,10 +1957,10 @@ } w=sequenceLength-1; i=1; - tmp1=*qNorm; + tmp1=*qnPtr; while(w--) - *qNorm+=qNorm[i++]; - ps = qNorm+1; + *qnPtr+=qnPtr[i++]; + ps = qnPtr+1; w=numVectors-sequenceLength; // +1 -1 while(w--){ tmp2=*ps; @@ -1966,7 +1968,7 @@ tmp1=tmp2; ps++; } - ps = qNorm; + ps = qnPtr; qMeanL2 = 0; w=numVectors-sequenceLength+1; while(w--){ @@ -2057,7 +2059,7 @@ cerr << "query point: " << queryPoint << endl; cerr.flush(); } query=query+queryPoint*dbH->dim; - qNorm=qNorm+queryPoint; + qnPtr=qnPtr+queryPoint; numVectors=wL; } @@ -2187,9 +2189,9 @@ // Search for minimum distance by shingles (concatenated vectors) for(j=0;j<=numVectors-wL;j+=HOP_SIZE) for(k=0;k<=trackTable[track]-wL;k+=HOP_SIZE){ - thisDist=2-(2/(qNorm[j]*sNorm[trackIndexOffset+k]))*DD[j][k]; + thisDist=2-(2/(qnPtr[j]*sNorm[trackIndexOffset+k]))*DD[j][k]; if(verbosity>10) { - cerr << thisDist << " " << qNorm[j] << " " << sNorm[trackIndexOffset+k] << endl; + cerr << thisDist << " " << qnPtr[j] << " " << sNorm[trackIndexOffset+k] << endl; } // Gather chi^2 statistics if(thisDistSILENCE_THRESH && sNorm[trackIndexOffset+k]>SILENCE_THRESH && + (USE_THRESH && qnPtr[j]>SILENCE_THRESH && sNorm[trackIndexOffset+k]>SILENCE_THRESH && // Are both query and target windows above mean energy? - (qNorm[j]>qMeanL2*.25 && sNorm[trackIndexOffset+k]>sMeanL2[track]*.25))) // && diffL2 < DIFF_THRESH ))) + (qnPtr[j]>qMeanL2*.25 && sNorm[trackIndexOffset+k]>sMeanL2[track]*.25))) // && diffL2 < DIFF_THRESH ))) thisDist=thisDist; // Computed above else thisDist=1000000.0; diff -r 394c8419217c -r 26ec0906adb9 tests/0023/run-test.sh --- a/tests/0023/run-test.sh Wed Oct 17 14:35:23 2007 +0000 +++ b/tests/0023/run-test.sh Wed Oct 17 14:44:53 2007 +0000 @@ -37,11 +37,11 @@ echo "query point (0.5,0.0)" ${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -p 1 > testoutput -echo testfeature10 0 0 0 > test-expected-output -echo testfeature01 2 0 0 >> test-expected-output +echo testfeature10 0 1 0 > test-expected-output +echo testfeature01 2 1 0 >> test-expected-output cmp testoutput test-expected-output ${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 -p 1 > testoutput -echo testfeature10 0 0 0 > test-expected-output +echo testfeature10 0 1 0 > test-expected-output cmp testoutput test-expected-output exit 104 diff -r 394c8419217c -r 26ec0906adb9 tests/0023/short-description --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/0023/short-description Wed Oct 17 14:44:53 2007 +0000 @@ -0,0 +1,1 @@ +as 0022 but with -p \ No newline at end of file