Changeset 5a703bd


Ignore:
Timestamp:
Nov 15, 2018, 2:03:02 AM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
5bcd9b9
Parents:
22ec93a
Message:

[fft] fix reconstruction for odd sizes (fftw only)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/fft.c

    r22ec93a r5a703bd  
    494494  }
    495495#endif
    496   if (compspec->data[compspec->length/2] < 0) {
    497     spectrum->phas[spectrum->length - 1] = PI;
     496#ifdef HAVE_FFTW3
     497  // for even length only, make sure last element is 0 or PI
     498  if (2 * (compspec->length / 2) == compspec->length) {
     499#endif
     500    if (compspec->data[compspec->length/2] < 0) {
     501      spectrum->phas[spectrum->length - 1] = PI;
     502    } else {
     503      spectrum->phas[spectrum->length - 1] = 0.;
     504    }
     505#ifdef HAVE_FFTW3
    498506  } else {
    499     spectrum->phas[spectrum->length - 1] = 0.;
    500   }
     507    i = spectrum->length - 1;
     508    spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i],
     509        compspec->data[i]);
     510  }
     511#endif
    501512}
    502513
     
    508519        + SQR(compspec->data[compspec->length - i]) );
    509520  }
    510   spectrum->norm[spectrum->length-1] =
    511     ABS(compspec->data[compspec->length/2]);
     521#ifdef HAVE_FFTW3
     522  // for even length, make sure last element is > 0
     523  if (2 * (compspec->length / 2) == compspec->length) {
     524#endif
     525    spectrum->norm[spectrum->length-1] =
     526      ABS(compspec->data[compspec->length/2]);
     527#ifdef HAVE_FFTW3
     528  } else {
     529    i = spectrum->length - 1;
     530    spectrum->norm[i] = SQRT(SQR(compspec->data[i])
     531        + SQR(compspec->data[compspec->length - i]) );
     532  }
     533#endif
    512534}
    513535
Note: See TracChangeset for help on using the changeset viewer.