Mercurial > hg > audiodb
comparison audioDB.cpp @ 148:8c1c6a5c1cc3 powertable
Abstract the operation to perform a windowed sequence sum into a
function, and use that function in the four places that were already
doing this operation.
author | mas01cr |
---|---|
date | Wed, 31 Oct 2007 13:08:21 +0000 |
parents | a564e6d7a30c |
children | 12fee2a993bf |
comparison
equal
deleted
inserted
replaced
147:a564e6d7a30c | 148:8c1c6a5c1cc3 |
---|---|
1586 if(meanDBdur) | 1586 if(meanDBdur) |
1587 delete meanDBdur; | 1587 delete meanDBdur; |
1588 | 1588 |
1589 } | 1589 } |
1590 | 1590 |
1591 // This is a common pattern in sequence queries: what we are doing is | |
1592 // taking a window of length seqlen over a buffer of length length, | |
1593 // and placing the sum of the elements in that window in the first | |
1594 // element of the window: thus replacing all but the last seqlen | |
1595 // elements in the buffer the corresponding windowed sum. | |
1596 void audioDB::sequence_sum(double *buffer, int length, int seqlen) { | |
1597 double tmp1, tmp2, *ps; | |
1598 int j, w; | |
1599 | |
1600 tmp1 = *buffer; | |
1601 j = 1; | |
1602 w = seqlen - 1; | |
1603 while(w--) { | |
1604 *buffer += buffer[j++]; | |
1605 } | |
1606 ps = buffer + 1; | |
1607 w = length - seqlen; // +1 - 1 | |
1608 while(w--) { | |
1609 tmp2 = *ps; | |
1610 *ps = *(ps - 1) - tmp1 + *(ps + seqlen - 1); | |
1611 tmp1 = tmp2; | |
1612 ps++; | |
1613 } | |
1614 } | |
1591 | 1615 |
1592 // k nearest-neighbor (k-NN) search between query and target tracks | 1616 // k nearest-neighbor (k-NN) search between query and target tracks |
1593 // efficient implementation based on matched filter | 1617 // efficient implementation based on matched filter |
1594 // assumes normed shingles | 1618 // assumes normed shingles |
1595 // outputs distances of retrieved shingles, max retreived = pointNN shingles per per track | 1619 // outputs distances of retrieved shingles, max retreived = pointNN shingles per per track |
1633 | 1657 |
1634 // Make norm measurements relative to sequenceLength | 1658 // Make norm measurements relative to sequenceLength |
1635 unsigned w = sequenceLength-1; | 1659 unsigned w = sequenceLength-1; |
1636 unsigned i,j; | 1660 unsigned i,j; |
1637 double* ps; | 1661 double* ps; |
1638 double tmp1,tmp2; | |
1639 | 1662 |
1640 // 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 |
1641 memcpy(sNorm, l2normTable, dbVectors*sizeof(double)); | 1664 memcpy(sNorm, l2normTable, dbVectors*sizeof(double)); |
1642 double* qnPtr = qNorm; | 1665 double* qnPtr = qNorm; |
1643 double* snPtr = sNorm; | 1666 double* snPtr = sNorm; |
1644 for(i=0; i<dbH->numFiles; i++){ | 1667 for(i=0; i<dbH->numFiles; i++){ |
1645 if(trackTable[i]>=sequenceLength){ | 1668 if(trackTable[i]>=sequenceLength) { |
1646 tmp1=*snPtr; | 1669 sequence_sum(snPtr, trackTable[i], sequenceLength); |
1647 j=1; | 1670 |
1648 w=sequenceLength-1; | |
1649 while(w--) | |
1650 *snPtr+=snPtr[j++]; | |
1651 ps = snPtr+1; | |
1652 w=trackTable[i]-sequenceLength; // +1 - 1 | |
1653 while(w--){ | |
1654 tmp2=*ps; | |
1655 *ps=*(ps-1)-tmp1+*(ps+sequenceLength-1); | |
1656 tmp1=tmp2; | |
1657 ps++; | |
1658 } | |
1659 ps = snPtr; | 1671 ps = snPtr; |
1660 w=trackTable[i]-sequenceLength+1; | 1672 w=trackTable[i]-sequenceLength+1; |
1661 while(w--){ | 1673 while(w--){ |
1662 *ps=sqrt(*ps); | 1674 *ps=sqrt(*ps); |
1663 ps++; | 1675 ps++; |
1695 DIFF_THRESH=SILENCE_THRESH; // mean shingle power | 1707 DIFF_THRESH=SILENCE_THRESH; // mean shingle power |
1696 SILENCE_THRESH/=5; // 20% of the mean shingle power is SILENCE | 1708 SILENCE_THRESH/=5; // 20% of the mean shingle power is SILENCE |
1697 if(verbosity>4) { | 1709 if(verbosity>4) { |
1698 cerr << "silence thresh: " << SILENCE_THRESH; | 1710 cerr << "silence thresh: " << SILENCE_THRESH; |
1699 } | 1711 } |
1700 w=sequenceLength-1; | 1712 |
1701 i=1; | 1713 sequence_sum(qnPtr, numVectors, sequenceLength); |
1702 tmp1=*qnPtr; | 1714 |
1703 while(w--) | |
1704 *qnPtr+=qnPtr[i++]; | |
1705 ps = qnPtr+1; | |
1706 w=numVectors-sequenceLength; // +1 -1 | |
1707 while(w--){ | |
1708 tmp2=*ps; | |
1709 *ps=*(ps-1)-tmp1+*(ps+sequenceLength-1); | |
1710 tmp1=tmp2; | |
1711 ps++; | |
1712 } | |
1713 ps = qnPtr; | 1715 ps = qnPtr; |
1714 qMeanL2 = 0; | 1716 qMeanL2 = 0; |
1715 w=numVectors-sequenceLength+1; | 1717 w=numVectors-sequenceLength+1; |
1716 while(w--){ | 1718 while(w--){ |
1717 *ps=sqrt(*ps); | 1719 *ps=sqrt(*ps); |
2070 adbQueryResponse->result.Spos[k]=trackSIndexes[k]; | 2072 adbQueryResponse->result.Spos[k]=trackSIndexes[k]; |
2071 sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE); | 2073 sprintf(adbQueryResponse->result.Rlist[k], "%s", fileTable+trackIDs[k]*O2_FILETABLESIZE); |
2072 } | 2074 } |
2073 } | 2075 } |
2074 | 2076 |
2075 | |
2076 // Clean up | 2077 // Clean up |
2077 if(trackOffsetTable) | 2078 if(trackOffsetTable) |
2078 delete[] trackOffsetTable; | 2079 delete[] trackOffsetTable; |
2079 if(queryCopy) | 2080 if(queryCopy) |
2080 delete[] queryCopy; | 2081 delete[] queryCopy; |
2090 delete[] DD; | 2091 delete[] DD; |
2091 if(timesdata) | 2092 if(timesdata) |
2092 delete[] timesdata; | 2093 delete[] timesdata; |
2093 if(meanDBdur) | 2094 if(meanDBdur) |
2094 delete[] meanDBdur; | 2095 delete[] meanDBdur; |
2095 | |
2096 | |
2097 } | 2096 } |
2098 | 2097 |
2099 // Radius search between query and target tracks | 2098 // Radius search between query and target tracks |
2100 // efficient implementation based on matched filter | 2099 // efficient implementation based on matched filter |
2101 // assumes normed shingles | 2100 // assumes normed shingles |
2137 | 2136 |
2138 // Make norm measurements relative to sequenceLength | 2137 // Make norm measurements relative to sequenceLength |
2139 unsigned w = sequenceLength-1; | 2138 unsigned w = sequenceLength-1; |
2140 unsigned i,j; | 2139 unsigned i,j; |
2141 double* ps; | 2140 double* ps; |
2142 double tmp1,tmp2; | |
2143 | 2141 |
2144 // Copy the L2 norm values to core to avoid disk random access later on | 2142 // Copy the L2 norm values to core to avoid disk random access later on |
2145 memcpy(sNorm, l2normTable, dbVectors*sizeof(double)); | 2143 memcpy(sNorm, l2normTable, dbVectors*sizeof(double)); |
2146 double* snPtr = sNorm; | 2144 double* snPtr = sNorm; |
2147 double* qnPtr = qNorm; | 2145 double* qnPtr = qNorm; |
2148 for(i=0; i<dbH->numFiles; i++){ | 2146 for(i=0; i<dbH->numFiles; i++){ |
2149 if(trackTable[i]>=sequenceLength){ | 2147 if(trackTable[i]>=sequenceLength){ |
2150 tmp1=*snPtr; | 2148 sequence_sum(snPtr, trackTable[i], sequenceLength); |
2151 j=1; | 2149 |
2152 w=sequenceLength-1; | |
2153 while(w--) | |
2154 *snPtr+=snPtr[j++]; | |
2155 ps = snPtr+1; | |
2156 w=trackTable[i]-sequenceLength; // +1 - 1 | |
2157 while(w--){ | |
2158 tmp2=*ps; | |
2159 *ps=*(ps-1)-tmp1+*(ps+sequenceLength-1); | |
2160 tmp1=tmp2; | |
2161 ps++; | |
2162 } | |
2163 ps = snPtr; | 2150 ps = snPtr; |
2164 w=trackTable[i]-sequenceLength+1; | 2151 w=trackTable[i]-sequenceLength+1; |
2165 while(w--){ | 2152 while(w--){ |
2166 *ps=sqrt(*ps); | 2153 *ps=sqrt(*ps); |
2167 ps++; | 2154 ps++; |
2199 DIFF_THRESH=SILENCE_THRESH; // mean shingle power | 2186 DIFF_THRESH=SILENCE_THRESH; // mean shingle power |
2200 SILENCE_THRESH/=5; // 20% of the mean shingle power is SILENCE | 2187 SILENCE_THRESH/=5; // 20% of the mean shingle power is SILENCE |
2201 if(verbosity>4) { | 2188 if(verbosity>4) { |
2202 cerr << "silence thresh: " << SILENCE_THRESH; | 2189 cerr << "silence thresh: " << SILENCE_THRESH; |
2203 } | 2190 } |
2204 w=sequenceLength-1; | 2191 |
2205 i=1; | 2192 sequence_sum(qnPtr, numVectors, sequenceLength); |
2206 tmp1=*qnPtr; | 2193 |
2207 while(w--) | |
2208 *qnPtr+=qnPtr[i++]; | |
2209 ps = qnPtr+1; | |
2210 w=numVectors-sequenceLength; // +1 -1 | |
2211 while(w--){ | |
2212 tmp2=*ps; | |
2213 *ps=*(ps-1)-tmp1+*(ps+sequenceLength-1); | |
2214 tmp1=tmp2; | |
2215 ps++; | |
2216 } | |
2217 ps = qnPtr; | 2194 ps = qnPtr; |
2218 qMeanL2 = 0; | 2195 qMeanL2 = 0; |
2219 w=numVectors-sequenceLength+1; | 2196 w=numVectors-sequenceLength+1; |
2220 while(w--){ | 2197 while(w--){ |
2221 *ps=sqrt(*ps); | 2198 *ps=sqrt(*ps); |