Skip to content

Commit

Permalink
Fix some code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Jun 2, 2019
1 parent a283635 commit 2c97c55
Showing 1 changed file with 60 additions and 63 deletions.
123 changes: 60 additions & 63 deletions dsp/chromagram/ConstantQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ void ConstantQ::sparsekernel()

FFT m_FFT(m_FFTLength);

for (unsigned k = m_uK; k--; )
{
for (unsigned u=0; u < m_FFTLength; u++)
{
for (unsigned k = m_uK; k--;) {
for (unsigned u=0; u < m_FFTLength; u++) {
hammingWindowRe[u] = 0;
hammingWindowIm[u] = 0;
}
Expand All @@ -134,15 +132,14 @@ void ConstantQ::sparsekernel()

unsigned origin = m_FFTLength/2 - hammingLength/2;

for (unsigned i=0; i<hammingLength; i++)
{
const double angle = 2*PI*i/samplesPerCycle;
const double real = cos(angle);
const double imag = sin(angle);
const double absol = hamming(hammingLength, i)/hammingLength;
hammingWindowRe[ origin + i ] = absol*real;
hammingWindowIm[ origin + i ] = absol*imag;
}
for (unsigned i=0; i<hammingLength; i++) {
const double angle = 2*PI*i/samplesPerCycle;
const double real = cos(angle);
const double imag = sin(angle);
const double absol = hamming(hammingLength, i)/hammingLength;
hammingWindowRe[ origin + i ] = absol*real;
hammingWindowIm[ origin + i ] = absol*imag;
}

for (unsigned i = 0; i < m_FFTLength/2; ++i) {
double temp = hammingWindowRe[i];
Expand All @@ -153,24 +150,24 @@ void ConstantQ::sparsekernel()
hammingWindowIm[i + m_FFTLength/2] = temp;
}

//do fft of hammingWindow
m_FFT.process( 0, hammingWindowRe, hammingWindowIm, transfHammingWindowRe, transfHammingWindowIm );

for (unsigned j=0; j<( m_FFTLength ); j++)
{
// perform thresholding
const double squaredBin = squaredModule( transfHammingWindowRe[ j ], transfHammingWindowIm[ j ]);
if (squaredBin <= squareThreshold) continue;
// Insert non-zero position indexes
sk->is.push_back(j);
sk->js.push_back(k);

// take conjugate, normalise and add to array sparkernel
sk->real.push_back( transfHammingWindowRe[ j ]/m_FFTLength);
sk->imag.push_back(-transfHammingWindowIm[ j ]/m_FFTLength);
}
//do fft of hammingWindow
m_FFT.process( 0, hammingWindowRe, hammingWindowIm, transfHammingWindowRe, transfHammingWindowIm );


for (unsigned j=0; j<( m_FFTLength ); j++) {
// perform thresholding
const double squaredBin = squaredModule( transfHammingWindowRe[ j ], transfHammingWindowIm[ j ]);
if (squaredBin <= squareThreshold) {
continue;
}
// Insert non-zero position indexes
sk->is.push_back(j);
sk->js.push_back(k);

// take conjugate, normalise and add to array sparkernel
sk->real.push_back( transfHammingWindowRe[ j ]/m_FFTLength);
sk->imag.push_back(-transfHammingWindowIm[ j ]/m_FFTLength);
}

}

Expand Down Expand Up @@ -260,29 +257,29 @@ double* ConstantQ::process( const double* fftdata )

SparseKernel *sk = m_sparseKernel;

for (unsigned row=0; row<2*m_uK; row++)
{
m_CQdata[ row ] = 0;
m_CQdata[ row+1 ] = 0;
for (unsigned row=0; row<2*m_uK; row++) {
m_CQdata[ row ] = 0;
m_CQdata[ row+1 ] = 0;
}
const unsigned *fftbin = &(sk->is[0]);
const unsigned *cqbin = &(sk->js[0]);
const double *real = &(sk->real[0]);
const double *imag = &(sk->imag[0]);
const unsigned int sparseCells = sk->real.size();

for (unsigned i = 0; i<sparseCells; i++)
{
const unsigned row = cqbin[i];
const unsigned col = fftbin[i];
if (col == 0) continue;
const double & r1 = real[i];
const double & i1 = imag[i];
const double & r2 = fftdata[ (2*m_FFTLength) - 2*col - 2 ];
const double & i2 = fftdata[ (2*m_FFTLength) - 2*col - 2 + 1 ];
// add the multiplication
m_CQdata[ 2*row ] += (r1*r2 - i1*i2);
m_CQdata[ 2*row+1] += (r1*i2 + i1*r2);
for (unsigned i = 0; i<sparseCells; i++) {
const unsigned row = cqbin[i];
const unsigned col = fftbin[i];
if (col == 0) {
continue;
}
const double & r1 = real[i];
const double & i1 = imag[i];
const double & r2 = fftdata[ (2*m_FFTLength) - 2*col - 2 ];
const double & i2 = fftdata[ (2*m_FFTLength) - 2*col - 2 + 1 ];
// add the multiplication
m_CQdata[ 2*row ] += (r1*r2 - i1*i2);
m_CQdata[ 2*row+1] += (r1*i2 + i1*r2);
}

return m_CQdata;
Expand Down Expand Up @@ -329,10 +326,9 @@ void ConstantQ::process(const double *FFTRe, const double* FFTIm,

SparseKernel *sk = m_sparseKernel;

for (unsigned row=0; row<m_uK; row++)
{
CQRe[ row ] = 0;
CQIm[ row ] = 0;
for (unsigned row=0; row<m_uK; row++) {
CQRe[ row ] = 0;
CQIm[ row ] = 0;
}

const unsigned *fftbin = &(sk->is[0]);
Expand All @@ -341,17 +337,18 @@ void ConstantQ::process(const double *FFTRe, const double* FFTIm,
const double *imag = &(sk->imag[0]);
const unsigned int sparseCells = sk->real.size();

for (unsigned i = 0; i<sparseCells; i++)
{
const unsigned row = cqbin[i];
const unsigned col = fftbin[i];
if (col == 0) continue;
const double & r1 = real[i];
const double & i1 = imag[i];
const double & r2 = FFTRe[ m_FFTLength - col ];
const double & i2 = FFTIm[ m_FFTLength - col ];
// add the multiplication
CQRe[ row ] += (r1*r2 - i1*i2);
CQIm[ row ] += (r1*i2 + i1*r2);
for (unsigned i = 0; i<sparseCells; i++) {
const unsigned row = cqbin[i];
const unsigned col = fftbin[i];
if (col == 0) {
continue;
}
const double & r1 = real[i];
const double & i1 = imag[i];
const double & r2 = FFTRe[ m_FFTLength - col ];
const double & i2 = FFTIm[ m_FFTLength - col ];
// add the multiplication
CQRe[ row ] += (r1*r2 - i1*i2);
CQIm[ row ] += (r1*i2 + i1*r2);
}
}

0 comments on commit 2c97c55

Please sign in to comment.