Skip to content

Commit

Permalink
Fix a rounding issue, during creation of sparse kernel
Browse files Browse the repository at this point in the history
Use double value for waveform generation and move a multiplication out of
loop.
  • Loading branch information
daschuer committed Jun 6, 2019
1 parent 9b18a22 commit 4747f6f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions dsp/chromagram/ConstantQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ void ConstantQ::sparsekernel()

// Compute a complex sinusoid windowed with a hamming window
// of the right length

int windowLength = (int)ceil
(m_dQ * m_FS / (m_FMin * pow(2, (double)j / (double)m_BPO)));

const double samplesPerCycle =
m_FS / (m_FMin * pow(2, (double)j / (double)m_BPO));
int windowLength = (int)ceil(m_dQ * samplesPerCycle);

int origin = m_FFTLength/2 - windowLength/2;

for (int i = 0; i < windowLength; ++i) {
double angle = (2.0 * M_PI * m_dQ * i) / windowLength;
double angle = (2.0 * M_PI * i) / samplesPerCycle;
windowRe[origin + i] = cos(angle);
windowIm[origin + i] = sin(angle);
}
Expand Down

0 comments on commit 4747f6f

Please sign in to comment.