| 169 | |
| 170 | |
| 171 | void cTonespec::computeFilters(long blocksize, double frameSizeSec, int idxc) |
| 172 | { |
| 173 | FLOAT_DMEM *_distance2key = distance2key[idxc]; |
| 174 | FLOAT_DMEM *_filterMap = filterMap[idxc]; |
| 175 | FLOAT_DMEM *_pitchClassFreq = pitchClassFreq[idxc]; |
| 176 | |
| 177 | int * _binKey = binKey[idxc]; |
| 178 | int * _pitchClassNbins = pitchClassNbins[idxc]; |
| 179 | |
| 180 | if (_distance2key != NULL) free(_distance2key); |
| 181 | _distance2key = (FLOAT_DMEM*)malloc(sizeof(FLOAT_DMEM) * blocksize); |
| 182 | if (_binKey != NULL) free(_binKey); |
| 183 | _binKey = (int *)malloc(sizeof(int) * blocksize); |
| 184 | if (_pitchClassNbins != NULL) free(_pitchClassNbins); |
| 185 | _pitchClassNbins = (int *)calloc(1,sizeof(int) * (nNotes+2)); |
| 186 | if (_filterMap != NULL) free(_filterMap); |
| 187 | _filterMap = (FLOAT_DMEM *)malloc(sizeof(FLOAT_DMEM) * blocksize); |
| 188 | |
| 189 | if (flBin[idxc] != NULL) free(flBin[idxc]); |
| 190 | flBin[idxc] = (int*)calloc(1,sizeof(FLOAT_DMEM)*2); |
| 191 | int firstBin = *(flBin[idxc]); |
| 192 | int lastBin = *(flBin[idxc]+1); |
| 193 | |
| 194 | int i,b; |
| 195 | |
| 196 | FLOAT_DMEM F0 = (FLOAT_DMEM)(1.0/frameSizeSec); |
| 197 | if (dbA) { |
| 198 | if (db[idxc] != NULL) free(db[idxc]); |
| 199 | db[idxc] = (FLOAT_DMEM*)malloc(sizeof(FLOAT_DMEM)*blocksize); |
| 200 | computeDBA( db[idxc], blocksize, F0 ); |
| 201 | } |
| 202 | |
| 203 | firstBin = (int)ceil((_pitchClassFreq[0]+_pitchClassFreq[1]) / (2.0*F0)); |
| 204 | lastBin = (int)floor((_pitchClassFreq[nNotes]+_pitchClassFreq[nNotes+1]) / (2.0*F0)); |
| 205 | //lastBin = (int)round(lastNote / F0); |
| 206 | if (firstBin < 1) firstBin = 1; |
| 207 | if (lastBin >= blocksize) lastBin = blocksize-1; |
| 208 | SMILE_IDBG(2,"\tOne bin represents: %f Hz\n\t\t\t\tUsing FFT bin %i to %i\n\t\t\t\tFor freq %f Hz to %f Hz",F0,firstBin,lastBin,firstNote,lastNote); |
| 209 | |
| 210 | int curNote = 0; |
| 211 | FLOAT_DMEM distance0 = 0.0; |
| 212 | FLOAT_DMEM distance1 = 0.0; |
| 213 | for (i = 0 ; i < blocksize; i++) // checks the frequency of every FFT bin and maps it to a key frequency |
| 214 | { |
| 215 | if (curNote > nNotes) curNote=nNotes; // ??? |
| 216 | distance0 = fabs(_pitchClassFreq[curNote] - ((FLOAT_DMEM)i * F0)); // get the distance |
| 217 | int note1 = curNote; |
| 218 | distance1 = fabs(_pitchClassFreq[++note1] - ((FLOAT_DMEM)i * F0)); // get the distance |
| 219 | while (distance0 > distance1) { |
| 220 | //fprintf(stderr,"curN: %i n1 %i - di0 %f di1 %f\n",curNote,note1,distance0,distance1); fflush(stderr); |
| 221 | if (note1 > nNotes) break; |
| 222 | distance0 = distance1; |
| 223 | distance1 = fabs(_pitchClassFreq[++note1] - ((FLOAT_DMEM)i * F0)); // get the distance |
| 224 | } |
| 225 | curNote = note1-1; |
| 226 | _binKey[i] = curNote; |
| 227 | } |
| 228 | /* |
nothing calls this directly
no test coverage detected