Mercurial > hg > audiodb
comparison audioDB.cpp @ 149:12fee2a993bf powertable
Maybe implement silence thresholding for the sequence query (without an
explicit threshold radius). Not yet tested.
author | mas01cr |
---|---|
date | Wed, 31 Oct 2007 14:37:55 +0000 |
parents | 8c1c6a5c1cc3 |
children | b1cbd2b78a18 |
comparison
equal
deleted
inserted
replaced
148:8c1c6a5c1cc3 | 149:12fee2a993bf |
---|---|
1662 | 1662 |
1663 // Copy the L2 norm values to core to avoid disk random access later on | 1663 // Copy the L2 norm values to core to avoid disk random access later on |
1664 memcpy(sNorm, l2normTable, dbVectors*sizeof(double)); | 1664 memcpy(sNorm, l2normTable, dbVectors*sizeof(double)); |
1665 double* qnPtr = qNorm; | 1665 double* qnPtr = qNorm; |
1666 double* snPtr = sNorm; | 1666 double* snPtr = sNorm; |
1667 | |
1668 double *sPower = 0, *qPower; | |
1669 double *spPtr = 0, *qpPtr = 0; | |
1670 | |
1671 if (usingPower) { | |
1672 if (!(dbH->flags & O2_FLAG_POWER)) { | |
1673 error("database not power-enabled", dbName); | |
1674 } | |
1675 sPower = new double[dbVectors]; | |
1676 spPtr = sPower; | |
1677 memcpy(sPower, powerTable, dbVectors * sizeof(double)); | |
1678 } | |
1679 | |
1667 for(i=0; i<dbH->numFiles; i++){ | 1680 for(i=0; i<dbH->numFiles; i++){ |
1668 if(trackTable[i]>=sequenceLength) { | 1681 if(trackTable[i]>=sequenceLength) { |
1669 sequence_sum(snPtr, trackTable[i], sequenceLength); | 1682 sequence_sum(snPtr, trackTable[i], sequenceLength); |
1683 if (usingPower) { | |
1684 sequence_sum(spPtr, trackTable[i], sequenceLength); | |
1685 } | |
1670 | 1686 |
1671 ps = snPtr; | 1687 ps = snPtr; |
1672 w=trackTable[i]-sequenceLength+1; | 1688 w=trackTable[i]-sequenceLength+1; |
1673 while(w--){ | 1689 while(w--){ |
1674 *ps=sqrt(*ps); | 1690 *ps=sqrt(*ps); |
1675 ps++; | 1691 ps++; |
1676 } | 1692 } |
1677 } | 1693 |
1678 snPtr+=trackTable[i]; | 1694 if (usingPower) { |
1695 ps = spPtr; | |
1696 w = trackTable[i] - sequenceLength + 1; | |
1697 while(w--) { | |
1698 *ps = *ps / sequenceLength; | |
1699 ps++; | |
1700 } | |
1701 } | |
1702 } | |
1703 snPtr += trackTable[i]; | |
1704 if (usingPower) { | |
1705 spPtr += trackTable[i]; | |
1706 } | |
1679 } | 1707 } |
1680 | 1708 |
1681 double* pn = sMeanL2; | 1709 double* pn = sMeanL2; |
1682 w=dbH->numFiles; | 1710 w=dbH->numFiles; |
1683 while(w--) | 1711 while(w--) |
1709 if(verbosity>4) { | 1737 if(verbosity>4) { |
1710 cerr << "silence thresh: " << SILENCE_THRESH; | 1738 cerr << "silence thresh: " << SILENCE_THRESH; |
1711 } | 1739 } |
1712 | 1740 |
1713 sequence_sum(qnPtr, numVectors, sequenceLength); | 1741 sequence_sum(qnPtr, numVectors, sequenceLength); |
1742 if (usingPower) { | |
1743 qPower = new double[numVectors]; | |
1744 qpPtr = qPower; | |
1745 if (lseek(powerfd, sizeof(int), SEEK_SET) == (off_t) -1) { | |
1746 error("error seeking to data", powerFileName, "lseek"); | |
1747 } | |
1748 int count = read(powerfd, qPower, numVectors * sizeof(double)); | |
1749 if (count == -1) { | |
1750 error("error reading data", powerFileName, "read"); | |
1751 } | |
1752 if ((unsigned) count != numVectors * sizeof(double)) { | |
1753 error("short read", powerFileName); | |
1754 } | |
1755 | |
1756 sequence_sum(qpPtr, numVectors, sequenceLength); | |
1757 ps = qpPtr; | |
1758 w = trackTable[i] - sequenceLength + 1; | |
1759 while(w--) { | |
1760 *ps = *ps / sequenceLength; | |
1761 ps++; | |
1762 } | |
1763 } | |
1714 | 1764 |
1715 ps = qnPtr; | 1765 ps = qnPtr; |
1716 qMeanL2 = 0; | 1766 qMeanL2 = 0; |
1717 w=numVectors-sequenceLength+1; | 1767 w=numVectors-sequenceLength+1; |
1718 while(w--){ | 1768 while(w--){ |
1948 logSampleSum+=log(thisDist); | 1998 logSampleSum+=log(thisDist); |
1949 } | 1999 } |
1950 | 2000 |
1951 // diffL2 = fabs(qnPtr[j] - sNorm[trackIndexOffset+k]); | 2001 // diffL2 = fabs(qnPtr[j] - sNorm[trackIndexOffset+k]); |
1952 // Power test | 2002 // Power test |
2003 if (usingPower) { | |
2004 if (!(powers_acceptable(qpPtr[j], sPower[trackIndexOffset + k]))) { | |
2005 thisDist = 1000000.0; | |
2006 } | |
2007 } | |
2008 | |
2009 /* | |
1953 if(!USE_THRESH || | 2010 if(!USE_THRESH || |
1954 // Threshold on mean L2 of Q and S sequences | 2011 // Threshold on mean L2 of Q and S sequences |
1955 (USE_THRESH && qnPtr[j]>SILENCE_THRESH && sNorm[trackIndexOffset+k]>SILENCE_THRESH && | 2012 (USE_THRESH && qnPtr[j]>SILENCE_THRESH && sNorm[trackIndexOffset+k]>SILENCE_THRESH && |
1956 // Are both query and target windows above mean energy? | 2013 // Are both query and target windows above mean energy? |
1957 (qnPtr[j]>qMeanL2*.25 && sNorm[trackIndexOffset+k]>sMeanL2[track]*.25))) // && diffL2 < DIFF_THRESH ))) | 2014 (qnPtr[j]>qMeanL2*.25 && sNorm[trackIndexOffset+k]>sMeanL2[track]*.25))) // && diffL2 < DIFF_THRESH ))) |
1958 thisDist=thisDist; // Computed above | 2015 thisDist=thisDist; // Computed above |
1959 else | 2016 else |
1960 thisDist=1000000.0; | 2017 thisDist=1000000.0; |
2018 */ | |
1961 | 2019 |
1962 // k-NN match algorithm | 2020 // k-NN match algorithm |
1963 m=pointNN; | 2021 m=pointNN; |
1964 while(m--){ | 2022 while(m--){ |
1965 if(thisDist<=distances[m]) | 2023 if(thisDist<=distances[m]) |